2012-02-23 07:56:40 -04:00
|
|
|
#include "AP_Math.h"
|
2015-04-28 02:36:53 -03:00
|
|
|
#include <float.h>
|
|
|
|
|
2012-02-23 07:56:40 -04:00
|
|
|
// 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)
|
|
|
|
{
|
2012-08-17 03:20:14 -03:00
|
|
|
if (isnan(v)) {
|
2015-04-24 00:50:50 -03:00
|
|
|
return 0.0f;
|
2012-08-17 03:20:14 -03:00
|
|
|
}
|
2013-01-10 14:42:24 -04:00
|
|
|
if (v >= 1.0f) {
|
2016-02-25 13:13:02 -04:00
|
|
|
return M_PI/2;
|
2012-08-17 03:20:14 -03:00
|
|
|
}
|
2013-01-10 14:42:24 -04:00
|
|
|
if (v <= -1.0f) {
|
2016-02-25 13:13:02 -04:00
|
|
|
return -M_PI/2;
|
2012-08-17 03:20:14 -03:00
|
|
|
}
|
2013-01-10 14:42:24 -04:00
|
|
|
return asinf(v);
|
2012-02-23 07:56:40 -04:00
|
|
|
}
|
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)
|
|
|
|
{
|
2013-01-10 14:42:24 -04:00
|
|
|
float ret = sqrtf(v);
|
2012-08-17 03:20:14 -03:00
|
|
|
if (isnan(ret)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2012-02-23 19:40:56 -04:00
|
|
|
}
|
2012-03-11 09:17:05 -03:00
|
|
|
|
|
|
|
|
2012-12-18 22:33:52 -04:00
|
|
|
|