3 ms·
This sort of thing is why you never compare floating point numbers for equality. Always compare using epsilons appropriately chosen for the circumstances. Floa
by taneq 1y ago
This sort of thing is why you never compare floating point numbers for equality. Always compare using epsilons appropriately chosen for the circumstances.
Floats are Sneaky and Not to be Trusted. :D
- sjrd 1y agoAlways... except when you're actually writing floating point operations. If I'm implementing `sqrt`, I'd better make sure the result is exactly the expected one. Epsilon is 0 in all my unit tests. ;)
- taneq 1y agoThis is true! As an implementor of floating point operations, you want to be exactly correct for all values (glares at Intel :P ) However, as a consumer of said floating point operations, I'm still gonna treat everything as Sneaky And Not To Be Trusted. :P Especially in C++ where this attribute is largely supplied by the compiler being /r/iamverysmart about this sort of thing.