math domain error fix from Charlie Hotchkiss.
This commit is contained in:
parent
cfc9e51128
commit
01d6408def
1 changed files with 14 additions and 2 deletions
|
@ -27,7 +27,7 @@
|
||||||
#include "star.hxx"
|
#include "star.hxx"
|
||||||
#include <Debug/logstream.hxx>
|
#include <Debug/logstream.hxx>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef FG_MATH_EXCEPTION_CLASH
|
||||||
# define exception c_exception
|
# define exception c_exception
|
||||||
#endif
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -90,7 +90,19 @@ void CelestialBody::updatePosition(fgTIME *t, Star *ourSun)
|
||||||
//of the planet
|
//of the planet
|
||||||
R = sqrt (xg*xg + yg*yg + zg*zg);
|
R = sqrt (xg*xg + yg*yg + zg*zg);
|
||||||
s = ourSun->getDistance();
|
s = ourSun->getDistance();
|
||||||
FV = RAD_TO_DEG * acos( (r*r + R*R - s*s) / (2*r*R));
|
|
||||||
|
// It is possible from these calculations for the argument to acos
|
||||||
|
// to exceed the valid range for acos(). So we do a little extra
|
||||||
|
// checking.
|
||||||
|
|
||||||
|
double tmp = (r*r + R*R - s*s) / (2*r*R);
|
||||||
|
if ( tmp > 1.0) {
|
||||||
|
tmp = 1.0;
|
||||||
|
} else if ( tmp < -1.0) {
|
||||||
|
tmp = -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FV = RAD_TO_DEG * acos( tmp );
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
Loading…
Add table
Reference in a new issue