Precision in C floats

后端 未结 4 1755
醉话见心
醉话见心 2020-12-06 06:12

Generally we say that a float has precision of 6 digits after the decimal point. But if we store a large number of the order of 10^30 we won\'t get 6 digits after the decima

4条回答
  •  佛祖请我去吃肉
    2020-12-06 06:58

    "6 digits after the decimal point" is nonesnse, and your example is a good demonstration of this.

    This is an exact specification of the float data type.

    The precision of the float is 24 bits. There are 23 bits denoting the fraction after the binary point, plus there's also an "implicit leading bit", according to the online source. This gives 24 significant bits in total.

    Hence in decimal digits this is approximately:

    24 * log(2) / log(10) = 7.22

提交回复
热议问题