brick/math
Arbitrary-precision math for PHP. Work with big integers, decimals and rationals reliably, with automatic acceleration via GMP or BCMath when available. PHP 8.2+ supported. Stable 0.x release cycles suitable for production.
0.1 + 0.2 ≠ 0.3) are unacceptable. Replace legacy bcmath or custom string-based math logic.MathException as an interface).Use This Package When:
BigDecimal).MathException as an interface).RoundingNecessaryException).Look Elsewhere When:
float or bcmath).0.13 for PHP 8.1 or older).BigDecimal::hasNonZeroFractionalPart()).gmpy2)."This package eliminates precision errors in critical calculations—like financial transactions or cryptographic operations—where even tiny rounding mistakes can cost millions or break security. It’s a drop-in replacement for error-prone floating-point math, with automatic performance optimizations (GMP/BCMath) and a MIT license for risk-free adoption. Used by teams at [example companies], it’s production-ready and future-proof for PHP 8.2+."
*"Brick\Math gives you:
BigDecimal handles 0.1 + 0.2 correctly (no floating-point traps).BigInteger::of(10)->plus(5)->multipliedBy(3).RoundingMode::HalfUp) and granular exceptions (e.g., DivisionByZeroException).Trade-offs:
BigRational or bitwise ops if unfamiliar.Alternatives:
bcmath: Less flexible (no BigInteger bitwise ops), harder to chain.Recommendation: Use this for finance, crypto, or scientific apps. For simple math, stick with native types."*
How can I help you explore Laravel packages today?