TOPICS
Search

Floating-Point Arithmetic


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 R 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 (x,y,z)|->(x×y)+z); 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).

operationfunctiondomainpossible exceptions
expe^x[-infty,+infty]Overflow; Underflow
expm1e^x-1[-infty,+infty]Overflow; Underflow
exp22^x[-infty,+infty]Overflow; Underflow
exp2m12^x-1[-infty,+infty]Overflow; Underflow
exp1010^x[-infty,+infty]Overflow; Underflow
exp10m110^x-1[-infty,+infty]Overflow; Underflow
logln(x)[0,+infty]Divide By Zero (if x=0); Invalid Operation (if x<0)
log2log_2(x)[0,+infty]Divide By Zero (if x=0); Invalid Operation (if x<0)
log10log_(10)(x)=log(x)[0,+infty]Divide By Zero (if x=0); Invalid Operation (if x<0)
logp1ln(x+1)[-1,+infty]Divide By Zero (if x=-1); Invalid Operation (if x<-1); Underflow
log2p1log_2(x+1)[-1,+infty]Divide By Zero (if x=-1); Invalid Operation (if x<-1); Underflow
log10p1log_(10)(x+1)[-1,+infty]Divide By Zero (if x=-1); Invalid Operation (if x<-1); Underflow
hypot(x,y)sqrt(x^2+y^2)[-infty,+infty]^2Overflow; Underflow
rSqrt1/sqrt(x)[0,+infty]Invalid Operation (if x<0); Divide By Zero (if x=+/-0)
compound(x,n)(1+x)^n[-1,+infty]×ZInvalid Operation (if x<-1); Divide By Zero (if x=-1 and n<0); Overflow; Underflow
rootn(x,n)x^(1/n)[-infty,+infty]×ZInvalid Operation (if n=0 or x<0 and n even); Divide By Zero (if x=+/-0 and n<0); Overflow/Underflow (if n=-1)
pown(x,n)x^n[-infty,+infty]×ZSeveral cases
pow(x,y)x^y[-infty,+infty]^2Several cases
powr(x,y)x^y[0,+infty]×[-infty,+infty]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  direct sum ,  circleminus ,  tensor , 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 x=1.234567×10^5 and y=9.876543×10^(-3) is exactly

 x+y=(1.234567+0.00000009876543)×10^5=1.23456709876543×10^5.
(1)

On the other hand, in a framework with radix b=10, 7-digit precision, and rounding to nearest, the value returned by floating-point addition would be

 x direct sum y=1.234567×10^5=x.
(2)

Similarly, given x=1.234571467×10^5 and y=1.23457129×10^5, one has that

 x-y=(1.234571467-1.23457129)×10^5=0.000000177×10^5=0.0177.
(3)

Rounding both operands to the nearest 7-digit decimal value gives 1.234571×10^5, so

 x circleminus y=0.0,
(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.


See also

Arithmetic, Biased Exponent, Floating-Point Algebra, Floating-Point Exponent, Floating-Point Normal Number, Floating-Point Number, Floating-Point Preferred Exponent, Floating-Point Quantum, Floating-Point Representation, IEEE 754-2008, Interval Arithmetic, NaN, Quiet NaN, Signaling NaN, Significand, Subnormal Number

Portions of this entry contributed by Christopher Stover

Explore with Wolfram|Alpha

References

Goldberg, D. "What Every Computer Scientist Should Know About Floating-Point Arithmetic." ACM Comput. Surv. 23, 5-48, 1991. https://doi.org/10.1145/103162.103163.Hauser, J. R. "Handling Floating-Point Exceptions in Numeric Programs." ACM Trans. Program. Lang. Sys. 18, 139-174, 1996. https://doi.org/10.1145/227699.227701.IEEE Computer Society. "IEEE Standard for Floating-Point Arithmetic: IEEE Std 754-2008 (Revision of IEEE Std 754-1985)." 2008. https://doi.org/10.1109/IEEESTD.2008.4610935.IEEE Computer Society. "IEEE Standard for Floating-Point Arithmetic: IEEE Std 754-2019 (Revision of IEEE Std 754-2008)." 2019. https://doi.org/10.1109/IEEESTD.2019.8766229.Severance, C. (Ed.). "IEEE 754: An Interview with William Kahan." Computer, 114-115, 1998.Stevenson, D. "A Proposed Standard for Binary Floating-Point Arithmetic: Draft 8.0 of IEEE Task P754." IEEE Comput. 14, 51-62, 1981.

Referenced on Wolfram|Alpha

Floating-Point Arithmetic

Cite this as:

Weisstein, Eric W., with contributions by Christopher Stover. "Floating-Point Arithmetic." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/Floating-PointArithmetic.html

Subject classifications