Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In any language I can think of, 0 and 0.0 are the same, once you're comparing them against a double.


Technically what is happening behind the scenes is that for most languages the compiler/interpreter will promote the integer to a double to avoid foot guns.

Nevertheless integer comparisons with any kind of floating point is not a wise choice.

The idiomatic way to compare a double would be to take into account whatever is the double precision epsilon for that language. Or just use the greater/less than like they have in the subsequent if statements in the original code snippet.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: