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

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

ktsirangelos/math-functions
===========================

A set of integer-based mathematical operations (divisors, factorials, prime numbers) with XML formatting support for presenting calculation results.

v1.4.0(2y ago)011MITPHPPHP ^8.2

Since Feb 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ktsirangelos/math-functions)[ Packagist](https://packagist.org/packages/ktsirangelos/math-functions)[ RSS](/packages/ktsirangelos-math-functions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

MathFunctions
=============

[](#mathfunctions)

The MathFunctions package provides a set of classes for performing various integer-based mathematical operations. It includes functionalities for calculating divisors, factorials, and identifying prime numbers within an array of integers. Additionally, it offers XML formatting for presenting calculation results.

Table of Contents
-----------------

[](#table-of-contents)

1. [Requirements](#requirements)
2. [Installation](#installation)
3. [Running Unit Tests](#running-unit-tests)
4. [Usage](#usage)
5. [Exceptions](#exceptions)
6. [Contributing](#contributing)
7. [License](#license)

Requirements
------------

[](#requirements)

- [PHP](https://www.php.net/) 8.2 or higher
- [Composer](https://getcomposer.org/) (for installation)

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

[](#installation)

```
$ composer require ktsirangelos/math-functions
```

Running Unit Tests
------------------

[](#running-unit-tests)

To run the unit tests for this library:

1. Clone the GitHub repository

```
$ git clone https://github.com/ktsirangelos/math-functions.git
```

2. Install dependencies

```
$ cd math-functions
$ composer install
```

3. Execute the tests

```
$ ./vendor/bin/phpunit tests
```

Usage
-----

[](#usage)

### Calculating Divisors

[](#calculating-divisors)

To calculate the positive and negative divisors of an integer (excluding 1 and itself), use the `calcDivisors()` method:

```
use MathFunctions\IntegerCalculator;

$integerCalculator = new IntegerCalculator();
// Example usage with integer 12
$divisors = $integerCalculator->calcDivisors(12);
// Expected Output: [-6, -4, -3, -2, 2, 3, 4, 6]
```

### Calculating Factorials

[](#calculating-factorials)

To calculate the factorial of an integer, use the `calcFactorial()` method:

```
use MathFunctions\IntegerCalculator;

$integerCalculator = new IntegerCalculator();
// Example usage with integer 5
$factorial = $integerCalculator->calcFactorial(5);
// Expected Output: 120
```

### Identifying Prime Numbers

[](#identifying-prime-numbers)

To find prime numbers within an array of integers and receive the results in XML format, use the `calcPrimeNumbers()` method:

```
use MathFunctions\IntegerCalculator;

$integerCalculator = new IntegerCalculator();
// Example usage with an array of integers
$primeNumbersXML = $integerCalculator->calcPrimeNumbers([2, 3, 4, 5, 6, 7]);
// Expected Output (XML string):
//
//
//     2
//     3
//     5
//     7
//
//
```

### Formatting Calculation Results

[](#formatting-calculation-results)

You can format calculation results into an XML string using the `toXML()` method:

```
use MathFunctions\Utilities\ResultFormatter;

$resultFormatter = new ResultFormatter();
// Example usage with an array of even numbers
$xmlResult = $resultFormatter->toXML('evenNumbers', [2, 4, 6, 8]);
// Expected Output (XML string):
//
//
//     2
//     4
//     6
//     8
//
//
```

Exceptions
----------

[](#exceptions)

The functions may throw exceptions for invalid inputs. Ensure to catch and handle these exceptions appropriately in your code.

Contributing
------------

[](#contributing)

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Total

5

Last Release

821d ago

### Community

Maintainers

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

---

Top Contributors

[![ktsirangelos](https://avatars.githubusercontent.com/u/91125365?v=4)](https://github.com/ktsirangelos "ktsirangelos (46 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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