PHPackages                             rican7/mathematician - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rican7/mathematician

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

rican7/mathematician
====================

A PHP mathematics library for simpler, more reliable math operations... even on big numbers

0.2.0(12y ago)30522[1 issues](https://github.com/Rican7/mathematician/issues)[1 PRs](https://github.com/Rican7/mathematician/pulls)MITPHPPHP &gt;=5.3.0

Since Apr 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Rican7/mathematician)[ Packagist](https://packagist.org/packages/rican7/mathematician)[ RSS](/packages/rican7-mathematician/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Mathematician
=============

[](#mathematician)

[![Build Status](https://camo.githubusercontent.com/9f2a135c3c1a6c27846a9e44062a022c4c9a64fce00831c7f8a05e70d2c2714d/68747470733a2f2f7472617669732d63692e6f72672f526963616e372f6d617468656d6174696369616e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Rican7/mathematician)[![Total Downloads](https://camo.githubusercontent.com/309139cbbbfc369344d899ed41f51e02105792c0132ccdadf0a11e62ae183025/68747470733a2f2f706f7365722e707567782e6f72672f526963616e372f6d617468656d6174696369616e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/Rican7/mathematician)[![Latest Stable Version](https://camo.githubusercontent.com/895e6f1b33e1a553f56be499d0646e7ecd3ebd9b7c040a99c8b70afe60e18b0e/68747470733a2f2f706f7365722e707567782e6f72672f526963616e372f6d617468656d6174696369616e2f762f737461626c652e706e67)](https://packagist.org/packages/Rican7/mathematician)

Mathematician is a PHP mathematics library for simpler, more reliable math operations... even on big numbers.

Face it: working with numbers in PHP is sub-par. This library aims to change that. The design goal of this library is to make it easier to work with numbers, regardless of size/precision or what extension the system has loaded. Portability and ease of use.

Why?
----

[](#why)

Why create or even use a library like this? Well, working with numbers in PHP is quite the struggle.

Unlike many languages (Python, Ruby, etc), when dividing an `integer` by an `integer` you get a result that is of the type: `float`. In fact, there's actually no `//` operation like there is in JavaScript to do integer division.

Not only that, but what happens when you want to work with numbers that are larger than `PHP_INT_MAX`? When adding `1` to `PHP_INT_MAX`... you get a float again. Which means you instantly lose precision. Try to cast it back to an integer and you'll get a negative number (thanks overflow). Its rough... so naturally you turn to one of two extensions for working with big numbers: `bcmath` or `gmp`. Well, now your application/library is dependent on a compiled extension and is less portable, not to mention that they aren't equal in functionality (have fun with binary operations in BC Math).

Anyway, I think you get the point here. This library was born out of my frustrations with the above. Hopefully this library eases the pain for you so you don't have to experience what I did. :P

Installation
------------

[](#installation)

1. [Get Composer](https://getcomposer.org/)
2. Add **"rican7/mathematician"** to your composer.json: `composer require rican7/mathematician 0.x.x`
3. Include the Composer autoloader `
