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())
|
return toValue(targetValue.toFloat())
|
||||||
case "-":
|
case "-":
|
||||||
value := targetValue.toFloat()
|
value := targetValue.toFloat()
|
||||||
if value == 0 {
|
// TODO Test this
|
||||||
if math.Signbit(value) {
|
sign := float64(-1)
|
||||||
return positiveZeroValue()
|
if math.Signbit(value) {
|
||||||
}
|
sign = 1
|
||||||
return negativeZeroValue()
|
|
||||||
}
|
}
|
||||||
return toValue(-value)
|
return toValue(math.Copysign(value, sign))
|
||||||
case "++=": // Prefix ++
|
case "++=": // Prefix ++
|
||||||
resultValue := toValue(+1 + targetValue.toFloat())
|
resultValue := toValue(+1 + targetValue.toFloat())
|
||||||
self.PutValue(target.reference(), resultValue)
|
self.PutValue(target.reference(), resultValue)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user