Let Nε(u) = {x| |x - u|≤ ε 2e-q},
where q is the excess
and e = E + q is the sum of exponent and excess
of the floating point representation of u. Then:
FCMPE:
s($X) ←
- 1
if f($Y) < Nε(f($Z))
and Nε(f($Y)) < f($Z)
0
if f($Y) ∈ Nε(f($Z))
or f($Z) ∈ Nε(f ($Y))
+1
if f($Y) > Nε(f($Z))
and Nε(f($Y)) > f($Z)
FEQLE:
s($X) ←
1
if f($Y) ∈ Nε(f($Z))
and f($Z) ∈ Nε(f ($Y))
0
otherwise
The value of ε is taken from the special register rE.
FUN:
s($X) ←
1
if either $Y or $Z is not a Number (NaN),
0
otherwise
FUNE:
s($X) ←
1
if either $Y, $Z or rE is not a Number (NaN),
0
otherwise
Description:
Besides doing arithmetic, we need to compare floating point numbers with each other, taking proper
account of NaNs and the fact that -0.0 should be considered equal to +0.0. The following instructions are
analogous to the comparison operators CMP and CMPU that we have used for integers.
FCMP:
"floating compare".
Register $X is set to -1 if $Y < $Z according to the conventions of floating point arithmetic, or to 1 if
$Y > $Z according to those conventions. Otherwise it is set to 0. An invalid exception occurs if either $Y
or $Z is a NaN; in such cases the result is zero.
FEQL:
"floating equal to".
Register $X is set to 1 if $Y = $Z according to the conventions of floating point arithmetic. Otherwise it is
set to 0. The result is zero if either $Y or $Z is a NaN, even if a NaN is being compared with itself. However,
no invalid exception occurs, not even when $Y or $Z is a signaling NaN. (Perhaps MMIX differs slightly
from the IEEE standard in this regard, but programmers sometimes need to look at signaling NaNs without
encountering side effects. Programmers who insist on raising an invalid exception whenever a signaling NaN
is compared for floating equality should issue the instructions FSUB $X,$Y,$Y; FSUB $X,$Z,$Z just before
saying FEQL $X,$Y,$Z.)
Suppose w, x, y, and z are unsigned 64-bit integers with w < x < 2
≤ y < z. Thus, the leftmost bits of
w and x are 0, while the leftmost bits of y and z are 1. Then we have w < x < y < z when these numbers
are considered as unsigned integers, but y < z < w < x when they are considered as signed integers, because
y and z are negative. Furthermore, we have z < y $le; w < x when these same 64-bit quantities are considered
to be floating point numbers, assuming that no NaNs are present, because the leftmost bit of a floating point
number represents its sign and the remaining bits represent its magnitude. The case y = w occurs in floating
point comparison if and only if y is the representation of -0.0 and w is the representation of +0.0.
FUN:
"floating unordered".
Register $X is set to 1 if $Y and $Z are unordered according to the conventions of floating point arithmetic
(namely, if either one is a NaN); otherwise register $X is set to 0. No invalid exception occurs, not even when
$Y or $Z is a signaling NaN.
The IEEE standard discusses 26 different possible relations on floating point numbers; MMIX implements
14 of them with single instructions, followed by a branch (or by a ZS to make a "pure" 0 or 1 result); all 26
can be evaluated with a sequence of at most four MMIX commands and a subsequent branch. The hardest
case to handle is "?>=" (unordered or greater or equal, to be computed without exceptions), for which the
following sequence makes $X ≥ 0 if and only if $Y ?>= $Z:
FUN $255,$Y,$Z
BP $255,1F % skip ahead if unordered
FCMP $X,$Y,$Z % $X=[$Y>$Z]-[$Y<$Z]; no exceptions will arise
1H CSNZ $X,$255,1 % $X=1 if unordered
FCMPE:
"floating compare (with respect to epsilon)".
Register $X is set to -1 if $Y ≺ $Z (rE) according to the conventions of Seminumerical Algorithms as stated
above; it is set to 1 if $Y ≻ $Z (rE) according to those conventions; otherwise it is set to 0. Here rE is
a floating point number in the special epsilon register , which is used only by the floating point comparison
operations FCMPE, FEQLE, and FUNE. An invalid exception occurs, and the result is zero, if any of $Y, $Z, or
rE are NaN, or if rE is negative. If no such exception occurs, exactly one of the three conditions $Y ≺ $Z,
$Y ∼ $Z, $Y ≻ $Z holds with respect to rE.
FEQLE:
"floating equivalent (with respect to epsilon)".
Register $X is set to 1 if $Y ≈ $Z (rE) according to the conventions of Seminumerical Algorithms as stated
above; otherwise it is set to 0. An invalid exception occurs, and the result is zero, if any of $Y, $Z, or rE are
NaN, or if rE is negative. Notice that the relation $Y ≈ $Z computed by FEQLE is stronger than the relation
$Y ∼ $Z computed by FCMPE.
FUNE:
"floating unordered (with respect to epsilon)".
Register $X is set to 1 if $Y, $Z, or rE are exceptional as discussed for FCMPE and FEQLE; otherwise it is set
to 0. No exceptions occur, even if $Y, $Z, or rE is a signaling NaN.
Please help to keep this site up to date!
If you want to point out important material or projects
that are not listed here, if you find errors or want to suggest improvements,
please send email to