Important : @harold's answer is almost exactly right, but it has a subtle wrong aspect that can drive you crazy for the very important edge case later - NaN treatment comes back from most languages ββ(e.g. C ++).
As @harold correctly says, the result of an unordered comparison is stored in the parity flag.
However, an unordered comparison is true if any operand is NaN , as described in this column . This means that NaN
will be less than and greater than absolutely every number, including NaN
.
So, if you want your language to comply with C ++ behavior, where any comparison with NaN returns false, you want:
For <=
:
ucomisd xmm0, xmm1 jbe else_label
For <
:
ucomisd xmm0, xmm1 jb else_label
Confirmed in the following gcc parsing, where I return a >= b
:
144e: 66 0f 2e c8 ucomisd %xmm0,%xmm1 1452: 0f 93 c0 setae %al
Here he uses setae
, which is case-equivalent, equivalent to jae
. Then it immediately returns without checking the parity flag.
For what its ja
, not jg
, @harold answer is still a clear and correct explanation.
And, of course, you donβt need to use ordered comparison, you can use unordered comparison, as shown in the previous answer, if you want absolutely every number to be less, greater and equal to NaN
in your program / language (where even NaN < NaN
truly!). And of course, as you can see, this can be a little slower, as this requires additional checks.