An open API service indexing awesome lists of open source software.

https://github.com/shtse8/arbimath

A PHP 8.0 library for arbitrary precision mathematics using BCMath, featuring an immutable ArbiNumber class.
https://github.com/shtse8/arbimath

arbitrary-precision bcmath immutable library math number php php8

Last synced: 10 months ago
JSON representation

A PHP 8.0 library for arbitrary precision mathematics using BCMath, featuring an immutable ArbiNumber class.

Awesome Lists containing this project

README

          

# 🚀 ArbiMath PHP: Unleash Infinite Precision in Your PHP Applications! 🚀

[![Latest Stable Version](https://img.shields.io/packagist/v/shtse8/arbimath.svg?style=flat-square)](https://packagist.org/packages/shtse8/arbimath)
[![Total Downloads](https://img.shields.io/packagist/dt/shtse8/arbimath.svg?style=flat-square)](https://packagist.org/packages/shtse8/arbimath)
[![License](https://img.shields.io/packagist/l/shtse8/arbimath.svg?style=flat-square)](https://packagist.org/packages/shtse8/arbimath)

**Tired of floating-point inaccuracies ruining your calculations? Need to handle numbers larger than your server's RAM?**

Standard PHP math functions can hit limitations quickly, leading to subtle bugs and precision errors, especially in critical applications like finance, scientific computing, or cryptography.

**✨ Enter ArbiMath PHP: Your ultimate weapon for high-precision mathematics in PHP! ✨**

ArbiMath PHP provides a robust, intuitive, and type-safe `ArbiNumber` class, built upon the battle-tested BCMath extension, allowing you to perform calculations with **virtually unlimited precision**. Say goodbye to precision headaches and hello to reliable results!

## Why Choose ArbiMath PHP? 🤔

* **🎯 Uncompromising Precision:** Perform calculations with the exactness you demand. No more rounding errors, no more approximations. Perfect for financial systems, scientific simulations, and anywhere accuracy is paramount.
* **🐘 Handle HUGE Numbers Effortlessly:** Whether it's astronomical figures or complex cryptographic keys, ArbiMath PHP manages numbers of any magnitude with ease.
* **💻 Clean & Intuitive API:** A thoughtfully designed object-oriented interface makes complex math feel simple. Chain methods for elegant and readable code.
* **✨ Optional Operator Overloading:** Want to write `$a + $b` instead of `$a->add($b)`? Install the (optional) PECL Operator extension and enjoy natural mathematical syntax!
* **⚡ Performance Optimized:** Leverages the highly optimized, low-level BCMath extension for reliable speed.
* ** nowoczesny PHP Ready:** Built for PHP 8.0+, embracing strict types and PSR-12 standards for modern development workflows.

## Quick Start ⚡

```php
mul($pi)->add($smallIncrement)->pow('3');

echo "Result: " . $result->toString() . "\n";
// Need formatting?
echo "Formatted: " . $result->format(10) . "\n"; // Format with separators and 10 decimal places

// With PECL Operator (Optional)
// $result = ($largeNumber * $pi + $smallIncrement) ** 3;
// echo $result;

?>
```

## Installation 🛠️

1. **Require via Composer:**
```bash
composer require shtse8/arbimath
```
2. **Ensure BCMath is Enabled:**
This extension is usually enabled by default, but if not:
```bash
# Example for PHP 8.0 on Debian/Ubuntu:
sudo apt install php8.0-bcmath
# Or consult your OS/PHP documentation
```
3. **(Optional) Install PECL Operator for Operator Overloading:**
*Note: This extension might require manual compilation and compatibility checks.*
```bash
# General steps (adapt for your system):
# git clone https://github.com/php/pecl-php-operator
# cd pecl-php-operator && phpize && ./configure && make && sudo make install
# echo "extension=operator.so" | sudo tee /etc/php/8.0/mods-available/operator.ini
# sudo ln -s /etc/php/8.0/mods-available/operator.ini /etc/php/8.0/cli/conf.d/20-operator.ini
# sudo service php8.0-fpm reload # If using FPM
```

## Core Methods Overview 📚

ArbiMath PHP offers a comprehensive set of methods:

* **Arithmetic:** `add()`, `sub()`, `mul()`, `div()`, `mod()`, `pow()`
* **Comparison:** `isEqual()`, `isSmaller()`, `isGreater()`, `isSmallerOrEqual()`, `isGreaterOrEqual()`
* **Rounding/Truncating:** `round()`, `floor()`, `ceil()`, `truncate()`
* **Logarithms:** `ln()`, `log()`
* **Other Utilities:** `abs()`, `isNegative()`, `isPositive()`, `inc()`, `dec()`, `format()`, `getHumanValue()`, `getHumanUnit()`, `duplicate()`, `toString()` / `__toString()`

*(Refer to the source code or future API documentation for detailed usage.)*

## ❤️ Support The Project ❤️

If ArbiMath PHP helps you tackle complex calculations and saves you time, consider showing your appreciation! Your support helps maintain and improve this library.

Buy Me A Coffee

## Contributing 🤝

Found a bug or have a feature request? Contributions are highly welcome! Please feel free to open an issue or submit a Pull Request.

## License 📄

ArbiMath PHP is open-source software licensed under the [MIT License](LICENSE).