diff --git a/builtin_math.go b/builtin_math.go index 48f8e68..37f7d8c 100644 --- a/builtin_math.go +++ b/builtin_math.go @@ -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)) diff --git a/math_test.go b/math_test.go index 2c4cdad..9b22807 100644 --- a/math_test.go +++ b/math_test.go @@ -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) {