quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

BigInt.asUintN returns signed values for 64-bit width

Open paolo-losi opened this issue 2 months ago • 2 comments

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:

$ ./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:

x & 0xFFFFFFFFFFFFFFFFn

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

paolo-losi avatar Sep 06 '26 11:09 paolo-losi

Hi @bellard and @paolo-losi, could I fix this, if not already fixed?

KaustAbhinand avatar Sep 13 '26 18:09 KaustAbhinand

Fixed.

bellard avatar Sep 26 '26 14:09 bellard