[njs] Fixed Number.prototype.toPrecision().

Dmitry Volyntsev xeioex at nginx.com
Wed Feb 19 14:23:28 UTC 2020


details:   https://hg.nginx.org/njs/rev/0173143d7b15
branches:  
changeset: 1334:0173143d7b15
user:      Dmitry Volyntsev <xeioex at nginx.com>
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") },
 


More information about the nginx-devel mailing list