Introducing ArbiMath: High-Precision Immutable Math for PHP 8
Handling large numbers and complex calculations with precision can be tricky in PHP. While the BCMath extension provides the foundation…
Introducing ArbiMath: High-Precision Immutable Math for PHP 8
Handling large numbers and complex calculations with precision can be tricky in PHP. While the BCMath extension provides the foundation, managing state and ensuring accuracy requires careful implementation.
Meet ArbiMath, a new PHP 8.0 library designed to simplify arbitrary precision mathematics. Built on top of BCMath, ArbiMath offers a clean, object-oriented approach centered around its core ArbiNumber class.
Why ArbiMath?
Arbitrary Precision: Leverages the power of BCMath for calculations that go beyond standard float limitations. Perfect for financial applications, scientific computing, or anywhere precision is paramount. Immutability: ArbiNumber objects are immutable. Every operation returns a new ArbiNumber instance, preventing accidental state changes and making your code safer and easier to reason about. PHP 8.0+ Ready: Built with modern PHP features like strict types and type hinting. Clean API: Provides an intuitive interface for common mathematical operations.
Quick Example
<?php
require 'vendor/autoload.php';
use Shtse8\\ArbiMath\\ArbiNumber;
// Set default precision (optional)
// ArbiNumber::setDefaultPrecision(50);
$num1 = new ArbiNumber('12345678901234567890.12345');
$num2 = new ArbiNumber('98765432109876543210.98765');
$sum = $num1->add($num2);
$product = $num1->multiply($num2);
$ln_val = $num1->ln(); // Natural logarithm
echo "Sum: " . $sum->toString() . "\n";
echo "Product: " . $product->toString() . "\n";
echo "Ln(num1): " . $ln_val->toString() . "\n";
// Check equality (uses precise comparison)
if ($num1->equals(new ArbiNumber('12345678901234567890.12345'))) {
echo "num1 is equal.\n";
}
?>
Getting Started
Installation is easy via Composer:
composer require shtse8/arbimath
Contribute and Explore
ArbiMath is open-source and available on GitHub. We welcome feedback, bug reports, and contributions!
GitHub Repository: https://github.com/shtse8/ArbiMath
Give ArbiMath a try for your next project requiring high-precision math in PHP!
메타데이터
- post_id
- 9bf3ceff185a
- slug
- introducing-arbimath-high-precision-immutable-math-for-php-8-9bf3ceff185a
- url
- https://medium.com/@shtse8/introducing-arbimath-high-precision-immutable-math-for-php-8-9bf3ceff185a
- canonical_url
- https://medium.com/@shtse8/introducing-arbimath-high-precision-immutable-math-for-php-8-9bf3ceff185a
- author_url
- https://medium.com/@shtse8
- status
- ok
- fetched_at
- 2026-06-26 03:39:16