Movement against float.init being nan
Ali Çehreli
acehreli at yahoo.com
Tue Aug 23 15:27:05 UTC 2022
On 8/23/22 01:07, IGotD- wrote:
> On Tuesday, 23 August 2022 at 01:19:35 UTC, Steven Schveighoffer wrote:
>>
>> Agreed that C/C++ initializing with garbage is the worst option.
>>
>> C# (as also mentioned) uses 0.
>>
>> I'm curious what all languages do that actually use an initial value?
>>
>> -Steve
>
> C++11 default value initialization exist. Meaning this
>
> ```c++
> double x{};
> ```
At that level, it's the same in D:
// Garbage value:
double x = void; // D
double x; // C++
// Zero value:
double x = 0; // D
double x{}; // C++
However, there is a difference with members:
struct S {
double x;
} // Add ; here for C++
S(); // S.x is double.nan in D
S{}; // S.x is 0 in C++
> find a language other than D that default initializes
> floats to NaN.
I failed with a quick search.
However, I still think initial value being nan is not an issue even if
it does not meet programmer expectations. For example, D could not leave
the value as garbage as C++ programmers comfortably expect so. And I am
pretty sure the default value cannot be changed for D at this time.
Ali
More information about the Digitalmars-d
mailing list