floating point double p0 = π.doubleValue(); // -> 3.141592653589793 (hex: 0x1.921fb54442d18p1) // p0 is smaller than π, so find next number representable as double double p1 = Math.nextUp(p0); // -> 3.1415926535897936 (hex: 0x1.921fb54442d19p1) Then is determined as . // ulp(π) is the difference between p1 and p0 BigDecimal ulp = new BigDecimal(p1).subtract(new BigDecimal(p0)); // -> 4.44089209850062616169452667236328125E-16 // (this is precisely 2**(-51)) // same result when using the standard library function double ulpMath = Math.ulp(p0); // -> 4.440892098500626E-16 (hex: 0x1.0p-51) Example 3 Another example, in Python, also typed at an interactive prompt, is: >>> x = 1.0 >>> p = 0 >>> while x != x + 1: ... x = x * 2 ... p = p + 1 ... >>> x 9007199254740992.0 >>> p 53 >>> x + 2 + 1 9007199254740996.0 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. Language support The Boost C++ libraries provides the functions boost::math::float_next, boost::math::float_prior, boost::math::nextafter and boost::math::float_advance to obtain nearby (and distant) floating-point values, and boost::math::float_distance(a, b) to calculate the floating-point distance between two doubles. The C language library provides functions to calculate the next floating-point number in some given direction: nextafterf and nexttowardf for float, nextafter and nexttoward for double, nextafterl and nexttowardl for long double, declared in <math.h>. It also provides the macros FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON, which represent the positive difference between 1.0 and the next greater representable number in the corresponding type (i.e. the ulp of one). The Java standard library provides the functions and . They were introduced with Java 1.5. The Swift standard library provides access to the next floating-point number in some given direction via the instance properties nextDown and nextUp. It also provides the instance property ulp and the type property ulpOfOne (which corresponds to C macros like FLT_EPSILON) for Swift's floating-point types. See also IEEE 754 ISO/IEC 10967, part 1 requires an ulp function Least significant bit (LSB) Machine epsilon References Bibliography Goldberg, David (1991–03). "Rounding Error" in "What Every Computer Scientist Should Know About Floating-Point Arithmetic". Computing Surveys, ACM, March 1991. Retrieved from http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html#689. Computer arithmetic Floating point