From f4b6cee0ccfb91123b5a141ec70ab9b3a47fac37 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 1 Jul 2024 23:43:24 +0200 Subject: [PATCH 1/2] Issue #2543 - adjust toFixed precision range according to spec update. As pointed out in the ecma-262 spec change discussion, the behavior is inconsistent for negative numbers because the exponential fallback assumes all the digits will be displayed. The negative support was motivated just by consistency, without any particular concrete use cases, and it's not supported in other browsers, so this patch removes negatives. Resolves #2543 --- js/src/jsnum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index beff701bd0..598cf7caf0 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -848,7 +848,7 @@ num_toFixed_impl(JSContext* cx, const CallArgs& args) if (!ToInteger(cx, args[0], &prec)) return false; - if (!ComputePrecisionInRange(cx, -20, MAX_PRECISION, prec, &precision)) + if (!ComputePrecisionInRange(cx, 0, MAX_PRECISION, prec, &precision)) return false; } From ef1f142cde96a09842e0a2ed3c9776a264ea2f11 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 2 Jul 2024 00:14:28 +0200 Subject: [PATCH 2/2] Issue #2531 - Adjust rounding in toExponential (and kin) to round up at midpoint. Resolves #2531 --- js/src/dtoa.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/src/dtoa.c b/js/src/dtoa.c index 1df01cc2ae..5d18f8c1e2 100644 --- a/js/src/dtoa.c +++ b/js/src/dtoa.c @@ -1,9 +1,10 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /**************************************************************** * - * The author of this software is David M. Gay. + * The original author of this software is David M. Gay. * * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. + * Copyright (c) 2024 by Moonchild Productions. * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice @@ -2958,7 +2959,7 @@ dtoa } #endif dval(d) += dval(d); - if (dval(d) > ds || (dval(d) == ds && L & 1)) { + if (dval(d) >= ds) { bump_up: while(*--s == '9') if (s == s0) {