Comment by ekelsen

20 days ago

I think it commutes even when one or both inputs are NaN? The output is always NaN.

NaNs are distinguishable. /Which/ NaN you get doesn't commute.

  • I guess at the bit level, but not at the level of computation? Anything that relies on bit patterns of nans behaving in a certain way (like how they propagate) is in dangerous territory.

    • > Anything that relies on bit patterns of nans behaving in a certain way (like how they propagate) is in dangerous territory.

      Why? This is well specified by IEEE 754. Many runtimes (e.g. for Javascript) use NaN boxing. Treating floats as a semi-arbitrary selection of rational numbers plus a handful of special values is /more/ correct than treating them as real numbers, but treating them as actually specified does give more flexibility and power.

      9 replies →

Unless you compile with fast-math ofc, because then the compiler will assume that NaN never occurs in the program.