Machine Epsilon - How To Determine Machine Epsilon

How To Determine Machine Epsilon

Where standard libraries do not provide precomputed values (as float.h does with FLT_EPSILON, DBL_EPSILON and LDBL_EPSILON for C and C++), the best way to determine machine epsilon is to refer to the table, above, and use the appropriate pow formula. Computing machine epsilon is often given as a textbook exercise. The following examples compute machine epsilon in the sense of the spacing of the floating point numbers at 1 rather than in the sense of the unit roundoff.

Note that results depend on the particular floating-point format used, such as float, double, long double, or similar as supported by the programming language, the compiler, and the runtime library for the actual platform.

Some formats supported by the processor might not be supported by the chosen compiler and operating system. Other formats might be emulated by the runtime library, including arbitrary-precision arithmetic available in some languages and libraries.

In a strict sense the term machine epsilon means the 1+eps accuracy directly supported by the processor (or coprocessor), not some 1+eps accuracy supported by a specific compiler for a specific operating system, unless it's known to use the best format.

A trivial example is the machine epsilon for integer arithmetic on processors without floating point formats; it is 1, because 1+1=2 is the smallest integer greater than 1.

IEEE 754 floating-point formats monotonically increase over positive values and monotonically decrease over negative values. They also have the property that where f(x) is the reinterpretation of x from an unsigned or twos-complement integer format to a floating-point format of the same width, and 0 < |f(x)| < ∞, |f(x+1) − f(x)| ≥ |f(x) − f(x−1)|. In languages that allow type punning and always use IEEE 754-1985, we can exploit this to compute a machine epsilon in constant time. For example, in C:

typedef union { long long i64; double d64; } dbl_64; double machine_eps (double value) { dbl_64 s; s.d64 = value; s.i64++; return s.d64 - value; }

This will give a result of the same sign as value. If a positive result is always desired, the return statement of machine_eps can be replaced with:

return (s.i64 < 0 ? value - s.d64 : s.d64 - value);

64-bit doubles give 2.220446e-16, which is 2−52 as expected.

Read more about this topic:  Machine Epsilon

Famous quotes containing the words determine and/or machine:

    Many readers judge of the power of a book by the shock it gives their feelings—as some savage tribes determine the power of muskets by their recoil; that being considered best which fairly prostrates the purchaser.
    Henry Wadsworth Longfellow (1807–1882)

    The machine unmakes the man. Now that the machine is perfect, the engineer is nobody. Every new step in improving the engine restricts one more act of the engineer,—unteaches him.
    Ralph Waldo Emerson (1803–1882)