Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some BigInt values are incorrect. #34801

Closed
bjforte opened this issue Aug 16, 2020 · 1 comment
Closed

Some BigInt values are incorrect. #34801

bjforte opened this issue Aug 16, 2020 · 1 comment

Comments

@bjforte
Copy link

bjforte commented Aug 16, 2020

Node version v12.16.1
64-bit Windows 10 Pro v2004

The BigInt value BigInt(0xFFFFFFFFFFFFFFFF) should be 2^64 - 1 but it's evaluating as 2^64

//Example

const v1 = BigInt(0xFFFFFFFFFFFFFFFF); // 2^64 - 1
const v2 = BigInt(0x10000000000000000); // 2^64

console.log(v1 === v2);
console.log(v1,v2);

// Output

true
18446744073709551616n 18446744073709551616n

@targos
Copy link
Member

targos commented Aug 16, 2020

You need tu use BigInt('0xFFFFFFFFFFFFFFFF') (with a string argument), otherwise the value will be a floating point number, which cannot represent 2^64-1.

@targos targos closed this as completed Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants