Movement against float.init being nan

Nick Treleaven nick at geany.org
Sat Aug 20 12:02:17 UTC 2022


On Saturday, 20 August 2022 at 11:51:13 UTC, Adam D Ruppe wrote:
> On Saturday, 20 August 2022 at 10:26:08 UTC, Nick Treleaven 
> wrote:
>> On Saturday, 20 August 2022 at 03:12:43 UTC, Steven 
>> Schveighoffer wrote:
>>> You can't even `assert(x != double.init)`. You have to use an 
>>> esoteric function `isNaN` for that.
>>
>> Actually, you can use `is`:
>> ```d
>> static assert(float() is float.nan);
>> ```
>
> That works for float.init specifically, but if you've done some 
> operation on it and ended up with a nan, that will not 
> necessarily be true since nans come in several bit patterns.

Then compare it with real.nan - smaller types will be promoted to 
real:

```d
static assert(float() is real.nan);
static assert(double() is real.nan);
static assert(real() is real.nan);
```


More information about the Digitalmars-d mailing list