
On Tue, Aug 31, 2021 at 12:35:05PM -0700, Nick Parlante wrote:
You will be relieved to know that we have great fun showing them how == does not work for floating point numbers. It is super memorable how that all comes unglued.
Of course `==` works for floating point numbers. For floats, `x == y` returns True if and only if: - x and y are both zeroes - x and y are both +INF - x and y are both -INF - or x and y have the same numeric value. In other words, it is the intuitive and correct meaning of "equals" for all numbers capable of being represented as a float. People who remember floating point maths on computers prior to the widespread adoption of IEEE-754 will know that this is actually quite a big deal, and not something to sneer at. What doesn't work, for some definition of "doesn't", is everything else about floats: addition, subtraction, multiplication, conversion from decimal, etc. But *equality* is one of the few operations that works exactly. -- Steve