Download the PHP package brick/math without Composer

On this page you can find all versions of the php package brick/math. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package math

Brick\Math

A PHP library to work with arbitrary precision numbers.

Build Status Coverage Status Latest Stable Version Total Downloads License

Installation

This library is installable via Composer:

Requirements

This library requires PHP 8.1 or later.

For PHP 8.0 compatibility, you can use version 0.11. For PHP 7.4, you can use version 0.10. For PHP 7.1, 7.2 & 7.3, you can use version 0.9. Note that these PHP versions are EOL and not supported anymore. If you're still using one of these PHP versions, you should consider upgrading as soon as possible.

Although the library can work seamlessly on any PHP installation, it is highly recommended that you install the GMP or BCMath extension to speed up calculations. The fastest available calculator implementation will be automatically selected at runtime.

Project status & release process

While this library is still under development, it is well tested and considered stable enough to use in production environments.

The current releases are numbered 0.x.y. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), y is incremented.

When a breaking change is introduced, a new 0.x version cycle is always started.

It is therefore safe to lock your project to a given release cycle, such as ^0.12.

If you need to upgrade to a newer release cycle, check the release history for a list of changes introduced by each further 0.x.0 version.

Package contents

This library provides the following public classes in the Brick\Math namespace:

And the following exceptions in the Brick\Math\Exception namespace:

Overview

Instantiation

The constructors of the classes are not public, you must use a factory method to obtain an instance.

All classes provide an of() factory method that accepts any of the following types:

Example:

Note that all of() methods accept all the representations above, as long as it can be safely converted to the current type:

Note about native integers: instantiating from an int is safe as long as you don't exceed the maximum value for your platform (PHP_INT_MAX), in which case it would be transparently converted to float by PHP without notice, and could result in a loss of information. In doubt, prefer instantiating from a string, which supports an unlimited numbers of digits:

Note about floating-point values: instantiating from a float might be unsafe, as floating-point values are imprecise by design, and could result in a loss of information. Always prefer instantiating from a string, which supports an unlimited number of digits:

Immutability & chaining

The BigInteger, BigDecimal and BigRational classes are immutable: their value never changes, so that they can be safely passed around. All methods that return a BigInteger, BigDecimal or BigRational 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: plus(), minus(), multipliedBy(), etc. accept the same types as of(). For example, given the following number:

The following lines are equivalent:

Just like of(), other types of BigNumber are acceptable, as long as they can be safely converted to the current type:

Division & rounding

BigInteger

By default, dividing a BigInteger 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 BigDecimal 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 exactlyDividedBy(), 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 BigRational can always be represented exactly:

Bitwise operations

BigInteger supports bitwise operations:

and bit shifting:

Serialization

BigInteger, BigDecimal and BigRational 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.


All versions of math with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brick/math contains the following files

Loading the files please wait ....