diff --git a/core/circuit/circuit.go b/core/circuit/circuit.go index c77b463b1..c2ff6f85f 100644 --- a/core/circuit/circuit.go +++ b/core/circuit/circuit.go @@ -326,9 +326,9 @@ func (c *Circuit) ValidatePower(old, new float64, charging bool) float64 { var capped float64 if charging { - capped = min(maxPower, new, max(0, potential+old)) + capped = min(new, maxPower, max(0, potential+old)) } else { - capped = max(0, min(new, potential)) + capped = min(new, max(0, potential)) } if new > capped { c.log.DEBUG.Printf("validate power: %.5gW + (%.5gW -> %.5gW) > %.5gW capped at %.5gW", c.power, old, new, maxPower, capped) @@ -350,9 +350,9 @@ func (c *Circuit) ValidateCurrent(old, new float64, charging bool) float64 { var capped float64 if charging { - capped = min(maxCurrent, new, max(0, potential+old)) + capped = min(new, maxCurrent, max(0, potential+old)) } else { - capped = max(0, min(new, potential)) + capped = min(new, max(0, potential)) } if new > capped { c.log.DEBUG.Printf("validate current: %.3gA + (%.3gA -> %.3gA) > %.3gA capped at %.3gA", c.current, old, new, maxCurrent, capped)