Skip to content

Commit 0191aea

Browse files
authored
Handle zero limb when counting leading zeroes (#1110)
I opted to take a more general approach than bellard/quickjs@638ec8c so this problem hopefully doesn't show up again in the future. Fixes: #1105
1 parent 3d3b58d commit 0191aea

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

quickjs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10617,6 +10617,8 @@ do { \
1061710617
/* a != 0 */
1061810618
static inline js_limb_t js_limb_clz(js_limb_t a)
1061910619
{
10620+
if (!a)
10621+
return JS_LIMB_BITS;
1062010622
return clz32(a);
1062110623
}
1062210624

tests/test_bigint.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function test_bigint1()
6363

6464
r = 1n << 32n;
6565
assert(r, 4294967296n, "1 << 32n === 4294967296n");
66+
67+
assert(String(-9223372036854775808n), "-9223372036854775808");
6668
}
6769

6870
function test_bigint2()

0 commit comments

Comments
 (0)