3 ms·
That's why they always teach: "never compare floats for equality." Or maybe they don't teach that anymore, I dunno. See link for the Fundamental Axiom of Floa
by antiquark 5mo ago
That's why they always teach: "never compare floats for equality."
Or maybe they don't teach that anymore, I dunno.
See link for the Fundamental Axiom of Floating Point Arithmetic: All floating point arithmetic operations are exact up to a relative error of epsilon_machine.
https://www.johnbcoughlin.com/posts/floating-point-axiom/ https://www.johnbcoughlin.com/posts/floating-point-axiom/
- cjfd 5mo agoOn the other hand, if you store a small integer in a float it is generally reliable to compare to it. E.g., setting a float to zero and comparing whether the float is zero.
- TomMasz 5mo agoI certainly teach that. When we work problems involving money, I always recommend students use integers for cents and only convert to dollars and cents when they have to print them.