So while you can safely compare 0.5 * 2.0 == 1.0, you can't safely compare 0.1 * 2.0 == 0.2 (the former is true, the latter false).
The correct way to compare floating point numbers is
if (abs($x-$y) < $epsilon) {...}
Where $epsilon is a small number.
In reply to Re: eq vs ==
by moritz
in thread eq vs ==
by spikeheap
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |