Sorting floating-point values, and NaN

Walter Bright newshound2 at digitalmars.com
Tue Nov 12 10:31:41 PST 2013


On 11/12/2013 9:59 AM, Vladimir Panteleev wrote:
> Both of the above hinge on the relative obscurity of NaNs and the problems they
> could cause. People who are not specifically familiar with NaNs and how they
> interact with other floating-point values will treat floating-point values as
> "just numbers", and expect them to compare and sort in the same way as integers.

NaNs are valid values for floating point numbers. Trying to pretend they don't 
exist is a doomed strategy for programmers. I regard this as analogous to the 
regular proposals to hide the fact that char[] are sequences of unicode code 
points, attempts to pretend that integers don't overflow, etc.

Floating point math has some strange characteristics (NaNs are only one such), 
and anyone writing a non-toy fp app needs to learn that stuff. There's no other way.



More information about the Digitalmars-d mailing list