Unit in the Last Place
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

 and numerical analysis
Numerical analysis
Numerical analysis is the study of algorithms that use numerical approximation for the problems of mathematical analysis ....

, unit in the last place or unit of least precision (ULP) is the spacing between floating-point numbers, i.e., the value the least significant bit
Least significant bit
In computing, the least significant bit is the bit position in a binary integer giving the units value, that is, determining whether the number is even or odd. The lsb is sometimes referred to as the right-most bit, due to the convention in positional notation of writing less significant digits...

 (lsb) represents if it is 1. It is used as a measure of precision
Accuracy and precision
In the fields of science, engineering, industry and statistics, the accuracy of a measurement system is the degree of closeness of measurements of a quantity to that quantity's actual value. The precision of a measurement system, also called reproducibility or repeatability, is the degree to which...

 in numeric calculations.

The IEEE 754 specification—followed by all modern floating-point hardware—requires that the result of an elementary arithmetic
Elementary arithmetic
Elementary arithmetic is the simplified portion of arithmetic which is considered necessary and appropriate during primary education. It includes the operations of addition, subtraction, multiplication, and division. It is taught in elementary school....

 operation (addition, subtraction, multiplication, division, and square root
Square root
In mathematics, a square root of a number x is a number r such that r2 = x, or, in other words, a number r whose square is x...

) be within 0.5 ULP of the mathematically exact result—that is, that it be the best possible result. Reputable numeric
Numerical analysis
Numerical analysis is the study of algorithms that use numerical approximation for the problems of mathematical analysis ....

 libraries compute the basic transcendental function
Transcendental function
A transcendental function is a function that does not satisfy a polynomial equation whose coefficients are themselves polynomials, in contrast to an algebraic function, which does satisfy such an equation...

s to between 0.5 and about 1 ULP, as it is computationally expensive to guarantee 0.5 ULP precision.

Example

If ULP(x) is less than or equal to 1, then x + 1 > x. Otherwise, x + 1 = x. This is demonstrated in the following Haskell
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...

 code typed at an interactive prompt:


> until (\x -> x x+1) (+1) 0 :: Float
1.6777216e7
> it-1
1.6777215e7
> it+1
1.6777216e7


Here we start with 0 in 32-bit single-precision and repeatedly add 1 until the operation is idempotent. The result is equal to 224 (in hex
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

, 4b800000) since the significand
Significand
The significand is part of a floating-point number, consisting of its significant digits. Depending on the interpretation of the exponent, the significand may represent an integer or a fraction.-Examples:...

 for a single-precision number in this example contains 24 bits.

Another example, in Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, also typed at an interactive prompt, is:


>>> x = 1.0
>>> while (x != x + 1.0):
... x = x * 2.0
...
>>> x
9007199254740992.0
>>> from math import log
>>> log (x) / log (2)
53.0


In this case, we start with x = 1 and repeatedly double it until x + 1 = x. The result is 253, because the double-precision floating-point used a 53-bit significand.
Language support
Since Java 1.5, the Java standard library has included and functions,
although they use a different definition of ulp. Specifically, it uses the next highest real number for positive numbers, or the next lowest for negative.
The C language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 library maths.h provides the function nextafter to calculate the next double.
The Boost C%2B%2B Libraries offer boost::math::float_distance(a, b) to calculate the floating point distance between two doubles.
See also
  • IEEE 754
  • Least significant bit
    Least significant bit
    In computing, the least significant bit is the bit position in a binary integer giving the units value, that is, determining whether the number is even or odd. The lsb is sometimes referred to as the right-most bit, due to the convention in positional notation of writing less significant digits...

  • Machine epsilon
    Machine epsilon
    Machine epsilon gives an upper bound on the relative error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the subject of computational science...

  • ISO/IEC 10967
    ISO/IEC 10967
    ISO/IEC 10967, Language independent arithmetic , is a series ofstandards on computer arithmetic. It is compatible with IEC 60559, and indeed much of thespecifications in parts 2 and 3 are for IEEE 754 special values...

    , part 1 requires an ulp function
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK