The description for type float
in C mentions that the number of significant digits is 6
. However,
float f = 12345.6;
and then printing it using printf() does not print 12345.6
, it prints 12345.599609
. So what does "6 significant digits" (or "15 in case of a double
") mean for a floating point type?
According to the IEEE standard, 32-bit floating point numbers are represented as follows: The most significant bit indicates sign of the number, where 0 indicates positive and 1 indicates negative. The 8-bit exponent shows the power of the number.
float has 7 decimal digits of precision. double is a 64-bit IEEE 754 double precision Floating Point Number – 1 bit for the sign, 11 bits for the exponent, and 52* bits for the value.
The float data type has only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point.
6 significant digits means that the maximum error is approximately +/- 0.0001%. The single float value actually has about 7.2 digits of precision (source). This means that the error is about +/- 12345.6/10^7 = 0.00123456. Which is on the order of your error (0.000391).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With