I read here that:
Modulus with non integer numbers will give unpredictable results.
However, I tried to play a bit with it, and it seems to give pretty predictable results:
function mod($a, $b) {
echo "$a % $b = " . ($a % $b) . '<br>';
}
mod(10.3, 4);
mod(10.3, 2);
mod(-5.1, 3);
// OUTPUT:
// 10.3 % 4 = 2
// 10.3 % 2 = 0
// -5.1 % 3 = -2
In other words, the double
seems to be converted to integer
first.
Is there any definition of how %
works when the first operand is double
?