Movement against float.init being nan
Paul Backus
snarwin at gmail.com
Thu Aug 25 20:37:13 UTC 2022
On Thursday, 25 August 2022 at 19:21:08 UTC, Ali Çehreli wrote:
> I found documentation on --fast-math here:
>
> https://clang.llvm.org/docs/UsersManual.html
>
> It includes "compiler make[s] [...] assumptions [...] Operands
> to floating-point operations are not equal to NaN and Inf"
>
> This is contrary to Walter's understanding, which I understand
> as "operations on NaN stay NaN". LLVM (at least Clang) seems to
> have a different take on NaN.
It is not just "contrary to Walter's understanding", it is
contrary to the IEEE 754 standard. Here is an article that goes
into more detail about it:
https://simonbyrne.github.io/notes/fastmath/
> LLVM must be thinking x != x is not a valid operation on NaN.
> Could we use a bit pattern check instead? Or write it as an asm
> block?
LLVM with fast-math assumes that all floating-point operands are
finite, which means that it can optimize `x != x` to `false` at
compile time. A sufficiently smart optimizer could in principle
perform the same optimization on a bit pattern check, if it
recognized the bit pattern for NaN.
More information about the Digitalmars-d
mailing list