Why can't I get large number libraries for javascript to work?

Looking for a library to work with large numbers in javascript (more than 2 ^ 53). I checked a couple of questions ( A large number of JavaScript libraries ? And Is there a bignum library for JavaScript? ), And then changed a bit from javascript-bignum.js and big.js , but the fact is, I cannot imagine the odd numbers, since both

Big(9007199254740995); 

and

 SchemeNumber.fn["string->number"](9007199254740995); 

return

 9007199254740996 

but not

 9007199254740995 

as i expected.

So, am I doing something wrong? Or is there no way to represent large odd numbers?

+4
source share
1 answer

If you say it

 Big(9007199254740995) 

you do not give the bignum library a chance! Your number literal is first parsed by pure JS, in which that number is not exactly representable. You can see it simply with

 window.alert(9007199254740995); 

which alerts 9007199254740996 .

In order for your selected signal library to successfully represent this number, you need to pass it as a string , for example:

 Big('9007199254740995') 

should get you that exact number like bignum.

+8
source

All Articles