Welcome! Log In Create A New Profile

Advanced

[njs] Math.pow() method fix.

Valentin Bartenev
December 16, 2016 10:26AM
details: http://hg.nginx.org/njs/rev/631a3be91d22
branches:
changeset: 286:631a3be91d22
user: Valentin Bartenev <vbart@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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Math.pow() method fix.

Valentin Bartenev 540 December 16, 2016 10:26AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 294
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready