Movement against float.init being nan

max haughton maxhaton at gmail.com
Thu Aug 25 18:11:11 UTC 2022


On Thursday, 25 August 2022 at 18:05:36 UTC, Bastiaan Veelo wrote:
> 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.

One of the nice things about UDAs and so on is that you can use 
them to opt into specific optimizations LLVM can do without 
opting into the blatantly dangerous ones.

http://johanengelen.github.io/ldc/2016/10/11/Math-performance-LDC.html


More information about the Digitalmars-d mailing list