I'm trying to write a program to simulate the solar system and I'm passing large numbers into a function to calculate the gravitational force. The line of code in question is:
Earth.ptyForce = CalculateForce(Earth.ptyMass, Sun.ptyMass, dblSeparation)
Where:
Earth.ptyMassis equal to5.9736 * 10 ^ 24Sun.ptyMassis equal to1.989 * 10 ^ 30dblSeparationis only equal to300and is scaled inside the function.
I just get a system overflow and I suspect it's because the numbers are too large, is there any way around this? I've considered just passing smaller numbers into the function and just scaling them up but I'd rather avoid doing that if possible.
Just in case it's needed the CalculateForce Fucnction is as follows:
Public Function CalculateForce(ByVal intMass1 As Integer, ByVal intMass2 As Integer, ByVal dblDistance As Double)
dblDistance *= dblDistanceScalar
Return dblGravitationalConstant * intMass1 * intMass2 / dblDistance ^ 2
End Function
The error specifically reads:
System.OverflowException: 'Arithmetic operation resulted in an overflow.'