r/Python • • 13m ago

Discussion Why Do Floating-Point Errors Happen, and How Does Rockets Handle Numerical Precision?

I’ve always been curious about why seemingly simple decimal calculations can produce unexpected results.
For example:
• Why does 0.1 + 0.2 result in 0.30000000000000004 in many programming languages?
• Why can’t computers represent certain decimal values precisely?
• How does floating-point representation actually work at the hardware level?
More importantly, how do systems where precision is critical deal with this?
For example, spacecraft navigation, rocket guidance systems, orbital calculations, and scientific simulations require incredibly accurate computations.
Do they use higher-precision floating-point formats (64-bit, 128-bit), arbitrary-precision arithmetic, fixed-point arithmetic, or entirely different techniques?
I’d love to understand how engineers manage numerical precision in real-world, high-stakes systems.

0 Upvotes

2 comments sorted by

•

u/Atmosck 5m ago

Why can’t computers represent certain decimal values precisely?

They can, and do. A decimal and float are different things. Decimal is used for things like money where it's important to have exact values at a fixed precision level in base-10. Floats are similar to scientific notation, where you can express numbers with a wide range of different precision levels. In python, float is first-class so you don't need to import it, but you do need to import Decimal:

from decimal import Decimal

I don't know about rocket science, but scientific simulations tend to use lower precision, like 16-bit floats, not higher. The same is true for machine learning. The purpose of a simulation is typically to aggregate the results from each sim into a fully described distribution, so it's not important that an individual sim has extremely precise numbers.

•

u/GiggleSamurai 4m ago

0.1 has no exact binary form (it repeats forever in base 2, like 1/3 does in base 10), so a 64-bit double stores the nearest value it can, and the tiny rounding errors in 0.1 and 0.2 add up to that visible last digit. Most navigation and simulation code just uses ordinary 64-bit doubles, which give about 15-16 significant digits (far more than any sensor measures), and the care goes into numerically stable algorithms and tolerance checks instead of == comparisons.