Why do some T.init evaluate to true while others to false?
Alex Parrill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 30 14:45:06 PDT 2016
On Friday, 27 May 2016 at 15:49:16 UTC, ArturG wrote:
> On Friday, 27 May 2016 at 15:24:18 UTC, Adam D. Ruppe wrote:
>> On Friday, 27 May 2016 at 15:19:50 UTC, ArturG wrote:
>>> yes but i have to check for that when some one does
>>
>> Why? This is no different than if they set any of the other
>> four billion possible values.
>
> What do you mean?
>
> operation on float.nan gives you a float.nan so why does the
> shortcut evaluate to true and not false wouldnt that make more
> sense?
NaN in IEEE 754 floating-point numbers (the floating-point number
system most languages and processors use) is defined as a number
with all exponent bits set and a non-zero mantissa. The mantissa
value is the "NaN payload", and can be any value.
`is` does a binary comparison on floating-point numbers, so NaNs
with different payloads will not be considered equal, as you have
found out with `float.init !is float.nan`.
More information about the Digitalmars-d-learn
mailing list