This section discusses situations that fall outside the usual model of round a mathematical result to fit into the destination.
Any arithmetic operation on a NaN produces
a NaN result. Special accommodation may
be made for aggregating functions
like min
or max
,
but they fall outside the scope of
basic arithmetic.
In signed-magnitude systems like IEEE 754, zero has an algebraic sign whose rules fall outside ordinary mathematics. As with the actual computation, we look to the most natural – or perhaps least surprising – answer.
When zero results from
mul
or div
, its sign
is just the exclusive-or of the operands' signs.
neg
flips zero's sign and abs
gives zero positive sign. copysign
does what it says. The first surprise is sqrt
,
which preserves the sign of a zero input.
The unobvious cases are add
and sub
.
What is the sign of the result of 5.0 - 5.0
?
There is no mathematical choice. The 754 rule is based on the
rounding mode.
Deliver +0
when rounding to nearest, toward 0, or
toward \( + \infty \), and deliver -0
when
rounding toward \( - \infty \).
The cases +0 + +0
and +0 - -0
deliver +0
with no sign ambiguity.
Similarly,
the cases -0 + -0
and -0 - +0
deliver -0
.
The 754 rule applies to the other four cases
+0 + -0
, +0 - +0
,
-0 + +0
, and -0 - -0
.
This operation produces a NaN. It's called Invalid in 754.
\( \lim_{x,y \rightarrow 0} x / y \) does not exist.
This operation produces a NaN. It's called Invalid in 754.
\( \lim_{x \rightarrow 0, y \rightarrow \infty} x \times y \) does not exist.
This operation produces \( \infty \) with the exclusive-or of the operands' signs, provided the number system supports an infinity symbol, as 754 does.
\( \lim_{y \rightarrow 0} x / y = \pm\infty \) for \( x \neq 0 \).
This operation produces \( 0 \) with the exclusive-or of the operands' signs.
\( \lim_{y \rightarrow \infty } x / y = 0 \) for \( x \) finite.
This operation produces \( \infty \) with the exclusive-or of the operands' signs.
\( \lim_{y \rightarrow \infty } x \times y = \pm \infty \) for \( x \neq 0 \).