BigNum — Arbitrary Precision Integers
JavaScript’s native BigInt constructor throws SyntaxError when given malformed string input, and
TypeError when given floats or numbers outside safe bounds.
BigNum provides total, non-throwing constructors returning Maybe<bigint>, alongside data-last
arithmetic helpers that compose with pipe.
Safe Parsing and Conversions
Section titled “Safe Parsing and Conversions”Data-Last Arithmetic
Section titled “Data-Last Arithmetic”All arithmetic operations are curried and data-last, allowing direct use inside pipelines:
Problems it solves
Section titled “Problems it solves”- Financial ledger arithmetic without precision drift: In billing systems, crypto ledgers, and
ecommerce platforms, calculating money using standard floating-point numbers produces subtle
rounding errors.
BigNumprovides exact integer arithmetic for cents, basis points, and wei usingbigint. - Crypto token and subunit scaling without float loss: Scaling crypto tokens (such as converting
between Ether and 18-decimal-place Wei, or Bitcoin and Satoshis) exceeds JavaScript’s
Number.MAX_SAFE_INTEGER(which caps at ~9 quadrillion).BigNumhandles arbitrarily large integers with mathematical precision. - Safe parsing of 64-bit database identifiers and snowflake IDs: Calling
BigInt()on untrusted query strings or JSON tokens throws runtime exceptions on invalid characters.BigNum.from.stringreturnsMaybe<bigint>, safely handling unvalidated input at API boundaries without try/catch blocks. - Pipelined BigInt transformations and boundary clamping: Chaining mathematical adjustments
(such as calculating fee tiers, applying percentage splits, and clamping transaction minimums)
inside
pipeusing curried, data-last combinators (BigNum.add,BigNum.mul,BigNum.clamp).