Why can floating point store more values than integers?

978 views

In a 32-bit floating point, it was said that the highest possible value is 3.4028235 x 10^38. However, when we evaluate this, it will be equal to 340282346638528860000000000000000000000. This whole number would require more than 100 integer bits right? My question is: If that is the case, how come this number requiring more than 100 bits fitted in a 32-bit floating point?

In: 3

23 Answers

Anonymous 0 Comments

A 32-bit float can actually store fewer values than a 32-bit integer. The floating point values cover a much larger range but many of the possible values are exactly equal to other values. Most obviously, floating point has negative zero.

Anonymous 0 Comments

A 32-bit float can actually store fewer values than a 32-bit integer. The floating point values cover a much larger range but many of the possible values are exactly equal to other values. Most obviously, floating point has negative zero.

Anonymous 0 Comments

It can’t store more values, it’s just that the values it can store are distributed differently. Within 8,388,608 of 0, 32 bit floating point numbers are packed closer than 1 apart. More than 16,777,215 away from 0, they are more than 1 apart.

That ‘more than 1 apart’ is what allows them to store much bigger numbers than integers of the same size. The *difference* between the largest 32 bit floating point number and the second largest has 31 digits when written in decimal so they get *really* spread out.

If you include positive and negative infinity, positive and negative zero, and positive and negative “not a number” all as separate values, there are the same number of 32 bit floating point numbers as there are 32 bit integers.

Anonymous 0 Comments

It can’t store more values, it’s just that the values it can store are distributed differently. Within 8,388,608 of 0, 32 bit floating point numbers are packed closer than 1 apart. More than 16,777,215 away from 0, they are more than 1 apart.

That ‘more than 1 apart’ is what allows them to store much bigger numbers than integers of the same size. The *difference* between the largest 32 bit floating point number and the second largest has 31 digits when written in decimal so they get *really* spread out.

If you include positive and negative infinity, positive and negative zero, and positive and negative “not a number” all as separate values, there are the same number of 32 bit floating point numbers as there are 32 bit integers.

Anonymous 0 Comments

It can’t store more values, it’s just that the values it can store are distributed differently. Within 8,388,608 of 0, 32 bit floating point numbers are packed closer than 1 apart. More than 16,777,215 away from 0, they are more than 1 apart.

That ‘more than 1 apart’ is what allows them to store much bigger numbers than integers of the same size. The *difference* between the largest 32 bit floating point number and the second largest has 31 digits when written in decimal so they get *really* spread out.

If you include positive and negative infinity, positive and negative zero, and positive and negative “not a number” all as separate values, there are the same number of 32 bit floating point numbers as there are 32 bit integers.

Anonymous 0 Comments

As others point out – a 32 bit int can hold 32 bits worth of information. a 32 bit float…can still only hold 32 bits worth of information. Note, information is different from ‘maximum size of the number being stored’.

Floats themselves use a portion of the information (bits) to store the magnitude of the number, and the rest of the information to store the exponent (thinking in scientific notation). In floating point terms, you can’t differentiate between 340282346638528860000000000000000000000 and 340282346638528860000000000000500000000 or even
340282346638528864999000000000000000000
All of the precision after the zeroes start is uncertain. Just like how we can do most day to day math with pi=3.14 and get precise-enough answers, we get different results with more precise 3.1415926…but those extra digits of precision don’t have a significant impact on the result, just the precision of the result. The next biggest number in your example is an increment of 10000000000000000000000 (1E22). It can hold bigger numbers, but not ‘more’ numbers.

Anonymous 0 Comments

As others point out – a 32 bit int can hold 32 bits worth of information. a 32 bit float…can still only hold 32 bits worth of information. Note, information is different from ‘maximum size of the number being stored’.

Floats themselves use a portion of the information (bits) to store the magnitude of the number, and the rest of the information to store the exponent (thinking in scientific notation). In floating point terms, you can’t differentiate between 340282346638528860000000000000000000000 and 340282346638528860000000000000500000000 or even
340282346638528864999000000000000000000
All of the precision after the zeroes start is uncertain. Just like how we can do most day to day math with pi=3.14 and get precise-enough answers, we get different results with more precise 3.1415926…but those extra digits of precision don’t have a significant impact on the result, just the precision of the result. The next biggest number in your example is an increment of 10000000000000000000000 (1E22). It can hold bigger numbers, but not ‘more’ numbers.

Anonymous 0 Comments

As others point out – a 32 bit int can hold 32 bits worth of information. a 32 bit float…can still only hold 32 bits worth of information. Note, information is different from ‘maximum size of the number being stored’.

Floats themselves use a portion of the information (bits) to store the magnitude of the number, and the rest of the information to store the exponent (thinking in scientific notation). In floating point terms, you can’t differentiate between 340282346638528860000000000000000000000 and 340282346638528860000000000000500000000 or even
340282346638528864999000000000000000000
All of the precision after the zeroes start is uncertain. Just like how we can do most day to day math with pi=3.14 and get precise-enough answers, we get different results with more precise 3.1415926…but those extra digits of precision don’t have a significant impact on the result, just the precision of the result. The next biggest number in your example is an increment of 10000000000000000000000 (1E22). It can hold bigger numbers, but not ‘more’ numbers.

Anonymous 0 Comments

A given number of bits can represent the same number of numbers. The range these numbers can take can vary depending upon how you use those bits, but the total number of numbers you can represent is still 2^32. While floating point represents a larger range of number than integers of the same bits, the number of floating point numbers that can be represented are exactly the same (2^32).

You sacrifice precision of your numbers when you use some of the bits to indicate exponents. You can express every integer between the lower and upper bound (least and greatest representable number) of 32-bit integers. With floating point numbers you cannot represent every integer between the lower and upper bound of representation.

Anonymous 0 Comments

A given number of bits can represent the same number of numbers. The range these numbers can take can vary depending upon how you use those bits, but the total number of numbers you can represent is still 2^32. While floating point represents a larger range of number than integers of the same bits, the number of floating point numbers that can be represented are exactly the same (2^32).

You sacrifice precision of your numbers when you use some of the bits to indicate exponents. You can express every integer between the lower and upper bound (least and greatest representable number) of 32-bit integers. With floating point numbers you cannot represent every integer between the lower and upper bound of representation.