digitalmars.D.learn - why is the default floating point value NAN ?
- Codifies (3/3) Oct 17 2018 I'd have thought it ought to be 0.0 ?
- Codifies (3/6) Oct 17 2018 okay I should have carried on reading the blog, its so
- Dennis (12/14) Oct 17 2018 Indeed, the initial value is not supposed to be useful, it's
- Adam D. Ruppe (3/6) Oct 17 2018 You are supposed to initialize your own variables explicitly. NaN
I'd have thought it ought to be 0.0 ? So far I seen carefully considered and sensible reasons for doing things in D, so why NAN ?
Oct 17 2018
On Wednesday, 17 October 2018 at 15:48:16 UTC, Codifies wrote:I'd have thought it ought to be 0.0 ? So far I seen carefully considered and sensible reasons for doing things in D, so why NAN ?okay I should have carried on reading the blog, its so uninitialized values stick out when debugging...
Oct 17 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.
Oct 17 2018
On Wednesday, 17 October 2018 at 15:48:16 UTC, Codifies wrote:I'd have thought it ought to be 0.0 ? So far I seen carefully considered and sensible reasons for doing things in D, so why NAN ?You are supposed to initialize your own variables explicitly. NaN is a somewhat easy way to indicate that you forgot to do that.
Oct 17 2018