On Thursday, 26 May 2016 at 15:48:18 UTC, Basile B. wrote:
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?
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)"...