Comparing floating point: == vs is

Daniel Murphy yebblies at nospamgmail.com
Sat Jul 16 02:03:51 PDT 2011


"Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message 
news:mailman.1687.1310805329.14074.digitalmars-d-learn at puremagic.com...
> Under what circumstances would a comparison of floating point values 
> return
> true for is but not ==? If I understand corcectly, is does a bit-by-bit
> comparison. So, I would expect that if is returns true, == would return 
> true.
> However, that does not seem to always be the case. Does anyone know why 
> that
> would be?
>
> In particular, I'm trying to write a function for swapping the endianness 
> of
> floating point values, and while it seems to be generally be returning 
> true for
> is, == keeps failing. So, it sounds like I have two floating point values 
> which
> have the exact same bits (since is succeeds) but which aren't equal 
> according
> to ==. I don't understand what's going on at all. Does anyone have a clue 
> what
> might be happening?
>
> - Jonathan M Davis

As of the last release, 'is' for floating point types is broken. (before it 
just did the same as ==)
At compile time, a is b will be true if a and b have the same bit pattern, 
or if a and b are both nans.
At run time, a is b will return true if they have the same bit pattern only, 
but may sometimes return false on platforms other than windows as it 
includes the padding bytes in the comparison. 




More information about the Digitalmars-d-learn mailing list