PHPackages                             antonienko/positive-modulus - 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. antonienko/positive-modulus

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

antonienko/positive-modulus
===========================

Modulus returning always positive numbers

v1.0(10y ago)02.8kMITPHPPHP &gt;=5.3

Since Jun 15Pushed 10y agoCompare

[ Source](https://github.com/antonienko/PositiveModulus)[ Packagist](https://packagist.org/packages/antonienko/positive-modulus)[ RSS](/packages/antonienko-positive-modulus/feed)WikiDiscussions master Synced 1mo ago

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

Positive Modulus
================

[](#positive-modulus)

[![Build Status](https://camo.githubusercontent.com/756cbf8d53f65611510499540a53f5f4574a51fa55191691d3b148f1b5ee7ac1/68747470733a2f2f6170692e736869707061626c652e636f6d2f70726f6a656374732f3535376561626131656464376632633035323136613662312f62616467653f6272616e63684e616d653d6d6173746572)](https://app.shippable.com/projects/557eaba1edd7f2c05216a6b1/builds/latest)

Php modulus operator `%`, when working with negative numbers will return negative results.

People with a mathematical background sometimes would expect that modulus is always positive.

That's the case when you are trying to iterate on a set of elements by decrementing the iterator, when you reach -1, you want the modulus operation to give you the highest number again to continue the iteration on the last element.

After some research, I found that both behaviours could be mathematically correct, so this library is for those who need a modulus that always returns a positive result.

\##Installation ###Composer This library is available in packagist.org, you can add it to your project via Composer.

In the "require" section of your composer.json file:

Always up to date (bleeding edge, API *not* guaranteed stable)

```
"antonienko/positive-modulus": "dev-master"
```

Specific minor version, API stability

```
"antonienko/positive-modulus": "0.2.*"
```

If you have any problems with the *minimum-stability* setting try appending @dev to the version

```
"antonienko/positive-modulus": "0.2.*@dev"
```

\##Sample Usage

```
PositiveModulus::calc($a, $b);
```

\##License Information Lincensed under **The MIT License (MIT)**. See the LICENSE file for more details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

3990d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fcdc6571b70b8819f1b8b419f4acf0e4117942d456414e85dfe574917ab3ac4?d=identicon)[antonienko](/maintainers/antonienko)

---

Tags

mathmodulus

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/antonienko-positive-modulus/health.svg)

```
[![Health](https://phpackages.com/badges/antonienko-positive-modulus/health.svg)](https://phpackages.com/packages/antonienko-positive-modulus)
```

###  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)[mathjax/mathjax

MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers.

10.8k90.8k1](/packages/mathjax-mathjax)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16720.7M17](/packages/phpseclib-bcmath-compat)[rubix/tensor

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

2751.4M5](/packages/rubix-tensor)[jlawrence/eos

Parse and solve math equations without using 'eval()'.

1071.1M11](/packages/jlawrence-eos)

PHPackages © 2026

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