PHPackages                             bermudaphp/number - 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. bermudaphp/number

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

bermudaphp/number
=================

A comprehensive PHP library for advanced number operations and mathematical computations

v2.0.0(11mo ago)0422MITPHPPHP ^8.4CI passing

Since Jul 2Pushed 11mo agoCompare

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

READMEChangelog (2)Dependencies (1)Versions (3)Used By (2)

Bermuda Number
==============

[](#bermuda-number)

A PHP library for number operations, mathematical computations, and statistical analysis.

[![PHP Version](https://camo.githubusercontent.com/504ead6a583c68d8d62d7bfceed24e569ca613d7a36bed380281b3455b5c7b31/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e342d626c7565)](https://php.net)[![Tests](https://github.com/bermudaphp/number/workflows/Tests/badge.svg)](https://github.com/bermudaphp/number/actions)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

**🌍 English | [Русский](README.md)**

📦 Installation
--------------

[](#-installation)

```
composer require bermudafunk/number
```

🎯 Quick Start
-------------

[](#-quick-start)

```
use Bermuda\Stdlib\Number;
use Bermuda\Stdlib\NumberConverter;

// Creation
$num = Number::from(42);
$num = Number::from('0xFF'); // Hex
$num = Number::from('0b1010'); // Binary

// Arithmetic
$result = Number::from(10)
    ->add(5)
    ->multiply(2)
    ->divide(3); // (10 + 5) * 2 / 3

// Mathematical functions
$num = Number::from(16);
echo $num->sqrt()->value; // 4
echo $num->log2()->value; // 4

// Percentages
$price = Number::from(100);
$tax = $price->percent(20); // 20% of 100 = 20
$discount = Number::from(80)->percentOf(100); // 80% of 100

// NumberConverter - safe conversion
$safe = NumberConverter::convertValue('123'); // 123 (int)
$safe = NumberConverter::convertValue('hello'); // 'hello' (string)

// NumberConverter - strict conversion
$strict = NumberConverter::convertToNumber('123'); // 123 (int)
// NumberConverter::convertToNumber('hello'); // InvalidArgumentException
```

📚 Documentation
---------------

[](#-documentation)

### Creating Number Objects

[](#creating-number-objects)

```
// From various types
Number::from(42);           // int
Number::from(3.14);         // float
Number::from('123');        // string
Number::from(true);         // bool -> 1
Number::from(null);         // null -> 0

// Special formats
Number::from('0xFF');       // hex -> 255
Number::from('0755');       // octal -> 493
Number::from('0b1010');     // binary -> 10
Number::from('1e3');        // scientific -> 1000
```

### NumberConverter - Conversion Utilities

[](#numberconverter---conversion-utilities)

```
use Bermuda\Stdlib\NumberConverter;

// Safe conversion - returns original if not a number
$result = NumberConverter::convertValue('123');    // 123 (int)
$result = NumberConverter::convertValue('45.67');  // 45.67 (float)
$result = NumberConverter::convertValue('0xFF');   // 255 (int)
$result = NumberConverter::convertValue('hello');  // 'hello' (string)
$result = NumberConverter::convertValue('');       // '' (string)

// Strict conversion - throws exception for invalid data
$number = NumberConverter::convertToNumber('123');    // 123 (int)
$number = NumberConverter::convertToNumber('45.67');  // 45.67 (float)
$number = NumberConverter::convertToNumber('0xFF');   // 255 (int)

// Exceptions for invalid data
try {
    NumberConverter::convertToNumber('hello');     // InvalidArgumentException
    NumberConverter::convertToNumber('');          // InvalidArgumentException
    NumberConverter::convertToNumber(' 123 ');     // InvalidArgumentException
} catch (InvalidArgumentException $e) {
    echo $e->getMessage(); // Detailed error description
}
```

### Arithmetic Operations

[](#arithmetic-operations)

```
$num = Number::from(10);

$num->add(5);              // 15
$num->subtract(3);         // 7
$num->multiply(2);         // 20
$num->divide(4);           // 2.5
$num->mod(3);              // 1
$num->power(2);            // 100
$num->abs();               // 10
$num->integerDivide(3);    // 3
```

### Mathematical Functions

[](#mathematical-functions)

```
$num = Number::from(16);

// Roots and powers
$num->sqrt();              // 4.0
$num->cbrt();              // 2.52
$num->exp();               // e^16

// Logarithms
$num->log();               // ln(16)
$num->log10();             // log10(16)
$num->log2();              // 4.0

// Trigonometry
$angle = Number::from(M_PI / 2);
$angle->sin();             // 1.0
$angle->cos();             // ~0
$angle->tan();             // large number

// Inverse trigonometric
Number::from(1)->asin();   // π/2
Number::from(1)->acos();   // 0
Number::from(1)->atan();   // π/4
```

### Rounding

[](#rounding)

```
$num = Number::from(3.7);

$num->ceil();              // 4.0
$num->floor();             // 3.0
$num->round();             // 4.0
$num->round(2);            // 3.70
$num->trunc();             // 3
$num->sign();              // 1 (positive)
```

### Type Checking and Properties

[](#type-checking-and-properties)

```
$num = Number::from(42);

// Types
$num->isInteger();         // true
$num->isFloat();           // false
$num->isFinite();          // true
$num->isNaN();             // false

// Mathematical properties
$num->isPositive();        // true
$num->isNegative();        // false
$num->isZero();            // false
$num->isEven();            // true
$num->isOdd();             // false
```

### Utilities

[](#utilities)

```
$a = Number::from(10);
$b = Number::from(20);

// Min/Max/Clamp
$a->max($b);               // 20
$a->min($b);               // 10
$a->clamp(15, 25);         // 15 (clamped to minimum)

// Percentages
$a->percent(25);           // 2.5 (25% of 10)
$a->percentOf($b);         // 50.0 (10 is 50% of 20)
```

### Conversion

[](#conversion)

```
$num = Number::from(255);

// Basic types
$num->toInt();             // 255
$num->toFloat();           // 255.0
$num->toNumber();          // 255

// Number systems
$num->toHex();             // "ff"
$num->toOctal();           // "377"
$num->toBinary();          // "11111111"
$num->toBase(36);          // "73"
```

### Statistical Functions

[](#statistical-functions)

```
$numbers = [1, 2, 3, 4, 5];

Number::mean($numbers);              // 3
Number::median($numbers);            // 3
Number::mode([1, 2, 2, 3]);         // 2.0
Number::standardDeviation($numbers); // ~1.58
Number::midrange($numbers);          // 3
```

### Random Numbers

[](#random-numbers)

```
// Random float from 10 to 20
Number::random(10, 20);

// Random int from 5 to 15
Number::randomInt(5, 15);
```

### Special Functions

[](#special-functions)

```
// Factorial
Number::factorial(5);        // 120

// Fibonacci numbers
Number::fibonacci(10);       // 55

// Ranges
Number::range(1, 5);         // [1, 2, 3, 4, 5]
Number::range(0, 10, 2);     // [0, 2, 4, 6, 8, 10]
Number::range(5, 1, -1);     // [5, 4, 3, 2, 1]
```

### Exception Handling

[](#exception-handling)

```
try {
    // Number exceptions
    Number::from('invalid');    // InvalidArgumentException
    Number::from(10)->divide(0); // ArithmeticError
    Number::factorial(-1);       // InvalidArgumentException

    // NumberConverter exceptions
    NumberConverter::convertToNumber('hello');     // InvalidArgumentException
    NumberConverter::convertToNumber('123abc');    // InvalidArgumentException
    NumberConverter::convertToNumber(' 123 ');     // InvalidArgumentException

} catch (InvalidArgumentException $e) {
    // Invalid input format
} catch (ArithmeticError $e) {
    // Mathematical error (division by zero)
}
```

📋 Requirements
--------------

[](#-requirements)

- PHP 8.4+

📜 License
---------

[](#-license)

MIT License

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance52

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity73

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 ~1814 days

Total

2

Last Release

330d ago

Major Versions

v1.0 → v2.0.02025-06-20

PHP version history (2 changes)v1.0PHP &gt;= 7.2

v2.0.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (29 commits)")

---

Tags

mathematicsmatharithmeticcalculationimmutablenumbernumericstatisticsbase conversionbermuda

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bermudaphp-number/health.svg)

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

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[aza/math

AzaMath - Anizoptera CMF mathematic component. Arbitrary precision arithmetic (for huge integers; BCMath wrapper) and universal convertor between positional numeral systems (supported bases from 2 to 62 inclusive, and systems with custom alphabet; pure PHP realisation, can use GMP and core PHP functions for speed optimization).

1921.9k1](/packages/aza-math)[php-decimal/php-decimal

Correctly-rounded arbitrary precision decimal floating point

781.0M9](/packages/php-decimal-php-decimal)[rtlopez/decimal

An object oriented immutable arbitrary-precision arithmetic library for PHP

27262.8k2](/packages/rtlopez-decimal)

PHPackages © 2026

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