I'm looking for a Mathematical solution that deals with really (long, big, huge, storms) numbers. I haven't found anything yet, But I don't wanna think that this problem hasn't be solve at this time. I'm looking for an easy Number solution, like Microsoft Excel Precision (30 decimals), or a BigInteger (Java) solution. in Javascript of course.
Asked
Active
Viewed 7.0k times
29
-
1See http://stackoverflow.com/questions/3072307/is-there-a-bignum-library-for-javascript – Crescent Fresh Nov 26 '10 at 22:20
-
1You can use https://www.npmjs.com/package/big-numbers for converting, formatting, arithmetics and trigonometric operation with big numbers – alexey28 May 13 '19 at 06:44
-
Did you ever find a library that handles floating points correctly? Linked answer is integer-only. – aggregate1166877 Sep 28 '21 at 04:38
3 Answers
11
While looking for an big integer library for an ElGamal crypto implementation I tested several libraries with the following results:
I recommend this one: Tom Wu's jsbn.js (http://www-cs-students.stanford.edu/~tjw/jsbn/)
- Comprehensive set of functions and fast
Leemon Baird's big integer library (http://www.leemon.com/crypto/BigInt.js)
- Comprehensive set of functions and pretty fast
- BUT: Negative number representation is buggy!
bignumber.js (https://github.com/MikeMcl/bignumber.js)
- Pretty complete set of functions
- BUT: Converting really big numbers from strings into BigNumber objects result in INFINITY
Scheme arithmetic library for JavaScript (https://github.com/jtobey/javascript-bignum)
- JS-Implementation of Scheme arithmetic functions
- BUT: No function for y= x^e mod n
I haven't tested this by myself: BigNumber (http://jsfromhell.com/classes/bignumber)
- Functions for high precision claculations
- BUT: It's said to be slow due to internal representation of numbers as strings

Torben
- 6,317
- 1
- 33
- 32
-
Does the "BUT" for bignumber.js still hold true - is there an issue about this? – Olga Nov 30 '15 at 15:21
2
There's a BigInteger library for JavaScript available here:
(Note that I haven't used this myself. Try it and see what you think.)

LukeH
- 263,068
- 57
- 365
- 409
-
+1 for *an* answer, but **wow** that script needs refactoring. Completely unnecessary global symbols all over the place, just asking for collisions. – T.J. Crowder Nov 26 '10 at 22:18
-
@TJ I think that one's a more-or-less direct translation of the Java BigDecimal class ... it's been around *forever* – Pointy Nov 26 '10 at 22:21
-
Thanks, it would be great, if it just was a little more easy to understand and extend from. – crsuarezf Nov 27 '10 at 03:38
0
There is also Silent Matt's library for Big Integers. It does not handle decimals.

Jérôme Verstrynge
- 57,710
- 92
- 283
- 453
-
Sorry, but I'was looking for one that manage specially that kind of numbers. :) – crsuarezf Dec 14 '10 at 21:34