On 14/02/2012 15:39, Joshua Reusch wrote:
Hello,

why does this assertion fail:

assert(float.nan == float.nan);

there is the std.math.isNaN function which works correctly, but why can I not 
just use the
comparison ?

A NaN typically denotes some kind of invalid computation. If the results of two invalid computations were considered equal, it would probably cause problems.

Another way to think of it is to consider NaN as an unknown value. Two unknown values cannot be considered to be equal to each other. OK, so whether they're equal or not is actually unknown. If there were such a thing as bool.nan, equality comparisons in which at least one operand is NaN would probably evaluate to it. Indeed, null in SQL works this way. But in the absence of this in D, the best design has turned out to be to consider NaNs unequal.

Stewart.

Reply via email to