Movement against float.init being nan

Bastiaan Veelo Bastiaan at Veelo.net
Thu Aug 25 18:05:36 UTC 2022


On Monday, 22 August 2022 at 22:11:23 UTC, jmh530 wrote:
> On Monday, 22 August 2022 at 20:29:57 UTC, Bastiaan Veelo wrote:
>> I had some fun with `isNaN` the other day. We used it to check 
>> for initialisation in an access function to cache an expensive 
>> computation. This worked brilliantly until we noticed a 
>> malfunction in the release version. It took a while until I 
>> realised that I had given the LDC `fastmath` option to the 
>> release build, which assumes NaN does not occur, which makes 
>> `isNaN` misbehave.
>>
>
> Is there a simple example of this behavior?

Yes:
```d
import std;
void main()
{
     assert(isNaN(double.nan));
}
```

Compile with LDC and options `--ffast-math -O`.

-- Bastiaan.


More information about the Digitalmars-d mailing list