double.init is nan ..?

Adam D. Ruppe destructionator at gmail.com
Fri Mar 14 09:10:15 PDT 2014


On Friday, 14 March 2014 at 16:06:17 UTC, bearophile wrote:
> And double.init is a NaN.

Yes, and the reason for this is NaN is similar to null - an 
invalid state, so it can help you to catch uninitialized 
variables.

You should explicitly initialize the variables normally and for 
the cache case, either keep a separate variable to tell if it is 
initialized (since NaN might be a valid cache state, like how an 
int may legitimately be 0) or compare using std.math.isNaN.


More information about the Digitalmars-d mailing list