]> git.kaiwu.me - quickjs.git/commitdiff
fixed wrong result when comparing a negative BigInt with a negative float (liustack...
authorFabrice Bellard <fabrice@bellard.org>
Sat, 31 Oct 2026 12:00:35 +0000 (13:00 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 31 Oct 2026 12:00:35 +0000 (13:00 +0100)
quickjs.c
tests/test_bigint.js

index 2443d7cde8f359f2a884509e42c070e409e8478d..facb2f744e010ecd39dd810513e835156088d168 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -12507,9 +12507,9 @@ static int js_bigint_float64_cmp(JSContext *ctx, const JSBigInt *a,
         a_mant = js_bigint_get_mant_exp(ctx, &f, a);
         if (f != e) {
             if (f < e)
-                return -1;
+                return 2 * a_sign - 1;
             else
-                return 1;
+                return 1 - 2 * a_sign;
         } else {
             mant = (mant | ((uint64_t)1 << 52)) << 11; /* align to a_mant */
             if (a_mant < mant)
index c95fab743a654d8014944d8cd6fffb30d80e4f5c..25d462c5e88d5391359232e2680465c470e538f1 100644 (file)
@@ -97,6 +97,11 @@ function test_bigint1()
 
     r = 1n << 32n;
     assert(r, 4294967296n, "1 << 32n === 4294967296n");
+
+    assert(-0.5 < -1n, false);
+    assert(-1n > -0.5, false);
+    assert(-2147483648 < -1n, true);
+    assert(-1n < -2147483648, false);
 }
 
 function test_bigint2()