From 7852f3a80fa9a80a99d2c311606651d536141863 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Sat, 31 Oct 2026 13:00:35 +0100 Subject: [PATCH] fixed wrong result when comparing a negative BigInt with a negative float (liustack, #583) --- quickjs.c | 4 ++-- tests/test_bigint.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) 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() -- 2.47.3