Floating-point arithmetic is arithmetic performed on floating-point representations by any number of automated devices.
Traditionally, this definition is phrased so as to apply only to arithmetic performed on floating-point representations of real numbers (i.e., to finite elements of the collection of floating-point numbers) though several additional types of floating-point data including signed infinities and NaNs are also commonly allowed as inputs for such functions.
Despite the succinctness of the definition, it is worth noting that the most widely-adopted standards in computing consider nearly the entirety of floating-point theory under
the heading "floating-point arithmetic." One reason for this breadth stems
from the fact that any floating-point
representation can account for but a finite subset
of the continuum of real numbers; this finiteness
presents a variety of unforeseen obstacles, chief among which is the fact that certain
properties of real arithmetic (e.g., associativity
of addition) sometimes fail to hold for floating-point
numbers (IEEE Computer Society 2008). As a result, any comprehensive treatment
of floating-point arithmetic and/or algebra
must address numerous caveats including representations of floating-point
numbers, rounding, etc. before ever discussing the
actual operations themselves.
The current IEEE standard for floating-point arithmetic is IEEE 754-2019 (IEEE Computer Society 2019), a technical revision of IEEE 754-2008. The discussion below follows the 2008 standard, referred to as IEEE 754, which substantially revised IEEE 754-1985. IEEE 754 addresses the following aspects of floating-point theory:
1. Floating-point representations and formats.
2. Attributes of floating-point representations, including rounding of floating-point numbers.
3. Arithmetic and algebraic operations on floating-point representations.
4. Infinity, non-numbers (NaNs), signs, and exceptions.
A number of the above topics are discussed across multiple sections of the standard's documentation (IEEE Computer Society 2008).
The "required" arithmetical operations defined by IEEE 754 on floating-point representations
are addition, subtraction,
multiplication, division,
square root, and fused multiply-add (a ternary operation defined by ); these are required in the sense
that adherence to the framework requires these operations
to be supported with correct rounding throughout. A
number of other "recommended" operations
are also provided within the framework, some of which are arithmetic
in nature; these are recommended in the sense that support for them is not strictly
required by the framework. Finally, note that the framework includes both a collection
of utility functions which may also be considered arithmetic, namely copy, negate, and abs,
as well as a number of closely-related functions defined
for vector-valued input (IEEE Computer Society 2008, pp. 46-47).
| operation | function | domain | possible exceptions |
| exp | Overflow; Underflow | ||
| expm1 | Overflow; Underflow | ||
| exp2 | Overflow; Underflow | ||
| exp2m1 | Overflow; Underflow | ||
| exp10 | Overflow; Underflow | ||
| exp10m1 | Overflow; Underflow | ||
| log | Divide By Zero (if | ||
| log2 | Divide By Zero (if | ||
| log10 | Divide By Zero (if | ||
| logp1 | Divide By Zero (if | ||
| log2p1 | Divide By Zero (if | ||
| log10p1 | Divide By Zero (if | ||
| Overflow; Underflow | |||
| rSqrt | Invalid Operation (if | ||
| Invalid Operation (if
| |||
| Invalid Operation (if | |||
| Several cases | |||
| Several cases | |||
| Several cases |
The above table summarizes the recommended arithmetic operations within IEEE 754. Note that the particulars of the exceptions labeled "Several cases" are addressed in detail in the IEEE 754 documentation (IEEE Computer Society 2008, pp. 43-45).
As noted above, even some of the basic required arithmetic operators behave unpredictably in light of floating-point
representations and rounding. This stems from the
fact that the "normal" arithmetic operations
are assumed within IEEE 754 to have infinite precision
while the values of floating-point addition, subtraction,
multiplication, and division,
written symbolically as ,
,
, and
, respectively, are computed by performing the "normal"
operations of
,
,
, and
, respectively, on floating-point
numbers written in terms of their exact values and rounding
the exact result to the destination format according to the selected rounding
direction. For decimal formats, the preferred
exponent separately selects a floating-point
representation of an exact result when several representations are possible.
As a result, loss of precision, overflow, and underflow
can all occur during the arithmetic and/or rounding
steps of the computation. For example, the result of adding
and
is exactly
|
(1)
|
On the other hand, in a framework with radix , 7-digit precision,
and rounding to nearest, the value returned by floating-point
addition would be
|
(2)
|
Similarly, given and
, one has that
|
(3)
|
Rounding both operands to the nearest 7-digit decimal value gives , so
|
(4)
|
thus losing the exact difference through anomalous cancellation. Subtracting identical rounded operands yields exact zero and need not raise an underflow exception; underflow concerns a tiny nonzero result relative to the available floating-point exponent range. Details and caveats of the other arithmetic functions mentioned throughout can be found in the documentation (IEEE Computer Society 2008, §5 and §9).
Some distinction is made between floating-point operations which are arithmetic in nature and those which are algebraic/trigonometric: Operations of the latter variety typically fall under the heading of floating-point algebra.