词条 | Unit in the last place |
释义 |
In computer science and numerical 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 digit represents if it is 1. It is used as a measure of accuracy in numeric calculations.[1] DefinitionOne definition is: In radix b with precision p, if be ≤ |x| < be+1, then ULP(x) = bmax(e,emin)−p+1.[2] Another definition, suggested by John Harrison, is slightly different: ULP(x) is the distance between the two closest straddling floating-point numbers a and b (i.e., those with a ≤ x ≤ b and a ≠ b), assuming that the exponent range is not upper-bounded.[3][4] These definitions differ only at signed powers of the radix.[2] The IEEE 754 specification—followed by all modern floating-point hardware—requires that the result of an elementary arithmetic operation (addition, subtraction, multiplication, division, and square root since 1985, and FMA since 2008) be correctly rounded, which implies that in rounding to nearest, the rounded result is within 0.5 ULP of the mathematically exact result, using John Harrison's definition; conversely, this property implies that the distance between the rounded result and the mathematically exact result is minimized (but for the halfway cases, it is satisfied by two consecutive floating-point numbers). Reputable numeric libraries compute the basic transcendental functions to between 0.5 and about 1 ULP. Only a few libraries compute them within 0.5 ULP, this problem being complex due to the Table-maker's dilemma.[5] ExamplesExample 1Let x be a positive floating-point number and assume that the active rounding attribute is round to nearest, ties to even, denoted RN. If ULP(x) is less than or equal to 1, then {{mono|1=RN(x + 1) > x}}. Otherwise, {{mono|1=RN(x + 1) = x}} or {{mono|1=RN(x + 1) = x + ULP(x)}}, depending on the value of the least significant digit and the exponent of x. This is demonstrated in the following Haskell code typed at an interactive prompt:{{fact|date=March 2015}} Here we start with 0 in single precision 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 2The following example in Java approximates {{pi}} as a floating point value by finding the two double values bracketing {{pi}}: {{math|p0 < π < p1}} Then {{math|ULP(π)}} is determined as {{math|ULP(π) {{=}} p1 - p0}} Example 3Another example, in Python, also typed at an interactive prompt, is:{{fact|date=March 2015}} In this case, we start with {{mono|1=x = 1}} and repeatedly double it until {{mono|1=x = x + 1}}. Similarly to Example 1, the result is 253 because the double-precision floating-point format uses a 53-bit significand. Language supportSince Java 1.5, the Java standard library has included {{Javadoc:SE|java/lang|Math|ulp(double)}} and {{Javadoc:SE|java/lang|Math|ulp(float)}} functions. The C language library provides functions to calculate the next floating-point number in some given direction: The Boost C++ Libraries offer boost::math::float_next, boost::math::float_prior, boost::math::nextafter and boost::math::float_advance functions to obtain nearby (and distant) floating-point values,[7] and boost::math::float_distance(a, b) to calculate the floating-point distance between two doubles.[8] See also
References1. ^David Goldberg: What Every Computer Scientist Should Know About Floating-Point Arithmetic, section 1.2 Relative Error and Ulps, ACM Computing Surveys, Vol 23, No 1, pp.8, March 1991. 2. ^1 {{cite book |author-last1=Muller |author-first1=Jean-Michel |author-last2=Brunie |author-first2=Nicolas |author-last3=de Dinechin |author-first3=Florent |author-last4=Jeannerod |author-first4=Claude-Pierre |author-first5=Mioara |author-last5=Joldes |author-last6=Lefèvre |author-first6=Vincent |author-last7=Melquiond |author-first7=Guillaume |author-last8=Revol |author-first8=Nathalie |author-last9=Torres |author-first9=Serge |title=Handbook of Floating-Point Arithmetic |date=2018 |orig-year=2010 |publisher=Birkhäuser |edition=2 |isbn=978-3-319-76525-9 |doi=10.1007/978-3-319-76526-6}} 3. ^{{cite web|last=Harrison|first=John|title=A Machine-Checked Theory of Floating Point Arithmetic|url=http://www.cl.cam.ac.uk/~jrh13/papers/fparith.html|accessdate=2013-07-17}} 4. ^Muller, Jean-Michel (2005-11). "On the definition of ulp(x)". INRIA Technical Report 5504. ACM Transactions on Mathematical Software, Vol. V, No. N, November 2005. Retrieved in 2012-03 from http://ljk.imag.fr/membres/Carine.Lucas/TPScilab/JMMuller/ulp-toms.pdf. 5. ^{{cite web |last=Kahan |first=William |title=A Logarithm Too Clever by Half |url=http://www.cs.berkeley.edu/~wkahan/LOG10HAF.TXT |accessdate=2008-11-14}} 6. ^{{cite book | url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf | title=ISO/IEC 9899:1999 specification | at=p. 237, §7.12.11.3 The nextafter functions and §7.12.11.4 The nexttoward functions}} 7. ^{{cite book | url=http://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/next_float/float_advance.html | title=Boost float_advance}} 8. ^{{cite book | url=http://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/next_float/float_distance.html | title=Boost float_distance}} Bibliography
2 : Floating point|Computer arithmetic |
随便看 |
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。