Download the PHP package fab2s/math without Composer

On this page you can find all versions of the php package fab2s/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

Math

CI QA codecov

A fluent bcmath based Helper to handle high precision calculus in base 10 with a rather strict approach (want precision for something right?). It does not try to be smart and just fails without bcmath, but it does auto detect GMP for faster base conversions.

Bcmath supports numbers of any size and precision up to 2 147 483 647 (or 0x7FFFFFFF) decimals, if there is sufficient memory, represented as strings.

Installation

Math can be installed using composer :

Math is also included in OpinHelper which packages several bellow "Swiss Army Knife" level Helpers covering some of the most annoying aspects of php programing, such as UTF8 string manipulation, high precision Mathematics or properly locking a file

Prerequisites

Math requires bcmath, GMP is auto-detected and used when available for faster base conversions (up to 62).

In practice

As Math is meant to be used where precision matters, it is pretty strict with input numbers : it will throw an exception whenever an input number does not match ^[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)$ after passing though trim().

In practice this means that "-.0051" and "00028.34" are ok, but "1E12", "3,14" or "1.1.1" will throw an exception. This is done so because in bcmath world, "1E12", "1.1.1" and "abc" are all "0", which could result in some disaster if you where to do nothing.

A Math instance is just initialized with a valid base 10 number. From there you can do the math and just cast the instance as string to get the current result at any stage.

The string form of any such calculus is normalized (things like '-0', '+.0' or '0.00' to '0'), which means that you can accurately compare Math instances results:

You can transparently re-use partial $calculus directly as instance when calculating:

Doing so is actually faster than casting a pre-existing instance to string because it does not trigger a normalization (internal number state is only normalized when exporting result) nor a number validation, as internal $number is already valid at all times.

Arguments should be string or Math, but it is ok to use integers up to INT_(32|64).

YOU SHOULD NOT use floats as casting them to string may result in local dependent format, such as using a coma instead of a dot for decimals or just turn them exponential notation which is not supported by bcmath. The way floats are handled in general and by PHP in particular is the very reason why bcmath exists, so even if you trust your locale settings, using floats still kinda defeats the purpose of using such lib.

Internal precision

Precision handling does not rely on bcscale as it is not so reliable IRL. As it is a global setup, it may affect or be affected by far away/unrelated code (with fpm it can actually spread to all PHP processes).

Math handle precisions at both instance and global (limited to the current PHP process) precision. The global precision is stored in a static variable. When set, each new instance will start with this global precision as its own precision (you can still set the instance precision after instantiation). When no global precision is set, initial instance precision defaults to Math::PRECISION (currently 9, or 9 digits after the dot)

Laravel

For those using Laravel, Math comes with a Laravel caster: MathCaster which you can use to directly cast your model properties.

``

Requirements

Math is tested against php 8.1 and 8.2. Additionally, MathCast is tested against Laravel 10 and 11.

Contributing

Contributions are welcome, do not hesitate to open issues and submit pull requests.

License

Math is open-sourced software licensed under the MIT license.


All versions of math with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-bcmath Version *
fab2s/context-exception Version ^2.0|^3.0
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 fab2s/math contains the following files

Loading the files please wait ....