]> git.kaiwu.me - quickjs.git/commitdiff
fixed Math.sumPrecise
authorFabrice Bellard <fabrice@bellard.org>
Mon, 23 Nov 2026 12:57:27 +0000 (13:57 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Mon, 23 Nov 2026 12:57:27 +0000 (13:57 +0100)
quickjs.c
tests/test_builtin.js

index 7d48a7dca1e06db36ae790ffdc1a70f620b847fe..a2e0b7fc879e6f5ccb25c91e0ec826cb093bce1c 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -49962,7 +49962,7 @@ typedef enum {
 /* we add one extra limb to avoid having to test for overflows during the sum */
 #define SUM_PRECISE_ACC_LEN 39
 
-#define SUM_PRECISE_COUNTER_INIT 250
+#define SUM_PRECISE_COUNTER_INIT 126
 
 typedef struct {
     SumPreciseStateEnum state;
index 9c647d16757b54cb409a1a004b677800fb389490..64c21fcd382fdc43cc6fdba598936f517cd47d8d 100644 (file)
@@ -421,6 +421,7 @@ function test_math()
     assert(Math.hypot(3, 4), 5);
     assert(Math.abs(Math.hypot(3, 4, 5) - 7.0710678118654755) <= 1e-15);
     assert(Math.sumPrecise([1,Number.EPSILON/2,Number.MIN_VALUE]), 1.0000000000000002);
+    assert(Math.sumPrecise(new Array(300).fill(Math.pow(2,53)-1)), 2702159776422297000);
 }
 
 function test_number()