Movement against float.init being nan

Paul Backus snarwin at gmail.com
Sun Aug 21 13:47:43 UTC 2022


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);



More information about the Digitalmars-d mailing list