AP_Math: better way of handling safe_sqrt()

better to test the result, than predict it
This commit is contained in:
Andrew Tridgell
2012-03-10 10:34:31 +11:00
parent ccada2e9c2
commit 8abbbe5713
+4 -3
View File
@@ -24,10 +24,11 @@ float safe_asin(float v)
// real input should have been zero
float safe_sqrt(float v)
{
if (isnan(v) || v <= 0.0) {
return 0.0;
float ret = sqrt(v);
if (isnan(ret)) {
return 0;
}
return sqrt(v);
return ret;
}