details:   https://hg.nginx.org/njs/rev/0173143d7b15
branches:  
changeset: 1334:0173143d7b15
user:      Dmitry Volyntsev <[email protected]>
date:      Wed Feb 19 17:21:32 2020 +0300
description:
Fixed Number.prototype.toPrecision().

This closes #290 issue on Github.

diffstat:

 src/njs_dtoa.c           |  2 +-
 src/test/njs_unit_test.c |  4 ++++
 2 files changed, 5 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r f5adc2ea2d53 -r 0173143d7b15 src/njs_dtoa.c
--- a/src/njs_dtoa.c    Tue Feb 11 01:48:24 2020 +0300
+++ b/src/njs_dtoa.c    Wed Feb 19 17:21:32 2020 +0300
@@ -532,7 +532,7 @@ njs_dtoa_prec_format(char *start, size_t
         if (point < (int) prec) {
             start[point] = '.';
 
-            njs_memset(&start[point + 1], '0', prec - len);
+            njs_memset(&start[point + 1], '0', prec - point);
         }
 
     } else if (point < (int) prec) {
diff -r f5adc2ea2d53 -r 0173143d7b15 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c  Tue Feb 11 01:48:24 2020 +0300
+++ b/src/test/njs_unit_test.c  Wed Feb 19 17:21:32 2020 +0300
@@ -609,6 +609,10 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("(-(2**10000)).toPrecision()"),
       njs_str("-Infinity") },
 
+    { njs_str("var v = parseFloat('9'.repeat(98));"
+              "[98,100].map(p=>v.toPrecision(p).length)"),
+      njs_str("98,101") },
+
     { njs_str("(-0).toPrecision(2)"),
       njs_str("0.0") },
 
_______________________________________________
nginx-devel mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to