mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Use math.Copysign for unary negation
This commit is contained in:
parent
a24b29ebfe
commit
ed8569f1ad
|
@ -77,13 +77,12 @@ func (self *_runtime) evaluateUnaryOperation(node *_unaryOperationNode) Value {
|
|||
return toValue(targetValue.toFloat())
|
||||
case "-":
|
||||
value := targetValue.toFloat()
|
||||
if value == 0 {
|
||||
// TODO Test this
|
||||
sign := float64(-1)
|
||||
if math.Signbit(value) {
|
||||
return positiveZeroValue()
|
||||
sign = 1
|
||||
}
|
||||
return negativeZeroValue()
|
||||
}
|
||||
return toValue(-value)
|
||||
return toValue(math.Copysign(value, sign))
|
||||
case "++=": // Prefix ++
|
||||
resultValue := toValue(+1 + targetValue.toFloat())
|
||||
self.PutValue(target.reference(), resultValue)
|
||||
|
|
Loading…
Reference in New Issue
Block a user