Movement against float.init being nan

Paul Backus snarwin at gmail.com
Sat Aug 20 18:47:29 UTC 2022


On Saturday, 20 August 2022 at 18:05:59 UTC, Dom Disc wrote:
> On Saturday, 20 August 2022 at 01:01:07 UTC, Walter Bright 
> wrote:
>> If there was a NaN value for int, I would have used it as the 
>> default. int.min is not really a NaN.
>
> But it should be!
> int.min is a notorious bogus value. You can't even use abs() on 
> it: it will either give you a different type or return garbage. 
> There is not even a working literal for it (at least for 
> long.min). So it should never have been a valid value from 
> beginning.
> The first thing I include in every of my programs is a module 
> that define exactly that: an alias to byte/short/int/long that 
> takes T.min as invalid value (and uses it as default value) and 
> gives T.min+1 as its real min value.

By the way, you don't have to write this yourself; you can use 
Checked!(int, WithNaN) [1] from std.checkedint.

[1] https://phobos.dpldocs.info/std.checkedint.WithNaN.html


More information about the Digitalmars-d mailing list