std.math.isIdentical and NaN

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 22 02:41:08 PDT 2015


On Monday, 22 June 2015 at 08:10:20 UTC, Dan Olson wrote:
> Docs for isIdentical say:
>
>    Same as ==, except that positive and negative zero are not 
> identical,
>    and two NANs are identical if they have the same 'payload'.
>
> However, it returns false for NaN's with different signbits but 
> same payload.  Should this be the case?
>
> Ran into this because isIdentical is used in unittests to 
> compare NaN's but I find an occassional test fails due to 
> signbit for some operations on LDC ARM.  I wrote an 
> isNaNWithPayload() predicate for the failing tests, but wonder 
> if isIdentical should ignore signbit for NaNs or have its docs 
> changed.

Well, given the name of the function and the fact that it's 
clearly trying to check for NaN equality rather than treating 
their comparison as always false, I would have expected that it 
would be true for NaNs if they were absolutely identical, which 
presumably includes the signbit, but I really don't know much 
about how NaNs are implemented, so I don't know what the 
implications of that are. Still, it seems odd to compare part of 
the NaN for equality but not all of it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list