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 rational numbers via a clean OOP API. Optimized with GMP or BCMath when available, with automatic runtime selection. Requires PHP 8.2+ (older versions available).

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Precision-Critical Financial Systems: Enables accurate monetary calculations (e.g., cryptocurrency, multi-currency platforms) where floating-point errors are unacceptable. Replaces custom logic or reliance on bcmath with a robust, maintained library.
  • Scientific/Engineering Applications: Supports arbitrary-precision math for simulations, statistical models, or physics calculations where decimal precision matters (e.g., quantum computing tools, astronomy platforms).
  • Build vs. Buy: Buy for teams needing production-ready precision math without reinventing the wheel. Avoids maintenance overhead of homegrown solutions (e.g., regex-based decimal parsing).
  • Roadmap Priorities:
    • Phase 1: Replace bcmath/gmp calls in core financial logic (e.g., order matching, fee calculations).
    • Phase 2: Extend to analytics (e.g., high-precision statistical aggregations).
    • Phase 3: Integrate with data pipelines (e.g., exact decimal transformations in ETL).
  • Use Cases:
    • Cryptocurrency Exchanges: Exact token balances, gas fee calculations.
    • Insurance/Actuarial Tools: Policy pricing with fractional cents.
    • E-Commerce: Dynamic pricing with tiered discounts (e.g., "Buy 3 for $2.99 each").
    • Data Science: Reproducible results in ML pipelines with exact decimal inputs.

When to Consider This Package

  • Adopt if:

    • Your app requires arbitrary-precision arithmetic (e.g., >15 decimal places) and PHP’s native float/int types are insufficient.
    • You need consistent rounding behavior across environments (avoids bcmath/gmp extension inconsistencies).
    • Your team lacks expertise in low-level precision math (e.g., handling edge cases in division/modulo).
    • You’re building financial, scientific, or cryptographic systems where precision errors could cause compliance/legal risks.
    • You want immutable, chainable math operations (e.g., $total->plus($tax)->dividedBy(100)).
  • Look elsewhere if:

    • You only need basic arithmetic (use native PHP types or bcmath).
    • Your stack cannot upgrade to PHP 8.2 (package drops support for older versions).
    • You require GPU acceleration (this is CPU-bound; consider Rust/C extensions for HPC).
    • Your use case is purely integer-based and fits within PHP_INT_MAX (use GMP directly).
    • You need real-time performance (this prioritizes correctness over speed; benchmark against GMP/BCMath).

How to Pitch It (Stakeholders)

For Executives:

"This library solves a critical gap in PHP’s math capabilities—precision errors cost us money and reputation. For example, in our crypto wallet, a 0.0001 BTC miscalculation due to floating-point rounding could lead to customer disputes or regulatory fines. Brick\Math ensures exact decimal arithmetic, just like Java’s BigDecimal, but natively in PHP. It’s MIT-licensed, battle-tested (2K+ stars), and maintained by the Brick team—no vendor lock-in. The ROI? Fewer bugs in financial systems, faster compliance audits, and the ability to handle edge cases (like 100! or π to 1000 digits) without custom code. We’re not just fixing a bug; we’re future-proofing our math."

For Engineers:

*"Brick\Math gives us three superpowers:

  1. Arbitrary precision: No more bcmath extension headaches or floating-point quirks. Works the same on every server.
  2. Clean API: Immutable objects with fluent methods ($total->plus($tax)->dividedBy(100)) and proper error handling (e.g., RoundingNecessaryException).
  3. Performance: Auto-selects the fastest backend (GMP/BCMath if available, falls back to pure PHP).

Migration path:

  • Start with BigDecimal for financial logic (replace number_format()/bcadd()).
  • Use BigInteger for cryptographic hashes or large IDs.
  • Replace float inputs with BigDecimal::fromFloatExact() to avoid silent precision loss.

Tradeoffs:

  • Slightly higher memory usage for very large numbers (but negligible for typical use cases).
  • Requires PHP 8.2+ (aligns with our roadmap to drop PHP 8.1).

Let’s prototype this in the payment service next sprint—it’s a drop-in replacement for our ad-hoc bcmath calls and will save us from floating-point bugs forever."*

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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope