float init 0 request

An home at home.com
Fri Aug 14 12:39:46 UTC 2026


On Friday, 14 August 2026 at 06:38:02 UTC, Walter Bright wrote:
> Floats are default initialized to NaN so people will be coerced 
> to explicitly code what they want the initialized value to be.
>
> I've seen enough code where the programmer forgot to initialize 
> a float, it was defaulted to 0, and the wrong result was not 
> detected.
>
> ```d
> float f;     // code reviewer: did the programmer intend it to 
> be 0?
> float g = 0; // code reviewer: yes, the programmer likely meant 
> to initialize it to 0
> ```
>

D advocates for unittest -> what happen to it?
Same as int i; // There is no different than float -> be 
consistent

Happy Coding!




More information about the Digitalmars-d mailing list