Why do some T.init evaluate to true while others to false?

ArturG via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 26 09:45:22 PDT 2016


On Thursday, 26 May 2016 at 15:51:39 UTC, Basile B. wrote:

>> Oh, I'm so sorry ! I totally missed the point of the Q.
>>
>> float.nan is not a "unique" value. Several values verify "nan" 
>> (Look at std.math.isNan). So I suppose it's simpler to test 
>> for nullity. Though with the sign there's also two possible 
>> 0...
>
> void main(string[] args)
> {
>     writeln(float.nan == float.init); // false
>     import std.math: isNaN;
>     writeln(isNaN(float.nan));  // true
>     writeln(isNaN(float.init)); //true
> }
>
> So the shortcut in the compiler might be more simple, there is 
> only a single test for "if(myFloat)"...

im just playing with this template[1] is there anything else i 
missed? (if you dont mind)
it basically treats any T.init as false and skips the 
function/delegate and just returns type.

[1] https://dpaste.dzfl.pl/d159d83e3167


More information about the Digitalmars-d-learn mailing list