Reputation: 19
I'm studying Matlab and computer arithmetic, but I'm having trouble grasping the concept of the Machine Epsilon. I would appreciate a simple explanation, as if I were a child. What does '2.2204e-16' mean, what are the issues when we add '1' and what is its purpose?
I've only thought that with a 64-bit machine epsilon, we know that a number is accurate up to the sixteenth digit, but I have many doubts.
Upvotes: 0
Views: 790
Reputation: 222660
Non-zero finite floating-point numbers are represented as ±f•be, where:
f is called the significand. p is the precision of the format. f is restricted to be in a certain interval. For the moment,1 we take 1 ≤ f < b. For example, with b = 2 and p = 53 (the precision for the format commonly used for double
), the number 1 is represented as:
That is “1.” followed by 52 “0” digits, so it is a 53-bit numeral in base 2.
The so-called machine epsilon is the smallest change we can make to get to the next representable number. That next number is:
So the difference is:
That is 2−52•20 = 2−52 ≈ 2.220446049•10−16.
This is the Unit of Least Precision (ULP) of 1.
Note that the ULP depends on the general size of the number, specifically on which exponent is used to represent it. The number 32,768 is represented with an exponent of 15:
So the next representable number of that is:
which means the difference is:
which is 2−52•215 ≈ 7.275957614•10−12.
So the ULP of 32,768 is about 7.275957614•10−12.
I've only thought that with a 64-bit machine epsilon, we know that a number is accurate up to the sixteenth digit, but I have many doubts.
The number of bits in a format can only tell you the precision of numbers in the format, not how accurate they are. When you convert a number to a floating-point format, it is rounded to the format. When you add, multiply, or perform other operations, the ordinary arithmetic result is rounded to the format. Over the course of various operations, these rounding errors may compound or cancel, so a final result may be very inaccurate or may be accurate. Determining which and by how much can be difficult. There are some sequences of operations that almost always produce inaccurate results no matter how precise a floating-point format is. Precision does not tell you about accuracy.
1 Sometimes, f is scaled to the interval [b p−1, b p[, and the exponent is adjusted accordingly. This makes f always an integer, so it is useful for using number theory in proofs about floating-point. Sometimes, it is scaled to [1/b, 1[. The C standard uses this. In all of those, the first digit of f must be non-zero. Sometimes, the first digit is allowed to be zero, which allows representing zero and subnormal numbers.
Upvotes: 0
Reputation: 153456
What does '2.2204e-16' mean, what are the issues when we add '1' and what is its purpose?
Using typical 64-bit floating point, epsilon is about 0.00000000000000022204 ('2.2204e-16' or 2.2204*10-16) or exactly 2-52.
Epsilon: the difference between 1 and the least normalized value greater than 1 that is representable in the given floating type.
...
Between [0.5 and 1.0], 64-bit floating point steps are each 2-53.
Between [1.0 and 2.0], 64-bit floating point steps are each 2-52. Epsilon
Between [2.0 and 4.0], 64-bit floating point steps are each 2-51.
Between [4.0 and 8.0], 64-bit floating point steps are each 2-50.
...
we know that a number is accurate up to the sixteenth digit, but I have many doubts.
Typical floating point, if written in base 2: ±b.bbbbbbbb... * 2exponent is precise to 53 binary digits.
That is about 15.95 or log10(253) decimal digits ±d.ddddddd... * 10exponent.
Upvotes: 1