Size of int and float

atul picture atul · Aug 16, 2011 · Viewed 41.7k times · Source

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?

Answer

Paul R picture Paul R · Aug 16, 2011

They are totally different - typically int is just a straightforward 2's complement signed integer, while float is a single precision floating point representation with 23 bits of mantissa, 8 bits exponent and 1 bit sign (see http://en.wikipedia.org/wiki/IEEE_754-2008).