I've been using fmod to validate data entry in Terry's Turkeys. You need to check weights are entered in 5g increments. So i take the input, *1000 and take the modulus for 5.
This threw up an odd bug when i inputted 8.065kg. Perfectly valid, as you can see. But rejected by my code. So i did a test:
for ($n = 0; $n < 10; $n += 0.005)
{
$largen = $n*1000;
$mod = $largen % 5;
if (fmod(($largen), 5) != 0 || $largen % 5 != 0)
{
echo "<tr><td>$n</td><td>$largen</td><td>".fmod(($largen), 5)."</td><td>".$mod."</td></tr>";
}
You'll find the output rather odd:
Results
Why's it doing this? It's not just fmod() being weird as it's for floating points, but % too.