Precision in floating point refers to the number of leading significant digits.
For common float
, it can be considered to have at least 6 decimal digits of significance.
Recall that floating point numbers are distributed logarithmically. There are about as many different FP number from 0.1 to 0.2 as between 10 to 20 as between 0.000001 to 0.000002 as between 1,000,000 to 2,000,000.
Notice that the digits for the next FP number changes by a small amount in the right most digits.
printf("FLT_MIN %.*e\n", FLT_DECIMAL_DIG - 1, FLT_MIN);
printf("FLT_MIN+ %.*e\n", FLT_DECIMAL_DIG - 1, nextafterf(FLT_MIN, 1.0));
printf("one %.*e\n", FLT_DECIMAL_DIG - 1, 1.0);
printf("one+ %.*e\n", FLT_DECIMAL_DIG - 1, nextafterf(1.0, 2.0));
printf("FLT_MIN- %.*e\n", FLT_DECIMAL_DIG - 1, nextafterf(FLT_MAX, 1.0));
printf("FLT_MAX %.*e\n", FLT_DECIMAL_DIG - 1, FLT_MAX);
Output
FLT_MIN 1.17549435e-38
FLT_MIN+ 1.17549449e-38
one 1.00000000e+00
one+ 1.00000012e+00
FLT_MAX- 3.40282326e+38
FLT_MAX 3.40282347e+38
The difference between two successive FP number is often called the unit-(in-the)-last-place ULP. It is this difference, as compared to the number that is the "precision". This difference for binary32 is constant for every power of 2, then it doubles with increasing power-of-2.
Note the difference of consecutive float
numbers just above 1.0 is 2-23 or 1.0/8,388,608 or 0.000000119...
. This is the definition of FLT_EPSILON
. Some consider that the "precision". C specifies that the most this can be is 1E-5
or 1 part in 100,000.
C does not specify the float
behave exactly like the commonly employed binary32, so expect some variations.