# assiging int to float

Angela lewis

Ranch Hand

Posts: 100

posted 12 years ago

i'm not an expert, but i'll try to help.

as i understand it, the specification for floats basically reserves part of the 32 bits for the mantissa (all the numbers regardless of where the decimal point is), and part for the exponent. it's sort of like scientific notation. in other words, the values are stored something like

123456 04

would be 1234.56

123456 06

would be 123456.0

123456 18

would be 123456000000000000.0

as the number get very large, like my last example, there are actually larger and larger 'gaps' between values that can be stored. for all practiacl purposes, there is no difference between 123456000000000000.0 and 123456000000000001.0.

so, yes, there are fewer bits for the mantissa, but that's a trade off we make for being able to store floats.

does that help?

as i understand it, the specification for floats basically reserves part of the 32 bits for the mantissa (all the numbers regardless of where the decimal point is), and part for the exponent. it's sort of like scientific notation. in other words, the values are stored something like

123456 04

would be 1234.56

123456 06

would be 123456.0

123456 18

would be 123456000000000000.0

as the number get very large, like my last example, there are actually larger and larger 'gaps' between values that can be stored. for all practiacl purposes, there is no difference between 123456000000000000.0 and 123456000000000001.0.

so, yes, there are fewer bits for the mantissa, but that's a trade off we make for being able to store floats.

does that help?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors