Conversation

@djlink the first time as a junior dev you accidentally do a f == f comparison

0
0
0
@djlink

looks like a horror movie poster lol
1
0
1

@djlink Funny, because the whole point of denormals (which are otherwise a huge pain) is to guarantee that the difference of two floating point numbers is zero iff they are equal.

1
0
0

@jbqueru @djlink It's obviously OK to compare floats if you know what you're doing. There is a certain amount of FUD around floating point numbers.
https://stackoverflow.com/a/7366183/14768587

1
0
0

@theohonohan @djlink Yup. Most of my CS classes in the first 2 years in college were specifically about how to deal with floats and more specifically how to order operations to maximize precision (I was a math major, and this part of CS was on the side of applied math). I admit I don't remember all of those techniques.

Amusingly, I remember the Dan-0411 bug.

0
0
0

@hyeyoo

The horror version of this would say

"They thought they could trust a floating point comparison"

@djlink

0
0
1

@djlink @Mattmos when I teach rust people just do not get why we have both Eq and PartialEq traits. The world is messy and we’re making you deal with it up front. Much better than finding out the hard way later.

1
0
0
If not for IEEE 754 floating-point compliance, I'd argue we should have just made NaN == NaN and had that be the end of it. (Or, alternatively, have NaN produce an exception like 1/0 by default.) That's a more understandable, less confusing, and in my opinion less error-prone system.

(Whether and how to *sort* NaN so that floats can be Ord is a harder and more debatable question.)
2
0
0

@josh @djlink maybe, but sadly IEEE-754 exists and we couldn’t not follow it

0
0
0

@josh @thejpster @djlink Why does the spec require that they not be equal, anyway? I never understood that and haven't bothered to read it.

1
0
0

@jhpratt @josh something something unordered comparisons something. If x is a number and y is not a number, then x < y is false but also x > y is false. If x == x, then we have to say y != y otherwise this is logically inconsistent. I think.

1
0
0
Seems possible to make a consistent system in which NaN is as well-behaved as infinity, and supports equality and comparison. That's just not the system we got. :(
0
0
0