commit 9daebf9ad38b53e7fc642ff97aa77170bb9bec40
parent 64f32e4f8096bb840f6cd1c1c501c061a96edd60
Author: Fabrice Bellard <fabrice@bellard.org>
Date: Fri, 22 Dec 2023 11:02:39 +0100
fixed js_strtod with large integers (github issue #206)
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c
@@ -9965,12 +9965,13 @@ static inline int to_digit(int c)
}
/* XXX: remove */
-static double js_strtod(const char *p, int radix, BOOL is_float)
+static double js_strtod(const char *str, int radix, BOOL is_float)
{
double d;
int c;
if (!is_float || radix != 10) {
+ const char *p = str;
uint64_t n_max, n;
int int_exp, is_neg;
@@ -9997,6 +9998,8 @@ static double js_strtod(const char *p, int radix, BOOL is_float)
if (n <= n_max) {
n = n * radix + c;
} else {
+ if (radix == 10)
+ goto strtod_case;
int_exp++;
}
p++;
@@ -10008,7 +10011,8 @@ static double js_strtod(const char *p, int radix, BOOL is_float)
if (is_neg)
d = -d;
} else {
- d = strtod(p, NULL);
+ strtod_case:
+ d = strtod(str, NULL);
}
return d;
}
diff --git a/quickjs/tests/test_language.js b/quickjs/tests/test_language.js
@@ -120,6 +120,7 @@ function test_cvt()
assert((Infinity >>> 0) === 0);
assert(((-Infinity) >>> 0) === 0);
assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4));
+ assert((19686109595169230000).toString() === "19686109595169230000");
}
function test_eq()