# js-big-integer

> Yet another class for arbitrary-precision integers in pure JavaScript. Small. Well tested.

Latest version **3.0.26** (published 2024-08-17) · 0 weekly downloads

## Install

```sh
npm install js-big-integer
pnpm add js-big-integer
yarn add js-big-integer
bun add js-big-integer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.26 |
| Published | 2024-08-17 |
| First published | 2014-09-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 43.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Maintainers | yaffle |
| Keywords | BigInteger, BigNumber, bigint, bignum, arbitrary-precision, integer |

## Links

- npm: https://www.npmjs.com/package/js-big-integer
- Repository: https://github.com/Yaffle/BigInteger
- Issues: https://github.com/Yaffle/BigInteger/issues
- npm.io page: https://npm.io/package/js-big-integer

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 3.0.26 (latest) — 2024-08-17
- 3.0.25 — 2023-08-18
- 3.0.24 — 2023-07-15
- 3.0.23 — 2023-04-18
- 3.0.22 — 2023-04-18
- 3.0.21 — 2023-04-18
- 3.0.20 — 2021-08-11
- 3.0.19 — 2021-07-28
- 3.0.18 — 2021-07-28
- 3.0.17 — 2021-07-25
- 3.0.16 — 2021-07-14
- 3.0.15 — 2021-07-06
- 3.0.14 — 2021-05-05
- 3.0.13 — 2021-05-05
- 3.0.12 — 2021-05-05
- … 16 more at https://npm.io/package/js-big-integer/versions

## README

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

Operation              | `BigInteger`                         | `Number`                         | `BigInt` (https://github.com/tc39/proposal-bigint)
-----------------------|--------------------------------------|----------------------------------|---------------------------------------------------
Conversion from String | `BigInteger.BigInt(string)`          | `Number(string)`                 | `BigInt(string)`
Conversion from Number | `BigInteger.BigInt(number)`          | N/A                              | `BigInt(number)`
Conversion to String   | `a.toString(radix)`                  | `a.toString(radix)`              | `a.toString(radix)`
Conversion to Number   | `a.toNumber()`                       | N/A                              | `Number(bigint)`
Addition               | `BigInteger.add(a, b)`               | `a + b`                          | `a + b`
Subtraction            | `BigInteger.subtract(a, b)`          | `a - b`                          | `a - b`
Multiplication         | `BigInteger.multiply(a, b)`          | `0 + a * b`                      | `a * b`
Division               | `BigInteger.divide(a, b)`            | `0 + Math.trunc(a / b)`          | `a / b`
Remainder              | `BigInteger.remainder(a, b)`         | `0 + a % b`                      | `a % b`
Exponentiation         | `BigInteger.exponentiate(a, b)`      | `0 + a**b`                       | `a**b`
Negation               | `BigInteger.unaryMinus(a)`           | `0 - a`                          | `-a`
Comparison             | `BigInteger.equal(a, b)`             | `a === b`                        | `a === b`
...                    | `BigInteger.lessThan(a, b)`          | `a < b`                          | `a < b`
...                    | `BigInteger.greaterThan(a, b)`       | `a > b`                          | `a > b`
...                    | `BigInteger.notEqual(a, b)`          | `a !== b`                        | `a !== b`
...                    | `BigInteger.lessThanOrEqual(a, b)`   | `a <= b`                         | `a <= b`
...                    | `BigInteger.greaterThanOrEqual(a, b)`| `a >= b`                         | `a >= b`
Signed Right Shift     | `BigInteger.signedRightShift(a, b)`  | `a >> b`                         | `a >> b`
Left Shift             | `BigInteger.leftShift(a, b)`         | `a << b`                         | `a << b`

Example
=======
```javascript

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/>

---
_Source: https://npm.io/package/js-big-integer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
