Floating point values in structs.

Dukc ajieskola at gmail.com
Tue Dec 22 18:10:22 UTC 2020


On Friday, 18 December 2020 at 16:18:12 UTC, Dave P. wrote:
> If the compiler is going to introduce the overhead of 
> initializing all the variables anyway, why set it to nan when 
> integer types get set to the useful default of 0?

Consider default value of `int*`. It is `null`, not a pointer to 
a newly-allocated 0. Most would probably agree that `null` works 
better, because it stands for "empty". 0 may or may not, 
depending on context.

It's this philosophy with floating-point values also. `0.0` might 
seem like a value when no value is intended, with `nan` there are 
no ambiguities.

More about this:
https://digitalmars.com/articles/b81.html
https://dlang.org/blog/2018/10/17/interfacing-d-with-c-arrays-part-1/




More information about the Digitalmars-d-learn mailing list