Anyone who doesn't know about this really shouldn't be speaking on what computers are supposedly good at
(This is not a bug. This is documented and expected behavior in pretty much every widely used programming language today. See: IEEE 754)
Discussion
Anyone who doesn't know about this really shouldn't be speaking on what computers are supposedly good at
(This is not a bug. This is documented and expected behavior in pretty much every widely used programming language today. See: IEEE 754)
@aesthr I have acquired a healthy and respectful fear of using the equality operator to compare floats. It's just almost never what one wants, due to finite precision and the weirdness of how NaN works.
This is such a great and classic example of that.
@ferret yeah, but that's not great either, right? because it diverges from the behavior of standard floating point numbers that's established nearly everywhere else
And if you're a programmer and just learning about this now ... I'm so sorry, but someone had to tell you the truth eventually.
@aesthr comparisons for equality without explicitly specifying the precision or maximum allowable error should have been made illegal in all programming languages instead of creating footguns.
this can actually work okay for nearly every case when doing it the right way, which is usually DIY for most environments and very easy to fuck up. may I (un)proudly present the C++ solution as an example: https://en.cppreference.com/cpp/types/numeric_limits/epsilon
@aesthr
i mean, it _can_ work if you stay nicely aligned on the grid of powers of 2 or if you find a cursed bcd/decimal float
@aesthr OK yeah screw programming I'm gonna stick to art
@aesthr I always loved in python when it'd print out 0.3000... skip a bit ...001