Hacker News new | ask | show | jobs
by kwhitefoot 3366 days ago
Comparing numbers is easy. The operators are there in the manual.

The hard part is understanding when it is appropriate to compare floating point numbers and how to produce them.

I regularly use floating point numbers as keys in dictionaries and of course all the code quality tools whine about comparisons being inexact. But in my case there is no fuzziness because the keys are all produced by the same method and hence do not suffer from any different rounding errors.

Pretty much every new member of the team sees floats being compared and has heart attack yet the code in question is in the oldest and most reliable component of the whole million line program.

Just don't expect two numbers produced by different expressions that would be mathematically equivalent but have operators in a different order to produce identical results.