in reply to Infinite loop but no reason why
Second, no matter the language, it is not a good idea to compare floating point numbers for equality. Your hunch is correct, precision issues defeat equality. Usually you want to compare the numbers within some tolerance like this:
where small_num is your tolerance for various errors (try .0005 or some such).if ( abs( $first_num - $second_num ) < $small_num ) ) { ... }
Alternatively, you could round them to the same precision and compare.
Phil
|
|---|