1

I am programming a physic simulation, and every element of the system simulated is described whit three dimension (x, y, z) stored in three long double. Well, my precision would be pretty precise, and I'd like to simulate enough vast systems, like the solar system. Considering the Sun in the center, how much can I go further to keep precision higher or equal to millimeter, and which measurement unit should I use?

P.S.:
I know that the solar system is much larger that the distance Sun-Pluto, but that distance is the minimum size that I'd like to consider valid in my simulation

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • https://www.tutorialspoint.com/cprogramming/c_data_types.htm – OldProgrammer Dec 18 '16 at 20:53
  • First thing you should know is that even if you could represent the value there is an inherit precision loss because of the way computers store numbers. Also, it might be irrelevant to use such a high precision for a simulation, you should analyze how relevant the precision is. That being said, you can use big number libraries to make computations with very precise numbers. It would however require a lot of computation power. Think about what a millimeter represents for the distance from the sun to the earth! Is it irrelevant or not? – Iharob Al Asimi Dec 18 '16 at 20:54
  • 1
    Sun-pluto distance is about 5.9e15mm. IEEE754 standard double precision provides 15-17 decimal digits (52 bit binary bits) precision. So standard double precision should be OK, long double may be better but long double is highly implementation defined and a lot of implementations choose to define long double the same as double, so do check the user manual. – user3528438 Dec 18 '16 at 21:06
  • this [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](http://stackoverflow.com/a/28020934/2521214) might interest you (especially the integration part). – Spektre Dec 19 '16 at 08:37
  • Answer to iharob: Thanks for your answer. I don't mind to have a too much precise simulation, but to have precise data; I mean: I'd like to simulate the movement of planets under gravity, but also interaction of little object like probes and asteroids, so even if the planet my probe is orbiting is orbiting some meters away is ok, but I also want to have my probe coordinates enought precise to calculate, for example, an impact whit an asteroid. – Emanuele Sorce Dec 19 '16 at 23:12

1 Answers1

6

The "Pluto/Sun mean distance" is 5.9*1012 meters or 5.9*1015 mm.

Typical double has 253 or about 9*1015 decimal precision and so can represent the Sun/Pluto distance exactly - to the millimeter.

Start with double and focus on code's various calculations that may compromise precision. If necessary use long double, yet I suspect double will work for you.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256