PHPackages                             powder96/numbers.php - 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. powder96/numbers.php

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

powder96/numbers.php
====================

Advanced Mathematics Library for PHP (port of Numbers.js)

15844.0k↓28.5%18[3 issues](https://github.com/powder96/numbers.php/issues)[2 PRs](https://github.com/powder96/numbers.php/pulls)1PHP

Since Mar 13Pushed 10y ago10 watchersCompare

[ Source](https://github.com/powder96/numbers.php)[ Packagist](https://packagist.org/packages/powder96/numbers.php)[ RSS](/packages/powder96-numbersphp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

Numbers.php
===========

[](#numbersphp)

[Numbers.php](https://github.com/powder96/numbers.php/) - an advanced mathematics toolkit for PHP &gt;= 5.3. It is a port of [Numbers.js](https://github.com/sjkaliski/numbers.js/) - same toolkit for JavaScript.

There is a version of Numbers.php which supports PHP 5.2, but it is no longer developed:

Description
-----------

[](#description)

Numbers.php provides a comprehensive set of mathematical tools that currently are not offered in PHP. These tools include:

- Basic calculations
- Calculus
- Matrix Operations
- Prime Numbers
- Statistics
- More...

A few things to note before using: PHP, like many languages, does not necessarily manage floating points as well as we'd all like it to. For example, if adding decimals, the addition tool won't return the exact value. This is an unfortunate error. Precautions have been made to account for this. After including numbers, you can set an error bound. Anything in this will be considered an "acceptable outcome."

The primary uses cases are calculations and data analysis on the server side. For client side operations, please use [Numbers.js](https://github.com/sjkaliski/numbers.js/).

How to use
----------

[](#how-to-use)

Numbers is pretty straightforward to use.

For example, if we wanted to estimate the integral of sin(x) from -2 to 4, we could:

Use riemann integrals (with 200 subdivisions)

```
use NumbersPHP\Calculus;
use NumbersPHP\Matrix;
use NumbersPHP\Statistic;
use NumbersPHP\Prime;

Calculus::riemann('sin', -2, 4, 200);
```

Or use adaptive simpson quadrature (with epsilon 0.0001)

```
Calculus::adaptiveSimpson('sin', -2, 4, 0.0001);
```

User-defined functions can be used too:

```
function myFunc($x) {
  return 2 * pow($x, 2) + 1;
}
Calculus::riemann('myFunc', -2, 4, 200);

Calculus::adaptiveSimpson(create_function('$x', 'return 2 * pow($x, 2) + 1;'), -2, 4, 0.0001);
```

Now say we wanted to run some matrix calculations:

We can add two matrices

```
$matrix1 = array(array(0, 1, 2),
				 array(3, 4, 5));
$matrix2 = array(array( 6,  7,  8),
				 array( 9, 10, 11));
Matrix::addition($matrix1, $matrix2);
```

We can transpose a matrix

```
Matrix::transpose($array);
```

Numbers also includes some basic prime number analysis. We can check if a number is prime:

```
//basic check
Prime::simple($number);

// Miller�Rabin primality test
Prime::millerRabin($number);
```

The statistics tools include mean, median, mode, standard deviation, random sample generator, correlation, confidence intervals, t-test, chi-square, and more.

```
Statistic::mean($array);
Statistic::median($array);
Statistic::mode($array);
Statistic::standardDev($array);
Statistic::randomSample($lower, $upper, $n);
Statistic::correlation($array1, $array2);
```

Test
----

[](#test)

Download and install these things:

- [PHP &gt;= 5.3](http://php.net/)
- [Composer PHAR](http://getcomposer.org/composer.phar)
- [PHPUnit PHAR](http://pear.phpunit.de/get/phpunit.phar)

Run in the command prompt:

```
	php composer.phar install
	php phpunit.phar --configuration phpunit.xml.dist
```

If you are going to run tests multiple times and you are using Microsoft(R) Windows(TM), you can use the batch file /test.cmd. Do not forget to set the path to PHP, Composer, and PHPUnit in the beginnig of that file.

Authors
-------

[](#authors)

### Numbers.js

[](#numbersjs)

- Steve Kaliski - [sjkaliski](http://twitter.com/sjkaliski)
- David Byrd - [davidbyrd11](http://twitter.com/davidbyrd11)
- Ethan Resnick - [studip101](http://twitter.com/studip101)
- Ethan - [altercation](https://github.com/altercation)
- Hrishikesh Paranjape - [hrishikeshparanjape](https://github.com/hrishikeshparanjape)
- Greg Leppert - [leppert](https://github.com/leppert)
- Lars-Magnus Skog - [ralphtheninja](https://github.com/ralphtheninja)
- Tim Wood - [codearachnid](https://github.com/codearachnid)
- Miles McCrocklin - [milroc](https://github.com/milroc)
- Nate Kohari - [nkohari](https://github.com/nkohari)
- Eric LaForce - [elaforc](https://github.com/elaforc)
- Kartik Talwar - [KartikTalwar](https://github.com/KartikTalwar)
- [btmills](https://github.com/btmills)
- swair shah - [swairshah](https://github.com/swairshah)
- Jason Hutchinson - [Zikes](https://github.com/Zikes)
- Philip I. Thomas - [philipithomas](https://github.com/philipithomas)
- Brandon Benvie - [Benvie](https://github.com/Benvie)
- Larry Battle - [LarryBattle](https://github.com/LarryBattle)
- [kmcgrane](https://github.com/kmcgrane)

### Numbers.php

[](#numbersphp-1)

- [powder96](https://github.com/powder96/)
- [geopal-solutions](https://github.com/geopal-solutions/)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f5deb22f17af2d45fd11f7c8d2aa5cb57eba77ab14a8e27a158e39a38d7dcd1?d=identicon)[powder96](/maintainers/powder96)

---

Top Contributors

[![sjkaliski](https://avatars.githubusercontent.com/u/602845?v=4)](https://github.com/sjkaliski "sjkaliski (106 commits)")[![geopal-solutions](https://avatars.githubusercontent.com/u/3493628?v=4)](https://github.com/geopal-solutions "geopal-solutions (41 commits)")[![ethanresnick](https://avatars.githubusercontent.com/u/471894?v=4)](https://github.com/ethanresnick "ethanresnick (35 commits)")[![KartikTalwar](https://avatars.githubusercontent.com/u/461702?v=4)](https://github.com/KartikTalwar "KartikTalwar (24 commits)")[![mattfowler](https://avatars.githubusercontent.com/u/956511?v=4)](https://github.com/mattfowler "mattfowler (20 commits)")[![milroc](https://avatars.githubusercontent.com/u/542959?v=4)](https://github.com/milroc "milroc (11 commits)")[![napoleond](https://avatars.githubusercontent.com/u/1054155?v=4)](https://github.com/napoleond "napoleond (9 commits)")[![zikes](https://avatars.githubusercontent.com/u/410905?v=4)](https://github.com/zikes "zikes (7 commits)")[![philipithomas](https://avatars.githubusercontent.com/u/1312414?v=4)](https://github.com/philipithomas "philipithomas (7 commits)")[![foundrium](https://avatars.githubusercontent.com/u/264613?v=4)](https://github.com/foundrium "foundrium (5 commits)")[![LarryBattle](https://avatars.githubusercontent.com/u/288263?v=4)](https://github.com/LarryBattle "LarryBattle (4 commits)")[![btmills](https://avatars.githubusercontent.com/u/1709537?v=4)](https://github.com/btmills "btmills (3 commits)")[![hrishikeshparanjape](https://avatars.githubusercontent.com/u/1056667?v=4)](https://github.com/hrishikeshparanjape "hrishikeshparanjape (1 commits)")[![nkohari](https://avatars.githubusercontent.com/u/1576?v=4)](https://github.com/nkohari "nkohari (1 commits)")[![thebyrd](https://avatars.githubusercontent.com/u/823707?v=4)](https://github.com/thebyrd "thebyrd (1 commits)")[![timrwood](https://avatars.githubusercontent.com/u/643885?v=4)](https://github.com/timrwood "timrwood (1 commits)")[![leppert](https://avatars.githubusercontent.com/u/26643?v=4)](https://github.com/leppert "leppert (1 commits)")[![swairshah](https://avatars.githubusercontent.com/u/776578?v=4)](https://github.com/swairshah "swairshah (1 commits)")

### Embed Badge

![Health badge](/badges/powder96-numbersphp/health.svg)

```
[![Health](https://phpackages.com/badges/powder96-numbersphp/health.svg)](https://phpackages.com/packages/powder96-numbersphp)
```

###  Alternatives

[askvortsov/flarum-categories

Traditional Category Layout for Flarum

2327.3k](/packages/askvortsov-flarum-categories)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
