npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bignum-core

v1.0.1

Published

Arbitrary-precision decimal arithmetic for JavaScript.

Readme

bignum-core

Arbitrary-precision decimal arithmetic for JavaScript.

bignum-core exports a single Decimal constructor. Values are stored as a sign, a base-10 exponent, and a digit array, and every operation is rounded to a configurable number of significant digits.

const Decimal = require('bignum-core');
// import Decimal from 'bignum-core';

new Decimal(0.1).plus(0.2).toString();           // '0.3'
new Decimal('1.23456789e+18').sqrt().toFixed(4); // '1111111106.0556'

Install

npm install bignum-core

Node.js (CommonJS and ESM):

const Decimal = require('bignum-core');
import Decimal from 'bignum-core';
import { Decimal } from 'bignum-core';

Browser:

<script src="path/to/bignum-core.js"></script>
<script type="module">
  import Decimal from './path/to/bignum-core.mjs';
</script>

The ES module bignum-core.mjs is the source. bignum-core.js is the generated UMD build (npm run build). TypeScript definitions ship as bignum-core.d.ts.

Precision vs JavaScript numbers

Pass strings (or other Decimal values) when a number has more than about 15 significant digits. Numeric literals are already rounded by JavaScript before they reach the constructor.

new Decimal(1.0000000000000001);   // '1'
new Decimal('1.0000000000000001'); // '1.0000000000000001'

new Decimal(0.7 + 0.1);            // '0.7999999999999999'
new Decimal('0.7').plus('0.1');    // '0.8'

Binary, octal, and hex strings are accepted with a prefix. Underscores are allowed as digit separators.

new Decimal('0xff.f');             // '255.9375'
new Decimal('0b10101100');         // '172'
new Decimal('2_147_483_647');      // '2147483647'

Arithmetic

Instances are immutable: methods return new Decimals.

const x = new Decimal(0.3);
x.minus(0.1).toString();           // '0.2'
x.toString();                      // '0.3'

x.div(3).plus(1).times(9).floor();

Most methods have a short alias (div / dividedBy, mul / times, sub / minus, add / plus, cmp / comparedTo, …).

x.sqrt().div(y).pow(3).eq(x.squareRoot().dividedBy(y).toPower(3));

Static helpers match the instance methods and several Math functions:

Decimal.sqrt('6.98372465832e+9823');
Decimal.pow(2, 0.0979843);
Decimal.max(1, '1e+30', -4);
Decimal.hypot(3, 4);               // '5'
Decimal.sum(0.1, 0.2, 0.3);        // '0.6'

Formatting:

const n = new Decimal(255.5);
n.toExponential(5);                // '2.55500e+2'
n.toFixed(5);                      // '255.50000'
n.toPrecision(5);                  // '255.50'
n.toFraction(1000);                // ['511', '2']

NaN and Infinity are valid values; use isNaN() and isFinite() instead of the global functions.

Configuration

Results are rounded to Decimal.precision significant digits using Decimal.rounding.

Decimal.set({ precision: 5, rounding: Decimal.ROUND_HALF_UP });
new Decimal(5).div(3);             // '1.6667'

Decimal.clone creates an independent constructor with its own settings:

const Money = Decimal.clone({ precision: 2, rounding: Decimal.ROUND_HALF_EVEN });
new Money(1).div(8);               // '0.12'

| Setting | Default | Meaning | |-------------|---------|---------| | precision | 20 | Significant digits kept on each result | | rounding | 4 | Rounding mode (Decimal.ROUND_HALF_UP) | | toExpNeg | -7 | Exponent at which toString switches to exponential form | | toExpPos | 21 | Exponent at which toString switches to exponential form | | minE | -9e15 | Underflow threshold | | maxE | 9e15 | Overflow threshold | | modulo | 1 | Remainder sign convention (1 matches JavaScript %) | | crypto | false | Use a CSPRNG for Decimal.random when available |

Rounding modes: ROUND_UP (0), ROUND_DOWN (1), ROUND_CEIL (2), ROUND_FLOOR (3), ROUND_HALF_UP (4), ROUND_HALF_DOWN (5), ROUND_HALF_EVEN (6), ROUND_HALF_CEIL (7), ROUND_HALF_FLOOR (8). Decimal.EUCLID (9) is a modulo mode only.

Representation

const x = new Decimal(-12345.67);
x.d;  // [12345, 6700000]  limbs, base 1e7
x.e;  // 4                 base-10 exponent
x.s;  // -1                sign

Treat d, e, and s as read-only.

Method-by-method documentation lives in doc/API.html.

Test

npm test

npm test rebuilds the UMD file, then runs the suite. Individual modules: node test/modules/toFraction. Open test/test.html to run the suite in a browser.

Minify

uglifyjs bignum-core.js --source-map url=bignum-core.min.js.map -c -m -o bignum-core.min.js
terser bignum-core.mjs --source-map url=bignum-core.min.mjs.map -c -m --toplevel -o bignum-core.min.mjs

Licence

MIT. Copyright (c) 2026 artemcheiv.