#557·quickjs

BigInt.asUintN returns signed values for 64-bit width

Author: paolo-losiCreated Sep 6, 2026Updated Sep 13, 2026

Summary

BigInt.asUintN() returns signed values for 64-bit inputs whose unsigned result has bit 63 set. It appears to behave like BigInt.asIntN() for this case.

Reproduction

This is reproducible with the current master source as of commit 04be246001599f5995fa2f2d8c91a0f198d3f34c (VERSION 2026-06-04), built with make qjs:

bash
$ ./qjs -e 'console.log(BigInt.asUintN(64, -1n)); console.log(BigInt.asUintN(64, 2n**63n)); console.log(BigInt.asUintN(64, 2n**64n - 1n));'
-1
-9223372036854775808
-1

Expected results for asUintN(64, ...) are:

18446744073709551615
9223372036854775808
18446744073709551615

BigInt.asIntN(64, ...) produces the signed values as expected. The equivalent mask also produces the expected unsigned values:

javascript
x & 0xFFFFFFFFFFFFFFFFn

For example, (-1n & 0xFFFFFFFFFFFFFFFFn) evaluates to 18446744073709551615n.