Ranges of floating point datatype in C?

后端 未结 6 1692
死守一世寂寞
死守一世寂寞 2020-11-30 03:49

I am reading a C book, talking about ranges of floating point, the author gave the table:

Type     Smallest Positive Value  Largest value      Precision
====         


        
6条回答
  •  星月不相逢
    2020-11-30 04:28

    A 32 bit floating point number has 23 + 1 bits of mantissa and an 8 bit exponent (-126 to 127 is used though) so the largest number you can represent is:

    (1 + 1 / 2 + ... 1 / (2 ^ 23)) * (2 ^ 127) = 
    (2 ^ 23 + 2 ^ 23 + .... 1) * (2 ^ (127 - 23)) = 
    (2 ^ 24 - 1) * (2 ^ 104) ~= 3.4e38
    

提交回复
热议问题