[njs] Math.pow() method fix.

Valentin Bartenev vbart at nginx.com
Fri Dec 16 15:24:26 UTC 2016


details:   http://hg.nginx.org/njs/rev/631a3be91d22
branches:  
changeset: 286:631a3be91d22
user:      Valentin Bartenev <vbart at nginx.com>
date:      Fri Dec 16 17:52:15 2016 +0300
description:
Math.pow() method fix.

diffstat:

 njs/njs_math.c           |  7 ++++---
 njs/test/njs_unit_test.c |  6 ++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diffs (35 lines):

diff -r b5e47a364c02 -r 631a3be91d22 njs/njs_math.c
--- a/njs/njs_math.c	Tue Dec 13 17:50:06 2016 +0300
+++ b/njs/njs_math.c	Fri Dec 16 17:52:15 2016 +0300
@@ -579,11 +579,12 @@ njs_object_math_pow(njs_vm_t *vm, njs_va
         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 {
diff -r b5e47a364c02 -r 631a3be91d22 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Dec 13 17:50:06 2016 +0300
+++ b/njs/test/njs_unit_test.c	Fri Dec 16 17:52:15 2016 +0300
@@ -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") },
 


More information about the nginx-devel mailing list