From: Erik Hofman Date: Tue, 29 Dec 2015 13:55:22 +0000 (+0100) Subject: Prevent two possible nan's X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=335fda719daaab3548775d1611574b3ddc69c1ae;p=flightgear.git Prevent two possible nan's --- diff --git a/src/FDM/JSBSim/initialization/FGTrim.cpp b/src/FDM/JSBSim/initialization/FGTrim.cpp index 6e7f90a55..526b81f22 100644 --- a/src/FDM/JSBSim/initialization/FGTrim.cpp +++ b/src/FDM/JSBSim/initialization/FGTrim.cpp @@ -503,7 +503,11 @@ FGTrim::RotationParameters FGTrim::calcRotation(vector& contacts, double DistPlane = d0 * DotProduct(u, iter->normal) / length; // The coordinate of the point of intersection 'P' between the circle and // the ground is (0, DistPlane, alpha) in the basis (u, v, t) - double alpha = sqrt(sqrRadius - DistPlane * DistPlane); + double mag = sqrRadius - DistPlane * DistPlane; + if (mag < 0) { + cout << "FGTrim::calcRotation DistPlane^2 larger than sqrRadius" << endl; + } + double alpha = sqrt(max(mag, 0.0)); FGColumnVector3 CP = alpha * t + DistPlane * v; // The transformation is now constructed: we can extract the angle using the // classical formulas (cosine is obtained from the dot product and sine from diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 691a34ea6..01878ea26 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -652,7 +652,10 @@ double FGAISchedule::getSpeed() double dist = SGGeodesy::distanceNm(dep->geod(), arr->geod()); double remainingTimeEnroute = (*i)->getArrivalTime() - (*i)->getDepartureTime(); - double speed = dist / (remainingTimeEnroute/3600.0); + double speed = 0.0; + if (remainingTimeEnroute > 0.01) + speed = dist / (remainingTimeEnroute/3600.0); + SG_CLAMP_RANGE(speed, 300.0, 500.0); return speed; }