1
0
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:
Robert Krimen 2013-02-22 11:49:41 -08:00
parent a24b29ebfe
commit ed8569f1ad

View File

@ -77,13 +77,12 @@ func (self *_runtime) evaluateUnaryOperation(node *_unaryOperationNode) Value {
return toValue(targetValue.toFloat())
case "-":
value := targetValue.toFloat()
if value == 0 {
if math.Signbit(value) {
return positiveZeroValue()
}
return negativeZeroValue()
// TODO Test this
sign := float64(-1)
if math.Signbit(value) {
sign = 1
}
return toValue(-value)
return toValue(math.Copysign(value, sign))
case "++=": // Prefix ++
resultValue := toValue(+1 + targetValue.toFloat())
self.PutValue(target.reference(), resultValue)