simplito/bn-php
Arbitrary-precision math for PHP with a clean, minimal API. Provides big integer/decimal operations beyond native limits, suitable for financial calculations, cryptography, and any code needing exact large-number arithmetic and conversions.
Install via Composer: composer require simplito/bn-php. This library provides arbitrary-precision integer arithmetic (BigNumber class) and is designed to be interoperable with the popular JavaScript bn.js library—especially useful in cross-language or blockchain-related projects (e.g., Ethereum). Start by importing the namespace: use Simplito\BigNum\BigNum;. A minimal usage example:
$bn = BigNum::from(123456789);
$sum = $bn->add(BigNum::from('987654321'));
echo $sum->toString(); // "1111111110"
For base conversion (e.g., hex to BN), use BigNum::from($hexString, 16).
BigNum::from($hex, 16) and format output with $bn->toJSON() or $bn->toString(16).BigNum::from('0x123', 16) on both sides.$fee = BigNum::from($gasLimit)->mul($gasPrice)->div(BigNum::from(1000000000));$bn->gt($other), $bn->lt(), or $bn->eq() for conditional logic instead of casting to strings/numbers.bn.js, this library expects lowercase hex prefixes (0x) but does not require them—you can pass raw hex (e.g., '1a2b'). Omit 0x unless specified in from($str, $base) (where base=16 handles both).bn.js features are implemented (e.g., modPow, extended Euclidean algorithm). Check BigNum source methods—contribution opportunities exist.assertEquals() with toString() because object comparison fails even for identical values.How can I help you explore Laravel packages today?