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

This result is correct or bug? #2230

Closed
behnammodi opened this issue Oct 14, 2019 · 2 comments
Closed

This result is correct or bug? #2230

behnammodi opened this issue Oct 14, 2019 · 2 comments

Comments

@behnammodi
Copy link

Please see this picture:

Screen Shot 2019-10-14 at 4 27 20 PM

@cjihrig cjihrig transferred this issue from nodejs/node Oct 14, 2019
@Hakerh400
Copy link

JavaScript stores all numbers as double-precision binary IEEE 754 floating point values. Each number is internally stored on 64 bits: 1 bit for sign, 52 for mantissa and 11 for exponent. Given that it has limited number of bits available, it can therefore represent only a limited number of different values. Integers are just a small subset of that.

The maximal integer you can safely represent (without losing the precision) is Number.MAX_SAFE_INTEGER, whose value is 9007199254740991. You are trying to represent 123456789012345678, which is larger than max safe integer, so you lost precision. That is expected.

To solve the problem, you can use BigInt (simply add n to the end of your number).

@gireeshpunathil
Copy link
Member

closing as answered

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

3 participants