Derived from this question : (Java) How does java do modulus calculations with negative numbers?
Anywhere to force PHP to return positive 51?
update Looking for a configuration setting to fix, instead hard-guessing
Or other math function like bcmath?
updated Not entire convinced by that java answer, as it does not take account of negative modulus -13+(-64) =?
-13+(-64) =?
Anyway, the post you referenced already gave the correct answer:
$r = $x % $n; if ($r < 0) { $r += abs($n); }
Where $x = -13 and $n = 64.
1.4m articles
1.4m replys
5 comments
57.0k users