double.init is nan ..?

Etienne etcimon at gmail.com
Fri Mar 14 09:14:04 PDT 2014


On 2014-03-14 12:10 PM, Adam D. Ruppe wrote:
> 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.

The cache library stores serialized strings mostly, and returns an empty 
value if there's a get on an empty key (like redis), so I was surprised 
to see get("key").unpack!double == double.init == false even when they 
key doesn't exist.

So, I guess I'll have to modify msgpack-d to give doubles a 0.000 
initialization value!


More information about the Digitalmars-d mailing list