3.0.25 • Published 9 months ago

js-big-integer v3.0.25

Weekly downloads
259
License
-
Repository
github
Last release
9 months ago

BigInteger

Yet another BigInteger class in JavaScript This library performs arithmetic operations on integers of arbitrary size.

To use it from a web browser:

<script src="BigInteger.js"></script>

To use it from the node.js:

npm install Yaffle/BigInteger

Then:

var BigInteger = require("js-big-integer").BigInteger;

The API is terrible, but small integers are stored as primitive numbers, so operations on small integers are faster. The API was updated to match the API provided by https://github.com/GoogleChromeLabs/jsbi

OperationBigIntegerNumberBigInt (https://github.com/tc39/proposal-bigint)
Conversion from StringBigInteger.BigInt(string)Number(string)BigInt(string)
Conversion from NumberBigInteger.BigInt(number)N/ABigInt(number)
Conversion to Stringa.toString(radix)a.toString(radix)a.toString(radix)
Conversion to Numbera.toNumber()N/ANumber(bigint)
AdditionBigInteger.add(a, b)a + ba + b
SubtractionBigInteger.subtract(a, b)a - ba - b
MultiplicationBigInteger.multiply(a, b)0 + a * ba * b
DivisionBigInteger.divide(a, b)0 + Math.trunc(a / b)a / b
RemainderBigInteger.remainder(a, b)0 + a % ba % b
ExponentiationBigInteger.exponentiate(a, b)0 + a**ba**b
NegationBigInteger.unaryMinus(a)0 - a-a
ComparisonBigInteger.equal(a, b)a === ba === b
...BigInteger.lessThan(a, b)a < ba < b
...BigInteger.greaterThan(a, b)a > ba > b
...BigInteger.notEqual(a, b)a !== ba !== b
...BigInteger.lessThanOrEqual(a, b)a <= ba <= b
...BigInteger.greaterThanOrEqual(a, b)a >= ba >= b
Signed Right ShiftBigInteger.signedRightShift(a, b)a >> ba >> b
Left ShiftBigInteger.leftShift(a, b)a << ba << b

Example

var factorial = function (n) {
  var result = BigInteger.BigInt(1);
  var i = 0;
  while (++i <= n) {
    result = BigInteger.multiply(result, BigInteger.BigInt(i));
  }
  return result;
};

console.log(factorial(30).toString(10));

Other pure JavaScript implementations: 1. http://www.leemon.com/crypto/BigInt.html 2. https://github.com/jtobey/javascript-bignum 3. https://github.com/node-modules/node-biginteger 4. https://github.com/vukicevic/crunch 5. https://github.com/MikeMcl/bignumber.js 6. https://github.com/peterolson/BigInteger.js 7. https://github.com/silentmatt/javascript-biginteger 8. http://www-cs-students.stanford.edu/~tjw/jsbn/ 9. https://github.com/Yaffle/BigInteger 10. https://github.com/peteroupc/BigNumber 11. https://github.com/indutny/bn.js 12. https://github.com/dankogai/js-math-bigint 13. https://github.com/defunctzombie/int 14. https://github.com/dtrebbien/BigDecimal.js 15. https://github.com/iriscouch/bigdecimal.js 16. http://ofmind.net/doc/hapint 17. https://github.com/GoogleChromeLabs/jsbi 18. https://github.com/tabatkins/bignum

Benchmark: http://yaffle.github.io/BigInteger/benchmark/

3.0.24

10 months ago

3.0.25

9 months ago

3.0.23

1 year ago

3.0.21

1 year ago

3.0.22

1 year ago

3.0.20

3 years ago

3.0.18

3 years ago

3.0.19

3 years ago

3.0.17

3 years ago

3.0.16

3 years ago

3.0.15

3 years ago

3.0.14

3 years ago

3.0.12

3 years ago

3.0.13

3 years ago

3.0.11

3 years ago

3.0.10

3 years ago

3.0.8

3 years ago

3.0.9

3 years ago

3.0.7

3 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago