why is the default floating point value NAN ?

Dennis dkorpel at gmail.com
Wed Oct 17 16:12:16 UTC 2018


On Wednesday, 17 October 2018 at 15:51:21 UTC, Codifies wrote:
> okay I should have carried on reading the blog, its so 
> uninitialized values stick out when debugging...

Indeed, the initial value is not supposed to be useful, it's 
there because dealing with garbage memory when forgetting to 
initialize a variable is hard to debug. That's also why 
characters are initialized to 0xFF. Unfortunately, (associative) 
arrays and integers initialize to an empty array and 0 
respectively by a lack of an 'invalid' value.

These are often useful initial values, so people who didn't know 
about / didn't agree with that philosphy started using default 
initialization. Even the 'Count fequencies of all 2-tuples' 
example on the dlang homepage uses an uninitialized associative 
array.


More information about the Digitalmars-d-learn mailing list