Why adding one can change nothing

A floating-point number stores a value in a form similar to scientific notation: a set of significant digits multiplied by a power of two. That lets a computer represent values across an enormous range, but the number of significant binary digits is limited. As the power of two grows, the gap between representable values grows too.

Imagine marks on a ruler that are close together near zero and farther apart farther along. If a stored number sits at a mark where neighboring marks are more than one unit apart, adding 1 may land between marks. The computer rounds the result to the nearest value it can represent—which can be the original number.

The threshold depends on the format

In the common 32-bit floating-point format, integers are represented exactly only up to 2²⁴, or 16,777,216. At that point, the next representable number is 2²⁴ + 2, so adding 1 to 2²⁴ rounds back to 2²⁴. The widely used 64-bit format has more precision: its corresponding threshold is 2⁵³, or 9,007,199,254,740,992.

These are not limits on how large a number can be. A floating-point format can represent vastly larger values; it simply cannot distinguish every neighboring integer at those magnitudes. The spacing expands as values grow.

Why programs have to account for it

This can surprise code that uses a floating-point value as an exact counter or identifier. A loop that repeatedly adds 1 may eventually stop changing its variable, and two different large integers may be stored as the same floating-point value. For exact whole-number arithmetic, programs use integer types when their range permits, or other representations designed to preserve exact values.

The practical lesson is that a number’s size and its precision are different things: a computer may store a huge value while losing the ability to tell it apart from its nearest neighbors.