]> git.kaiwu.me - quickjs.git/commitdiff
fixed bigint decrementation with JS_LIMB_BITS=64
authorFabrice Bellard <fabrice@bellard.org>
Sat, 31 Oct 2026 11:52:13 +0000 (12:52 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 31 Oct 2026 11:52:13 +0000 (12:52 +0100)
quickjs.c
tests/test_bigint.js

index d4945208b192f40ff82499e77c13fab943051d3f..ad607ae673a8da2397033e2d9bb4a82bf0afc0f3 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -15088,7 +15088,8 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx,
                 {
                     JSBigIntBuf buf2;
                     JSBigInt *p2;
-                    p2 = js_bigint_set_si(&buf2, 2 * (op - OP_dec) - 1);
+                    v = 2 * (op - OP_dec) - 1;
+                    p2 = js_bigint_set_si(&buf2, v);
                     r = js_bigint_add(ctx, p1, p2, 0);
                 }
                 break;
index c734678392cf9cb9bf4eb3c73491d7a7fd0fcbd5..c95fab743a654d8014944d8cd6fffb30d80e4f5c 100644 (file)
@@ -112,6 +112,7 @@ function test_bigint2()
 
 function test_bigint3()
 {
+    var x;
     assert(Number(0xffffffffffffffffn), 18446744073709552000);
     assert(Number(-0xffffffffffffffffn), -18446744073709552000);
     assert(100000000000000000000n == 1e20, true);
@@ -139,6 +140,8 @@ function test_bigint3()
     assert((2n) ** 127n, 170141183460469231731687303715884105728n);
     assert((-256n) ** 11n, -309485009821345068724781056n);
     assert((7n) ** 20n, 79792266297612001n);
+    x = 0x1ffffffffffffffffffffff01n;
+    assert(--x, 0x1ffffffffffffffffffffff00n);
 }
 
 /* pi computation */