Reputation: 9
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.ptyMass
is equal to 5.9736 * 10 ^ 24
Sun.ptyMass
is equal to 1.989 * 10 ^ 30
dblSeparation
is only equal to 300
and 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.'
Upvotes: 0
Views: 49