4 ms·
Years ago I created a solar system simulation for education called the Astronomicon. It was a fascinating education for me, not only about Astronomy and our so
by gilbetron 9y ago
Years ago I created a solar system simulation for education called the Astronomicon. It was a fascinating education for me, not only about Astronomy and our solar system, but about floating point precision and general numerical stability issues. The problem really showed up with Pluto (back then a planet ;) ). Using 32 bits, a floating point seemed fine, except when you started up the simulation and saw pluto jumping in discrete steps in it's orbit - you could actually see the bits, basically!
Graphics cards (they weren't called GPUs yet!) were just transitioning to 64 bit, so our high end cards could handle 64 bit precision, and everything was fine. But we were stuck with having to support some 32 bit cards. Then I figured if I scaled everything by ... 10,000 ... I think ... it would work out ok. The exact details escape me - maybe the mantissa wasn't enough for the needed precision, so multiplying by 10,000 before sending it to the GPU was enough. Or maybe the opposite. Regardless, it meant there was an annoying constant we had to deal with :)
Nothing like diving in and dealing with an issue like that to do some learnin'!
- madez 9y agoFixed precision floating point arithmetic is useful when you work over a large range of numbers and care about relative accuracy. That makes them also useful when the range is not known. However, the range is not irrelevant. Violating the allowed range can lead to bad accuracy, and shifting the numbers via a factor into the limitations can improve accuracy. From what you say, this happened in your case; the numbers got too small and you shifted them into the supported range, which is 2^(−126) to (1 − 2^(−24)) × 2^128 for IEEE 754-2008 32 bit numbers.
- taejo 9y agoHalf of all floating-point values are between -1 and 1. Half of the remaining values have magnitude between 1 and 2. And so on... If we represent positions in kilometers, and we're talking about a solar system with radius on the order of a billion kilometers in diameter, and it becomes clear that we're wasting almost all of those floating point bits!