float init 0 request

Walter Bright newshound2 at digitalmars.com
Sat Aug 15 04:42:24 UTC 2026


Ada was developed to be a safe language before NaNs existed. Being curious, I 
googled what Ada did with default initialization:

"Ada does not automatically default initialize standalone floating-point 
variables (or other scalar types) to a specific value like 0.0. If you declare a 
floating-point variable without an explicit initialization expression, its value 
is uninitialized, and reading it before assigning a value is erroneous behavior."

and:

"Compilers like GNAT provide pragmas (such as Initialize_Scalars) or specific 
command-line flags during development to fill uninitialized scalar variables 
with invalid or abnormal values. This helps catch uninitialized variable bugs 
early via constraint checks rather than relying on an accidental default zero."

and:

"While standard Fortran does not enforce this by default, many legacy and modern 
Fortran compilers (such as gfortran) include specific compiler options like 
-finit-real=nan. This instructs the compiler to initialize all unallocated or 
undefined real variables to a Signaling NaN (sNaN)."

Looks like I'm not the only one advocating this for bug reduction.



Some outside opinions:

https://stackoverflow.com/questions/1036686/is-it-a-good-idea-to-use-ieee754-floating-point-nan-for-values-which-are-not-set


More information about the Digitalmars-d mailing list