Game dev
Saved & recent

Floating-point precision

Related terms: float, double, rounding error, floating origin, epsilon

A float stores a number with a limited number of significant binary digits. Many decimal fractions cannot be represented exactly, so arithmetic rounds them. Numbers become more widely spaced as their magnitude grows.

Far from the world origin, small movements can round away and objects can jitter. Larger numeric types or shifting the world origin can help. Use a suitable tolerance when comparing approximate results.

Further reading
Python documentation: Floating-point arithmetic: representation error
0 +0.125 +0.25 +0.375 +0.5 +0.625 +0.75 0.125 start at 1,048,576 +0.08 exact offset 0 +0.25 +0.5 +0.75 0.25 start at 2,097,152 +0.08 exact offset exact target stored float32
Both lines use the same offset scale. In float32, adding 0.08 at 2²⁰ rounds to an offset of 0.125. At 2²¹ it rounds back to the start.

View in the full Game dev collection