jlb wrote: |
---|
How do you "know" that the value should be 4499.1...? |
Because I was told double precision has 15-16 significant digits. Or is that wrong now?
Have you manually calculated the value? |
I gave the exact result in my earlier post.
How are you trying to round away those "insignificant" values? |
Round down from digits <5, round up from digits >=5.
@mbozzi
I need to understand exactly how this floating point arithmetic works.
My program deals with particles and 'hard walls'. These walls have a beginning and an end coordinate. My particles have known positions and velocities, so I can calculate the intersection of their trajectories with said walls. If I have a point of intersection, I move my particle there. The particle, however, must never move beyond a wall. Due to the numerical inaccuracies of double precision arithmetic, it happens that the particle gets moved a little bit too far. If I have to deal with stuff like this, I need to know exactly what the computer does with its floating point numbers.
Anyway, it's also about understanding. I want to understand what's going on. I am not satisfied with merely accepting and trying to run away from the problem.
What is happening on the inside with the double precision numbers?
What is the significance of these final digits that are outside of the 15-16 digits space?
Sometimes, if I have two doubles that onle differ at the 17th digit, the computer thinks they are the same if I test with "if(a==b)" or "cout<<a-b;" (gives either 0 or not).
Other times, it still sees a difference. Yet I cannot find a rule to that, it looks completely random to me.