PHPackages                             fyre/math - 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. fyre/math

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

fyre/math
=========

A math utility library.

v3.0.1(6mo ago)0181MITPHP

Since Oct 26Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreMath)[ Packagist](https://packagist.org/packages/fyre/math)[ RSS](/packages/fyre-math/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (10)Dependencies (4)Versions (24)Used By (1)

FyreMath
========

[](#fyremath)

**FyreMath** is a free, open-source math library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Methods](#methods)

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

[](#installation)

**Using Composer**

```
composer require fyre/math

```

In PHP:

```
use Fyre\Utility\Math;
```

Methods
-------

[](#methods)

**Abs**

Get the absolute value of a number.

- `$number` is the input number.

```
$abs = Math::abs($number);
```

**Acos**

Get the arc cosine of a number.

- `$number` is the input number.

```
$acos = Math::acos($number);
```

**Acosh**

Get the inverse hyperbolic cosine of a number.

- `$number` is the input number.

```
$acosh = Math::acosh($number);
```

**Asin**

Get the arc sine of a number.

- `$number` is the input number.

```
$asin = Math::asin($number);
```

**Asinh**

Get the inverse hyperbolic sine of a number.

- `$number` is the input number.

```
$asinh = Math::asinh($number);
```

**Atan**

Get the arc tangent of a number.

- `$number` is the input number.

```
$atan = Math::atan($number);
```

**Atan2**

Get the arc tangent of 2 numbers.

- `$x` is a number representing the dividend.
- `$y` is a number representing the divisor.

```
$atan2 = Math::atan2($x, $y);
```

**Atanh**

Get the inverse hyperbolic tangent of a number.

- `$number` is the input number.

```
$atanh = Math::atanh($number);
```

**Binary To Decimal**

Convert a binary number to decimal.

- `$binaryString` is the binary string.

```
$decimal = Math::binaryToDecimal($binaryString);
```

**Ceil**

Round a number up.

- `$number` is the input number.

```
$rounded = Math::ceil($number);
```

**Clamp**

Clamp a number between a min and max.

- `$number` is the input number.
- `$min` is a number representing the minimum of the clamped value, and will default to 0.
- `$max` is a number representing the maximum of the clamped value, and will default to *1*.

```
$clamped = Math::clamp($number, $min, $max);
```

**Clamp Percent**

Clamp a number between 0 and 100.

- `$number` is the input number.

```
$clamped = Math::clampPercent($number);
```

**Convert Base**

Convert a number between bases.

- `$number` is the input number.
- `$fromBase` is a number representing the base of the number.
- `$toBase` is a number representing the base to convert to.

```
$newNumber = Math::convertBase($number, $fromBase, $toBase);
```

**Cos**

Get the cosine of a number.

- `$number` is the input number.

```
$cos = Math::cos($number);
```

**Cosh**

Get the hyperbolic cosine of a number.

- `$number` is the input number.

```
$cosh = Math::cosh($number);
```

**Decimal To Binary**

Convert a decimal number to binary.

- `$number` is the input number.

```
$binary = Math::decimalToBinary($number);
```

**Decimal To Hex**

Convert a decimal number to hex.

- `$number` is the input number.

```
$hex = Math::decimalToHex($number);
```

**Decimal To Octal**

Convert a decimal number to octal.

- `$number` is the input number.

```
$octal = Math::decimalToOctal($number);
```

**Degrees To Radians**

Convert a number of degrees to radians.

- `$number` is the input number.

```
$radians = Math::degreesToRadians($number);
```

**Distance**

Calculate the distance between 2 points.

- `$x1` is a number representing the first X co-ordinate.
- `$y1` is a number representing the first Y co-ordinate.
- `$x2` is a number representing the second X co-ordinate.
- `$y2` is a number representing the second Y co-ordinate.

```
$distance = Math::dist($x1, $y1, $x2, $y2);
```

**Exp**

Calculate the exponent of `e`.

- `$number` is the input number.

```
$exp = Math::exp($number);
```

**Exp Minus 1**

Calculate the exponent of `e-1`.

- `$number` is the input number.

```
$expMinus1 = Math::expMinus1($number);
```

**Floor**

Round a number down.

- `$number` is the input number.

```
$rounded = Math::floor($number);
```

**Fmod**

Calculate the modulo of a number with a divisor.

- `$number` is the input number.
- `$divisor` is a number representing the divisor.

```
$modulo = Math::fmod($number, $divisor);
```

**Hex To Decimal**

Convert a hex number to decimal.

- `$hexString` is the hex string.

```
$decimal = Math::hexToDecimal($hexString);
```

**Hypot**

Calculate the length of a point.

- `$x` is a number representing the X co-ordinate.
- `$y` is a number representing the Y co-ordinate.

```
$length = Math::hypot($x, $y);
```

**Inverse Linear Interpolation**

Inverse linear interpolation from one value to another.

- `$v1` is a number representing the minimum of the range.
- `$v2` is a number representing the maximum of the range.
- `$value` is a number representing the value to inverse interpolate.

```
$amount = Math::inverseLerp($v1, $v2, $value);
```

**Is Numeric**

Determine if the value is numeric.

- `$value` is the value to test.

```
$isNumeric = Math::isNumeric($value);
```

**Linear Interpolation**

Linear interpolation from one value to another.

- `$v1` is a number representing the minimum of the range.
- `$v2` is a number representing the maximum of the range.
- `$amount` is a number representing the amount to interpolate.

```
$value = Math::lerp($v1, $v2, $amount);
```

**Log**

Calculate the logarithm.

- `$number` is the input number.
- `$base` is a number representing the logarithmic base, and will default to *E*.

```
$log = Math::log($number, $base);
```

**Log 10**

Calculate the base-10 logarithm.

- `$number` is the input number.

```
$log = Math::log10($number);
```

**Log Plus 1**

Calculate the logarithm of a number + 1.

- `$number` is the input number.

```
$log = Math::logPlus1($number);
```

**Map**

Map a value from one range to another.

- `$number` is the input number.
- `$fromMin` is a number representing the minimum value of the current range.
- `$fromMax` is a number representing the maximum value of the current range.
- `$toMin` is a number representing the minimum value of the target range.
- `$toMax` is a number representing the maximum value of the target range.

```
$mapped = Math::map($number, $fromMin, $fromMax, $toMin, $toMax);
```

**Max**

Find the highest value.

All arguments supplied to this method will be compared.

```
$highest = Math::max(...$numbers);
```

**Min**

Find the lowest value.

All arguments supplied to this method will be compared.

```
$lowest = Math::min(...$numbers);
```

**Octal To Decimal**

Convert an octal number to decimal.

- `$octalString` is the octal string.

```
$decimal = Math::octalToDecimal($octalString);
```

**Pow**

Raise a number to the power of exponent.

- `$number` is the input number.
- `$exponent` is a number representing the exponent.

```
$pow = Math::pow($number, $exponent);
```

**Product**

Calculate the product of values.

All arguments supplied to this method will be multiplied.

```
$product = Math::product(...$numbers);
```

**Radians To Degrees**

Convert a number of radians to degrees.

- `$number` is the input number.

```
$degrees = Math::radiansToDegrees($number);
```

**Random**

Return a random floating-point number.

- `$a` is a number representing the minimum value (inclusive).
- `$b` is a number representing the maximum value (exclusive).

```
$random = Math::random($a, $b);
```

If `$b` is omitted, this function will return a random number between 0 (inclusive) and `$a` (exclusive).

If both arguments are omitted, this function will return a random number between 0 (inclusive) and 1 (exclusive).

**Random Int**

Return a random integer.

- `$a` is a number representing the minimum value (inclusive).
- `$b` is a number representing the maximum value (exclusive).

```
$randomInt = Math::randomInt($a, $b);
```

If `$b` is omitted, this function will return a random number between 0 (inclusive) and `$a` (exclusive).

**Round**

Round a number.

- `$number` is the input number.
- `$precision` is a number representing the number of decimal digits to use, and will default to 0.
- `$mode` is a number representing the rounding mode to use, and will default to *Math::ROUND\_HALF\_UP*.

```
$rounded = Math::round($number, $precision, $mode);
```

**Sin**

Get the sine of a number.

- `$number` is the input number.

```
$sin = Math::sin($number);
```

**Sinh**

Get the hyperbolic sine of a number.

- `$number` is the input number.

```
$sinh = Math::sinh($number);
```

**Sqrt**

Get the square root of a number.

- `$number` is the input number.

```
$sqrt = Math::sqrt($number);
```

**Sum**

Calculate the sum of values.

All arguments supplied to this method will be added.

```
$sum = Math::sum(...$numbers);
```

**Tan**

Get the tangent of a number.

- `$number` is the input number.

```
$tan = Math::tan($number);
```

**Tanh**

Get the hyperbolic tangent of a number.

- `$number` is the input number.

```
$tanh = Math::tanh($number);
```

**To Step**

Round a number to a specified step-size.

- `$number` is the input number.
- `$step` is a number representing the minimum step-size, and will default to *0.01*.

```
$toStep = Math::toStep($number, $step);
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance66

Regular maintenance activity

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~66 days

Recently: every ~21 days

Total

23

Last Release

208d ago

Major Versions

v1.0.5 → v2.02023-07-08

v2.0.14 → v3.02025-09-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/fad81fd5941e3a637c8a5749d05ae3ed9314d5e2fee57f59c3d9ec3b41259c6b?d=identicon)[elusivecodes](/maintainers/elusivecodes)

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (20 commits)")

---

Tags

mathnumberphputility

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/fyre-math/health.svg)

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

PHPackages © 2026

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