Re:What Is Null? (2010)
by WalterBright on Sunday August 04, 2019 @03:52PM
(#20608848)
> I guess floating point numbers are a special case, since the standard mandates that it includes the NaN value.
NaN is more useful than that. Consider if you've got a sensor array. The data from the array is crunched to produce a result. Suppose there are a few failed sensors in the array. By using NaN's for those sensors' data, you can then tell what part of your crunched output is dependent on that bad data.
If you'd just used 0.0 for the bad sensor data, you'd have no idea.
Oh I agree about that, and I agree that NaN is a good default for an uninitialized floating point variable.
My point was that you don't always, with every variable, need to be able to express an "undefined" or "invalid" value. The type system should be able to express if a given value is nullable or not.
For all variables which are definitely assigned (e.g. "int x = 17") you don't need a special "uninitialized" value, and the type system should be able to reflect that.
I guess floating point numbers are a special case, since the standard mandates that it includes the NaN value.