Is D floating point semantics too advanced?
Sean Kelly
sean at f4.ca
Sun Aug 26 13:47:59 PDT 2007
Bruno Medeiros wrote:
> Sean Kelly wrote:
>> Walter Bright wrote:
>>> Hans-Eric Grönlund wrote:
>>>> I've written a post on my blog wondering if the floating point
>>>> semantics is too advanced. The problem I have with it is that I can't
>>>> write something like this:
>>>>
>>>> if (someValue == real.nan) {...}
>>>>
>>>> It will never be true, which - for me - is unintuitive.
>>>
>>> The behavior is as specified by the floating point standard IEEE 754.
>>> To change it would break from FORTRAN, C and C++ usage in a way that
>>> would silently break code that is transliterated.
>>
>> It would be a horrible inconsistency, but the 'is' operator could be
>> made to return true in this instance. After all, 'is' tests identity,
>> not equality.
>>
>
> Why would it be inconsistent? Because the equality contract states that
> anything that has the same identity, should also compare equal?
I think it's easier to simply remember that 'is' compares identity for
references and equality everywhere else. It would be easy to forget or
screw up the special treatment of floating point numbers, particularly
in template code. I suggested using it more because it makes conceptual
sense than because it seemed practical to me.
Sean
More information about the Digitalmars-d
mailing list