Fix js_strtod with large integers

Ref: a96f440746
This commit is contained in:
Saúl Ibarra Corretgé 2023-12-22 21:46:01 +01:00
parent 119f2c1b4c
commit b8402ad388
2 changed files with 7 additions and 2 deletions

View file

@ -9987,12 +9987,13 @@ static inline int to_digit(int c)
} }
/* XXX: remove */ /* 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; double d;
int c; int c;
if (!is_float || radix != 10) { if (!is_float || radix != 10) {
const char *p = str;
uint64_t n_max, n; uint64_t n_max, n;
int int_exp, is_neg; int int_exp, is_neg;
@ -10019,6 +10020,8 @@ static double js_strtod(const char *p, int radix, BOOL is_float)
if (n <= n_max) { if (n <= n_max) {
n = n * radix + c; n = n * radix + c;
} else { } else {
if (radix == 10)
goto strtod_case;
int_exp++; int_exp++;
} }
p++; p++;
@ -10030,7 +10033,8 @@ static double js_strtod(const char *p, int radix, BOOL is_float)
if (is_neg) if (is_neg)
d = -d; d = -d;
} else { } else {
d = strtod(p, NULL); strtod_case:
d = strtod(str, NULL);
} }
return d; return d;
} }

View file

@ -120,6 +120,7 @@ function test_cvt()
assert((Infinity >>> 0) === 0); assert((Infinity >>> 0) === 0);
assert(((-Infinity) >>> 0) === 0); assert(((-Infinity) >>> 0) === 0);
assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4)); assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4));
assert((19686109595169230000).toString() === "19686109595169230000");
} }
function test_eq() function test_eq()