2012-02-23 07:56:40 -04:00
|
|
|
#include "AP_Math.h"
|
|
|
|
|
|
|
|
// a varient of asin() that checks the input ranges and ensures a
|
|
|
|
// valid angle as output. If nan is given as input then zero is
|
|
|
|
// returned.
|
|
|
|
float safe_asin(float v)
|
|
|
|
{
|
|
|
|
if (isnan(v)) {
|
2012-02-23 19:40:56 -04:00
|
|
|
return 0.0;
|
2012-02-23 07:56:40 -04:00
|
|
|
}
|
|
|
|
if (v >= 1.0) {
|
|
|
|
return PI/2;
|
|
|
|
}
|
|
|
|
if (v <= -1.0) {
|
|
|
|
return -PI/2;
|
|
|
|
}
|
|
|
|
return asin(v);
|
|
|
|
}
|
2012-02-23 19:40:56 -04:00
|
|
|
|
|
|
|
// a varient of sqrt() that checks the input ranges and ensures a
|
|
|
|
// valid value as output. If a negative number is given then 0 is
|
|
|
|
// returned. The reasoning is that a negative number for sqrt() in our
|
|
|
|
// code is usually caused by small numerical rounding errors, so the
|
|
|
|
// real input should have been zero
|
|
|
|
float safe_sqrt(float v)
|
|
|
|
{
|
|
|
|
if (isnan(v) || v <= 0.0) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
return sqrt(v);
|
|
|
|
}
|