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.
2.1m questions
2.1m answers
60 comments
57.0k users