Movement against float.init being nan
Dark Hole
dark.hole1 at yandex.ru
Sun Aug 21 14:09:23 UTC 2022
On Sunday, 21 August 2022 at 13:47:43 UTC, Paul Backus wrote:
> On Sunday, 21 August 2022 at 11:13:02 UTC, Dark Hole wrote:
>> Imagine, we have nullable int (int?) in language.
>>
>> ```d
>> int? x => null
>> x * null => null
>> x / null => null
>> x + null => null
>> x - null => null
>> -cast(int?)null => null
>> ```
>>
>> Seems like perfect solution (except performance costs)
>
> We have this in the standard library already:
>
> import std.checkedint;
>
> Checked!(int, WithNaN) n;
>
> assert(n.isNaN);
> assert((123 * n).isNaN);
> assert((123 / n).isNaN);
> assert((123 + n).isNaN);
> assert((123 - n).isNaN);
> assert((-n).isNaN);
My point is making this by default for all primitive types. This
will be consistent and simple:
```d
bool x; // Error, use bool? or init it something meaningful
struct Foo { bool x; } // Error too
```
So we have no problem "programmers make meaningless 0" and have
no problem to determine init for most of types.
More information about the Digitalmars-d
mailing list