antonienko/positive-modulus

Modulus returning always positive numbers

Installs: 2 793

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

pkg:composer/antonienko/positive-modulus

v1.0 2015-06-15 10:53 UTC

This package is not auto-updated.

Last update: 2025-10-11 23:32:50 UTC


README

Build Status

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.