Size of int and float

后端 未结 6 879
夕颜
夕颜 2021-02-01 07:17

I have a question about the ranges of ints and floats:

If they both have the same size of 4 bytes, why do they have different ranges?

6条回答
  •  情书的邮戳
    2021-02-01 07:37

    An integer is just a number... It's range depends on the number of bits (different for a signed or unsigned integer).

    A floating point number is a whole different thing. It's just a convention about representing a floating point number in binary...

    It's coded with a sign bit, an exponent field, and a mantissa.

    Read the following article:

    http://www.eosgarden.com/en/articles/float/

    It will make you understand what are floating point values, from a binary perspective. The you'll understand the range thing...

提交回复
热议问题