@formatjs/bigdecimal
BigInt-backed decimal arithmetic for ECMA-402 polyfills
Last updated 8 months ago by longlho .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @formatjs/bigdecimal 
SYNC missed versions from official npm registry.

@formatjs/bigdecimal

BigInt-backed decimal arithmetic library designed as a lightweight replacement for decimal.js in ECMA-402 polyfills.

Representation

Values are represented as mantissa × 10^exponent where:

  • mantissa is a bigint (signed, normalized — no trailing zeros)
  • exponent is a number (integer scaling factor)
  • Special flags handle NaN, ±Infinity, and -0

Normalization removes long runs of decimal zeros in eight-digit chunks, then handles the remaining digits. Arithmetic values and division precision stay unchanged.

API

Implements the 27 methods used by @formatjs/ecma402-abstract:

  • Arithmetic: times, div, plus, minus, mod, abs, negated, pow, floor, ceil, log
  • Comparison: eq, lessThan, greaterThan, lessThanOrEqualTo, greaterThanOrEqualTo
  • Queries: isZero, isNaN, isFinite, isNegative, isPositive, isInteger
  • Conversion: toNumber, toString
  • Static: BigDecimal.pow, BigDecimal.set

Internal arithmetic lazily retains powers of ten through 10^64 (at most 65 BigInts). Larger powers remain uncached. Safe integer Number inputs skip string parsing; fractional/unsafe values retain their decimal-string representation.

toNumber() converts unscaled integer coefficients directly from BigInt, with binary64 rounding. Fractional/scaled values retain decimal-text conversion; NaN, infinities and signed zero keep their explicit handling.

Division by signed powers of ten shifts the exponent when scale arithmetic is safe. Other divisors and unsafe exponents retain the 40-digit scaled division path. Signed zero and nonfinite values keep their existing handling.

Current Tags

  • 0.2.10                                ...           latest (a month ago)

12 Versions

  • 0.2.10                                ...           a month ago
  • 0.2.9                                ...           a month ago
  • 0.2.8                                ...           a month ago
  • 0.2.7                                ...           5 months ago
  • 0.2.6                                ...           6 months ago
  • 0.2.5                                ...           6 months ago
  • 0.2.4                                ...           6 months ago
  • 0.2.3                                ...           7 months ago
  • 0.2.2                                ...           7 months ago
  • 0.2.1                                ...           7 months ago
  • 0.2.0                                ...           8 months ago
  • 0.1.0                                ...           8 months ago
Downloads
Total 33
Today 0
This Week 0
This Month 23
Last Day 0
Last Week 16
Last Month 10
Dependencies (0)
None
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE