[njs] Fixed zero basis handling for scientific notation.

Andrey Zelenkov zelenkov at nginx.com
Wed Jun 7 14:50:02 UTC 2017


details:   http://hg.nginx.org/njs/rev/2cba0bd90189
branches:  
changeset: 354:2cba0bd90189
user:      Andrey Zelenkov <zelenkov at nginx.com>
date:      Wed Jun 07 16:36:13 2017 +0300
description:
Fixed zero basis handling for scientific notation.

diffstat:

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

diffs (32 lines):

diff -r 7196ac334d64 -r 2cba0bd90189 njs/njs_number.c
--- a/njs/njs_number.c	Wed Jun 07 15:45:01 2017 +0300
+++ b/njs/njs_number.c	Wed Jun 07 16:36:13 2017 +0300
@@ -154,8 +154,10 @@ njs_number_dec_parse(u_char **start, u_c
                 p++;
             }
 
-            exponent = minus ? -exponent : exponent;
-            num = num * pow(10.0, exponent);
+            if (num != 0) {
+                exponent = minus ? -exponent : exponent;
+                num = num * pow(10.0, exponent);
+            }
         }
     }
 
diff -r 7196ac334d64 -r 2cba0bd90189 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Jun 07 15:45:01 2017 +0300
+++ b/njs/test/njs_unit_test.c	Wed Jun 07 16:36:13 2017 +0300
@@ -191,6 +191,12 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("1.0e308"),
       nxt_string("1e+308") },
 
+    { nxt_string("0e309"),
+      nxt_string("0") },
+
+    { nxt_string("0e-309"),
+      nxt_string("0") },
+
     { nxt_string("1e"),
       nxt_string("SyntaxError: Unexpected token \"e\" in 1") },
 


More information about the nginx-devel mailing list