The pack
largeNumbers
function largeNumbers(): Pack<{ largeNumbers: typeof rules }>
Install renderer-independent enormous decimal arithmetic and formatting.
Helpers
formatLarge
function formatLarge(input: LargeInput, options: LargeFormatOptions = {}): string
Human-readable rounding with suffix rollover; values beyond named suffixes use engineering notation.
largeNumber
function largeNumber(value: LargeInput = 0): LargeNumber
Convenient public constructor.
largeNumberScales
const largeNumberScales: ReadonlyArray<Readonly<{ name: string; exponent: number; abbreviation: string }>>
Recognized short-scale names; gaps beyond vigintillion fall back to scientific notation.
Classes
LargeNumber
class LargeNumber
Immutable, JSON-safe forty-significant-digit decimals with compressed enormous exponents.
readonly coefficient: string— Signed integer coefficient stored as text so snapshots need no BigInt JSON support.readonly exponent: number— Value is coefficient times ten raised to this exponent.constructor(value: LargeInput = 0, rounding: LargeRounding = 'half-even')static from(value: LargeInput): LargeNumber— Parse without converting decimal text through a JavaScript number.get sign(): -1 | 0 | 1— Sign, including a canonical unsigned zero.compare(input: LargeInput): -1 | 0 | 1— Exact comparison of the retained decimal values.add(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber— Add with bounded exponent alignment and an explicit rounding policy.subtract(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber— Subtract; floor rounding is useful for conservative nonnegative currency spending.multiply(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber— Multiply without ordinary-number overflow.divide(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber— Divide with guard digits and sticky remainder; zero denominators fail explicitly.pow(exponent: number, rounding: LargeRounding = 'half-even'): LargeNumber— Integer exponentiation by squaring, bounded to one million in either direction.sqrt(rounding: LargeRounding = 'half-even'): LargeNumber— Nonnegative square root with decimal guard digits, without converting the magnitude to Number.negate(): LargeNumber— Return the opposite sign.abs(): LargeNumber— Return the nonnegative magnitude.round(places = 0, rounding: LargeRounding = 'half-even'): LargeNumber— Round to decimal places; negative places round to tens, billions and beyond.toNumber(): number— Approximate ordinary number conversion for bounded ratios/UI only; throws on overflow/underflow.toString(): string— Canonical scientific decimal text, preserving every retained digit.toJSON(): string— JSON serialization stores decimal text, never an overflowing Number or a raw BigInt.format(options: LargeFormatOptions = {}): string— Format compact, named, scientific, engineering or bounded plain output.
Constants
LARGE_NUMBER_MAX_EXPONENT
const LARGE_NUMBER_MAX_EXPONENT: 1000000000
Maximum absolute base-ten order of magnitude; arithmetic fails explicitly outside it.
LARGE_NUMBER_PRECISION
const LARGE_NUMBER_PRECISION: 40
Decimal significant digits retained by every arithmetic operation.
Types
LargeFormatOptions
interface LargeFormatOptions
Readable output with bounded size; formatting never changes the numeric value.
notation?: 'compact' | 'named' | 'scientific' | 'engineering' | 'plain'— Default compact: K/M/B/T and named larger suffixes, then engineering notation.significantDigits?: number— One to forty significant digits; default four.
LargeInput
type LargeInput = LargeNumber | string | number | bigint | { coefficient: string; exponent: number }
Exact decimal text, a safe ordinary numeric input, or a canonical decimal pair.
LargeRounding
type LargeRounding = 'half-even' | 'floor' | 'ceil' | 'trunc'
Round ties to even, toward negative/positive infinity, or toward zero.


