floating point verification using is?

Steven Schveighoffer schveiguy at yahoo.com
Fri Dec 18 11:09:39 PST 2009

On Fri, 18 Dec 2009 13:49:18 -0500, div0 <div0 at users.sourceforge.net>  

> Hash: SHA1
> Steven Schveighoffer wrote:
>> If I have 2 identical floating point values, how do I ensure they are
>> binary equivalents of eachother?  I'm trying to write some
>> unittest/assert code, and it's not exactly trivial.
>> I thought 'a is b' would work, but it just morphs into a == b, which
>> isn't helpful.  Why doesn't 'is' just do a bit compare for floating  
>> points?
>> -Steve
> Just out of curiosity; how many cases are there where a == b
> and they have different bit patterns?
> I can only think of +-0.
> Otherwise you can only get that with denormalised floats;
> which you won't get on an x86 processor.

nan is the specific one I was trying to test for.

 From my very hazy memory, I think there can even be multiple binary  
representations of nan, but I'm not sure.


More information about the Digitalmars-d-learn mailing list