Why do comparisons of NaN values behave differently from all other values? That is, all comparisons with the operators ==, <=, >=, <, > where one or both values is NaN
Because mathematics is the field where numbers "just exist". In computing you must initialize those numbers and keep their state according to your needs. At those old days memory initialization worked in the ways you could never rely on. You never could allow yourself to think about this "oh, that would be initialized with 0xCD all the time, my algo will not broke".
So you need proper non-mixing solvent which is sticky enough to not not letting your algorithm getting sucked into and broken. Good algorithms involving numbers are mostly going to work with relations, and those if() relations will be omitted.
This is just grease which you can put into new variable at creation, instead of programming random hell from computer memory. And your algorithm whatever it is, will not break.
Next, when you still suddenly finding out that your algorithm is producing NaNs, it is possible to clean it out, looking into every branch one at a time. Again, "always false" rule is helping a lot in this.