**New course!**Every coder should learn

**Generative AI!**

+ 1

# Float limitations

What limitations do floats have?

2 Answers

+ 1

In contrast with an integer of the same number of bits, a float will have fewer bits of precision because some of the bits are reserved to store the exponent. Out of 32 bits, a signed int reserves the high bit for the sign and has has 31 bits of precision. A 32-bit float has a sign bit and an 8-bit exponent, leaving only 23 bits to store its actual value. Using a neat trick they manage to actually have 24 bits of precision. They presume the highest bit is 1 and thereby avoid actually storing it. So a float loses 7 bits of precision compared to an int. What it gains is a much wider numeric range due to the exponent that shifts ("floats") the decimal point to the left or right.
In terms of significant digits, a 32-bit signed integer has 10, whereas a float has only 6 to 7. It varies due to the conversion from binary fractions.
Because of that conversion, the lowest bit in a float value sometimes gives slightly-off decimal results. It is known as epsilon, which represents the small amount of +/- error.

0

Computers can't store floats accurately which leads to bugs 🙂