Floating point types default to NaN?

Dave Jones dave at jones.com
Sat Nov 25 09:39:15 UTC 2017


On Friday, 24 November 2017 at 22:38:49 UTC, Jonathan M Davis 
wrote:
> On Friday, November 24, 2017 20:43:14 A Guy With a Question via 
> Digitalmars- d-learn wrote:
>> On Friday, 24 November 2017 at 14:43:24 UTC, Adam D. Ruppe
> That requires data flow analysis, which the compiler doesn't do 
> a lot of, because it can be complicated. It also tends to 
> result in the compiler giving warnings or errors in cases where 
> it's not actually true that the variable is used before it's 
> given a value, because it can't do it perfectly. There was a 
> recent discussion on this in the main newsgroup with regards to 
> guaranteeing with a pointer or reference was initialized to 
> something other than null.

I think he means just spew an error if a float is declared but 
not explicitly initialised... Whats the problem with...

float foo; // compiler error "floats must be explicitly 
initialised"
float foo = float.nan; // old behaviour.

I mean at the end of the day, that would turn a run time error 
into a compile time error which is a good thing isnt it?




More information about the Digitalmars-d-learn mailing list