Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Math Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Precision-Critical Financial Systems: Enable exact decimal arithmetic for currency calculations, tax computations, or accounting where floating-point inaccuracies (e.g., 0.1 + 0.2 ≠ 0.3) are unacceptable. Replace legacy bcmath or custom string-based math logic.
  • Cryptography & Security: Support arbitrary-precision integers for RSA, ECC, or hash functions (e.g., SHA-256) where integer overflows or precision loss could break security.
  • Scientific/Engineering Calculations: Handle large numbers (e.g., astronomical units, quantum physics constants) or high-precision measurements without floating-point rounding errors.
  • Build vs. Buy: Avoid reinventing arbitrary-precision math wheels; leverage a battle-tested, MIT-licensed library with GMP/BCMath optimizations instead of custom implementations.
  • Roadmap for PHP 8.2+: Future-proof applications by adopting a modern, actively maintained package with clear deprecation policies (e.g., MathException as an interface).
  • Data Migration/Serialization: Safely serialize/deserialize numbers across environments (e.g., microservices with varying PHP extensions) without precision loss.

When to Consider This Package

  • Use This Package When:

    • You need arbitrary-precision arithmetic (e.g., >16 decimal places for BigDecimal).
    • Your use case involves financial transactions, cryptography, or scientific computing.
    • You’re using PHP 8.2+ and can adopt breaking changes (e.g., MathException as an interface).
    • You want immutable, chainable math operations with clear error handling (e.g., RoundingNecessaryException).
    • Performance matters: Automatically selects GMP/BCMath for speed if available.
  • Look Elsewhere When:

    • You only need basic floating-point math (use PHP’s native float or bcmath).
    • Your team lacks PHP 8.2+ support (use version 0.13 for PHP 8.1 or older).
    • You’re constrained by legacy code that relies on deprecated methods (e.g., BigDecimal::hasNonZeroFractionalPart()).
    • You need GPU acceleration (consider Rust/Python libraries like gmpy2).
    • Your use case is trivial (e.g., simple counters) and doesn’t justify the dependency.

How to Pitch It (Stakeholders)

For Executives:

"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+."

For Engineers:

*"Brick\Math gives you:

  • Arbitrary precision: BigDecimal handles 0.1 + 0.2 correctly (no floating-point traps).
  • Immutable, chainable API: Clean syntax like BigInteger::of(10)->plus(5)->multipliedBy(3).
  • Performance: Auto-selects GMP/BCMath if available; falls back to pure PHP.
  • Safety: Explicit rounding modes (e.g., RoundingMode::HalfUp) and granular exceptions (e.g., DivisionByZeroException).
  • Compatibility: Works across PHP environments (serialization-safe, no extension dependency hell).

Trade-offs:

  • PHP 8.2+ required (or use older versions for legacy support).
  • Slight learning curve for BigRational or bitwise ops if unfamiliar.

Alternatives:

  • bcmath: Less flexible (no BigInteger bitwise ops), harder to chain.
  • Custom string math: Bug-prone, slower, and harder to maintain.

Recommendation: Use this for finance, crypto, or scientific apps. For simple math, stick with native types."*

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport