Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of significant digits for a floating point type

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?

like image 634
mk_ Avatar asked Oct 10 '12 08:10

mk_


People also ask

What is significant in floating point?

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.

How many digits can float data type can hold?

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.

How many digits we can use after decimal point in float data type?

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.


1 Answers

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).

like image 102
CrazyCasta Avatar answered Oct 06 '22 18:10

CrazyCasta