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

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

alireza-me/math
===============

30PHP

Since Jan 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Alireza-ME/Math)[ Packagist](https://packagist.org/packages/alireza-me/math)[ RSS](/packages/alireza-me-math/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Math Class
==========

[](#math-class)

This `Math` class provides a collection of useful mathematical operations. It includes basic arithmetic functions, advanced calculations like factorial, prime number checks, GCD, LCM, Fibonacci sequence generation, and more.

Features
--------

[](#features)

- **Prime Number Operations**:

    - Print prime numbers within a specified range.
- **Factorial Calculation**:

    - Calculate the factorial of a given number.
- **Basic Arithmetic**:

    - Add, subtract, multiply, divide, and raise numbers to a power.
- **Greatest Common Divisor (GCD)**:

    - Calculate the GCD of two numbers.
- **Least Common Multiple (LCM)**:

    - Calculate the LCM of two numbers.
- **Fibonacci Sequence**:

    - Generate and print the Fibonacci sequence up to a given number of terms.

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

[](#installation)

No external dependencies are required for this class. Just include the class in your PHP project.

Usage
-----

[](#usage)

### 1. Prime Numbers

[](#1-prime-numbers)

To print all prime numbers between two integers:

```
Math::printPrimeNumbersInRange(10, 50);
```

### 2. Factorial

[](#2-factorial)

To print the factorial of a number:

```
Math::printFactorial(5); // Output: Factorial of 5 is: 120
```

### 3. Basic Arithmetic Operations

[](#3-basic-arithmetic-operations)

You can perform basic arithmetic operations (addition, subtraction, multiplication, division, power) using the `printArithmeticOperation` method.

```
Math::printArithmeticOperation('add', 10, 5);        // Output: 10 + 5 = 15
Math::printArithmeticOperation('subtract', 10, 5);   // Output: 10 - 5 = 5
Math::printArithmeticOperation('multiply', 10, 5);   // Output: 10 * 5 = 50
Math::printArithmeticOperation('divide', 10, 5);     // Output: 10 / 5 = 2
Math::printArithmeticOperation('power', 2, 3);       // Output: 2 ^ 3 = 8
```

### 4. GCD (Greatest Common Divisor)

[](#4-gcd-greatest-common-divisor)

To calculate the GCD of two numbers:

```
echo "GCD of 54 and 24 is: " . Math::gcd(54, 24);  // Output: GCD of 54 and 24 is: 6
```

### 5. LCM (Least Common Multiple)

[](#5-lcm-least-common-multiple)

To calculate the LCM of two numbers:

```
echo "LCM of 54 and 24 is: " . Math::lcm(54, 24);  // Output: LCM of 54 and 24 is: 216
```

### 6. Fibonacci Sequence

[](#6-fibonacci-sequence)

To print the Fibonacci sequence up to a given number of terms:

```
Math::printFibonacci(10);  // Output: Fibonacci sequence up to 10 terms: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
```

Exception Handling
------------------

[](#exception-handling)

- Division by zero is handled using an `InvalidArgumentException`.
- Factorial calculation for negative numbers will also throw an `InvalidArgumentException`.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

Author
------

[](#author)

This class was created by **A\_LiReza\_ME**.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/300219011b5f2d90a6f5676eb23b456dada0816b56b42829bdc02e10647caf71?d=identicon)[Alireza-ME](/maintainers/Alireza-ME)

---

Top Contributors

[![Alireza-ME](https://avatars.githubusercontent.com/u/74488703?v=4)](https://github.com/Alireza-ME "Alireza-ME (16 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/polyfill-intl-idn

Symfony polyfill for intl's idn\_to\_ascii and idn\_to\_utf8 functions

3.4k774.6M90](/packages/symfony-polyfill-intl-idn)[thecodingmachine/safe

PHP core functions that throw exceptions instead of returning FALSE on error

2.5k95.7M455](/packages/thecodingmachine-safe)[php-cs-fixer/shim

A tool to automatically fix PHP code style

386.3M324](/packages/php-cs-fixer-shim)

PHPackages © 2026

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