Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

solutions like http://code.google.com/p/closure-library/source/browse/closu... have been in use for many years.



Yeah 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


If 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.


That 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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: