back to home

brick / math

Arbitrary-precision arithmetic library for PHP

2,129 stars
93 forks
0 issues
PHP

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing brick/math in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/brick/math)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

Brick\Math A PHP library to work with arbitrary precision numbers. Installation This library is installable via Composer: Requirements This library requires PHP 8.2 or later. For PHP 8.1 compatibility, you can use version . For PHP 8.0, you can use version . For PHP 7.4, you can use version . For PHP 7.1, 7.2 & 7.3, you can use version . Note that PHP versions [!NOTE] > The factory method does not accept values, because casting a float to string can be lossy. > To convert a float to a , use one of the dedicated methods: > > Immutability & chaining The , and classes are immutable: their value never changes, so that they can be safely passed around. All methods that return a , or return a new object, leaving the original object unaffected: The methods can be chained for better readability: Parameter types All methods that accept a number: , , , etc. accept the same types as . For example, given the following number: The following lines are equivalent: Just like , other types of are acceptable, as long as they can be safely converted to the current type: Division & rounding BigInteger By default, dividing a returns the exact result of the division, or throws an exception if the remainder of the division is not zero: You can pass an optional rounding mode to round the result, if necessary: If you're into quotients and remainders, there are methods for this, too: You can even get both at the same time: BigDecimal Dividing a always requires a scale to be specified. If the exact result of the division does not fit in the given scale, a rounding mode must be provided. If you know that the division yields a finite number of decimals places, you can use , which will automatically compute the required scale to fit the result, or throw an exception if the division yields an infinite repeating decimal: BigRational The result of the division of a can always be represented exactly: Bitwise operations supports bitwise operations: • • • • and bit shifting: • • Exceptions All exceptions thrown by this library implement the interface. This means that you can safely catch all exceptions thrown by this library using a single catch clause: If you need more granular control over the exceptions thrown, you can catch the specific exception classes: • • • • • • • Serialization , and can be safely serialized on a machine and unserialized on another, even if these machines do not share the same set of PHP extensions. For example, serializing on a machine with GMP support and unserializing on a machine that does not have this extension installed will still work as expected. PHPStan extension A third-party PHPStan extension is available for this library. It provides more specific throw type narrowing for brick/math methods, so that PHPStan can infer the exact exception classes thrown. Note that this extension is not maintained by the author of brick/math.