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) =?
If GMP is available, you can use
gmp_mod
Example:
Note that
n
andd
have to be GMP number resources or numeric strings. Anything else won't work¹will both return -51 instead (which is a bug).
¹ running the above in this codepad, will produce 51 in all three cases. It won't do that on my development machine.