min(NaN,5) = NaN (why no @fastmath?)

NaN propagating through operations is intended behavior, following IEEE 754

You’ll have to thank Intel for this, who, in their infinite wisdom, decided that this is how it should behave in x86… See also this:

Compares the low single-precision floating-point values in the first source operand and the second source operand and returns the minimum value to the low doubleword of the destination operand.

If the values being compared are both 0.0s (of either sign), the value in the second source operand is returned. If a value in the second operand is an SNaN, that SNaN is returned unchanged to the destination (that is, a QNaN version of the SNaN is not returned).

If only one value is a NaN (SNaN or QNaN) for this instruction, the second source operand, either a NaN or a valid floating-point value, is written to the result. If instead of this behavior, it is required that the NaN in either source operand be returned, the action of MINSD can be emulated using a sequence of instructions, such as, a comparison followed by AND, ANDN and OR.

The situation is of course the same for Float64 i.e. double precision. Fixing this in x86 is kind of impossible, practically speaking.

13 Likes