]> git.kaiwu.me - quickjs.git/commitdiff
fixed js_strtod with large integers (github issue #206)
authorFabrice Bellard <fabrice@bellard.org>
Fri, 22 Dec 2023 10:02:39 +0000 (11:02 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Fri, 22 Dec 2023 10:02:39 +0000 (11:02 +0100)
quickjs.c
tests/test_language.js

index d68abf7fb1872980a1206ff5bd43b910c81363fa..2b7f99b2962c83b60d6c64e4afd509f2a8b149e1 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -9950,12 +9950,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;
         
@@ -9982,6 +9983,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++;
@@ -9993,7 +9996,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;
 }
index 8d13deb94e7a04e5011ea2d6618f6cbcf0e1aac2..cc3349d3871b0bcfe25d07533a2e67d775453017 100644 (file)
@@ -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()