From: Fabrice Bellard Date: Sat, 31 Oct 2026 12:00:35 +0000 (+0100) Subject: fixed wrong result when comparing a negative BigInt with a negative float (liustack... X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=7852f3a80fa9a80a99d2c311606651d536141863;p=quickjs.git fixed wrong result when comparing a negative BigInt with a negative float (liustack, #583) --- diff --git a/quickjs.c b/quickjs.c index 2443d7c..facb2f7 100644 --- 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) diff --git a/tests/test_bigint.js b/tests/test_bigint.js index c95fab7..25d462c 100644 --- a/tests/test_bigint.js +++ b/tests/test_bigint.js @@ -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()