Why do some T.init evaluate to true while others to false?
Basile B. via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 26 08:38:55 PDT 2016
On Thursday, 26 May 2016 at 15:34:50 UTC, ArturG wrote:
> On Thursday, 26 May 2016 at 15:29:52 UTC, Basile B. wrote:
>
>>
>> float.init is not equal to 0.0f. In D FP points values are
>> initialized to nan (not a number).
>>
>> By the way for strings it works, it's like the array case I
>> described in the first answer).
>
> yes i guess i tested all/most types and know that float.init is
> float.nan but why is nan true and not false?
because nan is not 0 and that the shortcut for float is
if (fpValue) <=> if (fpValue != 0)
if (!fpValue)<=> if (fpValue == 0)
There's no relation between the initializer and the shortcut.
It's not because for some values the shortcut matches to the
initializer that it must always be the case...But I admit I don't
know the exact rationale.
Does anyone know ?
More information about the Digitalmars-d-learn
mailing list