mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Fix Math.pow(-1, +Infinity) => NaN
This commit is contained in:
parent
46f720d27b
commit
302b2f0cbf
|
@ -110,7 +110,7 @@ func builtinMath_pow(call FunctionCall) Value {
|
|||
// TODO Make sure this works according to the specification (15.8.2.13)
|
||||
x := toFloat(call.Argument(0))
|
||||
y := toFloat(call.Argument(1))
|
||||
if x == 1 && math.IsInf(y, 0) {
|
||||
if math.Abs(x) == 1 && math.IsInf(y, 0) {
|
||||
return NaNValue()
|
||||
}
|
||||
return toValue_float64(math.Pow(x, y))
|
||||
|
|
|
@ -220,6 +220,10 @@ func TestMath_pow(t *testing.T) {
|
|||
test(`Math.pow(-0, -1)`, "-Infinity")
|
||||
test(`Math.pow(-0, -2)`, "Infinity")
|
||||
test(`Math.pow(-1, 0.1)`, "NaN")
|
||||
|
||||
test(`
|
||||
[ Math.pow(-1, +Infinity), Math.pow(1, Infinity) ];
|
||||
`, "NaN,NaN")
|
||||
}
|
||||
|
||||
func TestMath_round(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user