29

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.

crsuarezf
  • 1,201
  • 3
  • 18
  • 33

3 Answers3

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