Welcome! Log In Create A New Profile

Advanced

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

Dmitry Volyntsev
February 19, 2020 09:24AM
details: https://hg.nginx.org/njs/rev/0173143d7b15
branches:
changeset: 1334:0173143d7b15
user: Dmitry Volyntsev <xeioex@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") },

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

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

Dmitry Volyntsev 300 February 19, 2020 09:24AM



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

Online Users

Guests: 311
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