]> git.kaiwu.me - njs.git/commitdiff
Math.pow() method fix.
authorValentin Bartenev <vbart@nginx.com>
Fri, 16 Dec 2016 14:52:15 +0000 (17:52 +0300)
committerValentin Bartenev <vbart@nginx.com>
Fri, 16 Dec 2016 14:52:15 +0000 (17:52 +0300)
njs/njs_math.c
njs/test/njs_unit_test.c

index cb3f9932f486e91fa5769cac8361a22448e33a05..4bd636ab8e779a15ebf6a6fe1dcd7b2007554015 100644 (file)
@@ -579,11 +579,12 @@ njs_object_math_pow(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         exponent = args[2].data.u.number;
 
         /*
-         * Accordig to ECMA-262 the result of Math.pow(+/-1, +/-Infinity)
-         * should be NaN.
+         * According to ECMA-262:
+         *  1. If exponent is NaN, the result should be NaN;
+         *  2. The result of Math.pow(+/-1, +/-Infinity) should be NaN.
          */
 
-        if (fabs(base) != 1 || !isinf(exponent)) {
+        if (fabs(base) != 1 || (!isnan(exponent) && !isinf(exponent))) {
             num = pow(base, exponent);
 
         } else {
index 4ebb7c5f24486ea0b1bd6c59e3fb64b82192a599..16d797787ce6bc779e58c672f5c641e22588c926 100644 (file)
@@ -6215,6 +6215,12 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Math.pow()"),
       nxt_string("NaN") },
 
+    { nxt_string("Math.pow(1, NaN)"),
+      nxt_string("NaN") },
+
+    { nxt_string("Math.pow(3, NaN)"),
+      nxt_string("NaN") },
+
     { nxt_string("Math.pow('a', -0)"),
       nxt_string("1") },