TOPICS
Search

Floating-Point Arithmetic


Simply stated, 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.

As of 2014, the most commonly implemented standard for floating point arithmetic is the IEEE Standard 754-2008 for Floating-Point Arithmetic (written shorthand as IEEE 754-2008 and as IEEE 754 henceforth). This framework is a massive overhaul of its predecessor - IEEE 754-1985 - and includes a built-in collection of guidelines specifying nearly every conceivable aspect of floating-point theory. In particular, IEEE 754 addresses the following aspects of floating-point theory in considerable detail:

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
loglog_e(x)=ln(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)
logp1log_e(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)
rootn(x,n)x^(1/n)[-infty,+infty]×ZInvalid Operation (if n=0 or x<0 and n even); 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 a common exponent and rounding the result to a fixed number of significant digits (by way of the so-called preferred exponent) afterward. 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.0000009876543)×10^5=1.23456709876543×10^5.
(1)

On the other hand, in a framework with radix b=10 and 7-digit precision, 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.234571419)×10^5=0.000000048×10^5=0.0048
(3)

using the 7-digit precision assumed above. However, one has that

 x circleminus y=0.0,
(4)

thus yielding a complete lack of precision. Note that in extreme cases like this, systems implementing IEEE 754 won't actually yield +/-0 as a result: In particular, such a scenario will trigger an underflow warning. 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

This entry contributed by Christopher Stover

Explore with Wolfram|Alpha

WolframAlpha

More things to try:

References

Goldberg, D. "What Every Computer Scientist Should Know About Floating-Point Arithmetic." ACM Comput. Surv. 23, 5-48, March 1991. http://docs.sun.com/source/806-3568/ncg_goldberg.html.Hauser, J. R. "Handling Floating-Point Exceptions in Numeric Programs." ACM Trans. Program. Lang. Sys. 18, 139-174, 1996. http://www.jhauser.us/publications/HandlingFloatingPointExceptions.html.IEEE Computer Society. "IEEE Standard for Floating-Point Arithmetic: IEEE Std 754-2008 (Revision of IEEE Std 754-1985)." 2008. http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=4610935.Severance, C. (Ed.). "IEEE 754: An Interview with William Kahan." Computer, 114-115, Mar. 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:

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

Subject classifications