4 ms·
Will ES6 have native support for 64-bit integers and arbitrary-precision numbers? Or at least 64-bit integers? To me, this is the biggest, fundamental problem w
by rpedela 13y ago
Will ES6 have native support for 64-bit integers and arbitrary-precision numbers? Or at least 64-bit integers? To me, this is the biggest, fundamental problem with Javascript.
- kevingadd 13y agoSigned/unsigned 64-bit integers are on the agenda, but I think they are planned for ES7. They're being prototyped in SpiderMonkey right now.
- nonchalance 13y agosolutions like http://code.google.com/p/closure-library/source/browse/closure/goog/math/long.js http://code.google.com/p/closure-library/source/browse/closu... have been in use for many years.
- rpedela 13y agoYeah there are plenty of JS libraries for large numbers, but all of them are a bit of a hack. They are not as fast as native compiler/interpreter support, and there is no obvious way to integrate the logic into other native functions such as JSON.parse and JSON.stringify. So you have to create your own JSON parser which is not as fast like I did: https://github.com/datalanche/json-bignum https://github.com/datalanche/json-bignum
- Raphael 13y agoIf you want to use native JSON, store it as an object with a string. { "small": 2, "large": { "bignum": "-9223372036854775807.4237482374983253298159" } } Then make sure to replace or treat the object as a big number. Granted, it is more busywork.
- rpedela 13y agoThat is fine if the JSON consumer and producer are Javascript. What happens when the producer is a language that handles large numbers correctly? The numbers are rounded in Javascript.