note 102169 deleted from language.operators.arithmetic by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:08:01 +0000 |
| Subject: | note 102169 deleted from language.operators.arithmetic by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189825@lists.php.net to get a copy of this message | ||
Note Submitter: Walter Tross
----
if you want $n % $m >= 0 and $n % $m == ($n + $m) % $m to hold everywhere except for overflows:
<?php
function modulo($n, $m)
{
$r = $n % $m;
return $r < 0 ? $r + abs($m) : $r; // replace abs($m) with $m if you know that $m > 0
}
?>