JavaScript Number Precision
The cluster focuses on JavaScript's use of 64-bit floating-point numbers for all numeric values, causing precision issues with large integers beyond 2^53, limitations in JSON handling, and the role of BigInt as a partial solution.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Even something as simple as integers is problematic, because they are underspecified. Since javascript uses 64 bit floating point numbers for all numeric types, 64 bit integers can not accurately be represented. If you need 64 bit integers, your best bet is to use strings...
So basically, the only numeric type of javascript is a float, which can only represent integers up to 2^53 accurately. Not good if you need an int larger than that.
Why repeat JavaScript's mistake of having all numbers be floats, with no integer type? I thought that one's well known by now :(
You're referring to the optimisation of storing JS Numbers as integers until they get too large, presumably?
JavaScript uses 64 bit floats for all numbers. Unless you deal with particularly huge integers I don’t think there will be problems.“According to the ECMAScript standard, there is only one number type: the double-precision 64-bit binary format IEEE 754 value (numbers between -(253 -1) and 253 -1). There is no specific type for integers. In addition to being able to represent floating-point numbers, the number type has three symbolic values: +Infinity, -Infinity, and NaN (not-a-number).”<a
BigInt is relatively recent, all things considered. JS only having floats is a conception flaw.
Arbitrary precision integers is a JavaScript implementation detail; JSON standard doesn't specify number precision.
Because Numbers in javascripts are floats, and not allowing floats in numbers would be a serious backward compatibility issue.Also, I'm assuming there are performance issues with using bigints.
No, this is independent of BigInt. JITs speculate that numbers are integers for performance.
Only if using the BigInt type: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...all other numbers are floats