In computer science and numerical analysis, unit in the last place or unit of least precision (ulp) is the spacing between two consecutive floating-point numbers, i.e., the value the least significant digit (rightmost digit) represents if it is 1. It is used as a measure of accuracy in numeric calculations.
Definition The most common definition is: In radix b {\displaystyle b} with precision p {\displaystyle p} , if b e ≤ | x | < b e + 1 {\displaystyle b^{e}\leq |x|<b^{e+1}} , then ulp ( x ) = b max { e , e min } − p + 1 {\displaystyle \operatorname {ulp} (x)=b^{\max\{e,\,e_{\min }\}-p+1}} , where e min {\displaystyle e_{\min }} is the minimal exponent of the normal numbers. In particular, ulp ( x ) = b e − p + 1 {\displaystyle \operatorname {ulp} (x)=b^{e-p+1}} for normal numbers, and ulp ( x ) = b e min − p + 1 {\displaystyle \operatorname {ulp} (x)=b^{e_{\min }-p+1}} for subnormals. Another definition, suggested by John Harrison, is slightly different: ulp ( x ) {\displaystyle \operatorname {ulp} (x)} is the distance between the two closest straddling floating-point numbers a {\displaystyle a} and b {\displaystyle b} (i.e., satisfying a ≤ x ≤ b {\displaystyle a\leq x\leq b} and a ≠ b {\displaystyle a\neq b} ), assuming that the exponent range is not upper-bounded. These definitions differ only at signed powers of the radix.
Examples
Example 1 Let x {\displaystyle x} be a positive floating-point number and assume that the active rounding mode is round to nearest, ties to even, denoted RN {\displaystyle \operatorname {RN} } . If ulp ( x ) ≤ 1 {\displaystyle \operatorname {ulp} (x)\leq 1} , then RN ( x + 1 ) > x {\displaystyle \operatorname {RN} (x+1)>x} . Otherwise, RN ( x + 1 ) = x {\displaystyle \operatorname {RN} (x+1)=x} or RN ( x + 1 ) = x + ulp ( x ) {\displaystyle \operatorname {RN} (x+1)=x+\operatorname {ulp} (x)} , depending on the value of the least significant digit and the exponent of x {\displaystyle x} . This is demonstrated in the following Haskell code typed at an interactive prompt:
Here we start with 0 in single precision (binary32) and repeatedly add 1 until the operation does not change the value. Since the significand for a single-precision number contains 24 bits, the first integer that is not exactly representable is 224+1, and this value rounds to 224 in round to nearest, ties to even. Thus the result is equal to 224.
Example 2 The following example in Java approximates π as a floating-point value by finding the two double values bracketing π {\displaystyle \pi } : p 0 < π < p 1 {\displaystyle p_{0}<\pi <p_{1}} .
Then ulp ( π ) {\displaystyle \operatorname {ulp} (\pi )} is determined as ulp ( π ) = p 1 − p 0 {\displaystyle \operatorname {ulp} (\pi )=p_{1}-p_{0}} .
Example 3 Another example, in Python, also typed at an interactive prompt, is:
In this case, we start with x = 1 and repeatedly double it until x = x + 1. Similarly to Example 1, the result is 253 because the double-precision floating-point format uses a 53-bit significand.
… excerpt ends here. Continue reading the full article.
