From 039229248952a680199d0e0f5e99df1cb54b69db Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Tue, 28 Apr 2015 15:06:13 +0900 Subject: [PATCH] AP_Math: inline is_equal, add is_zero --- libraries/AP_Math/AP_Math.cpp | 6 ------ libraries/AP_Math/AP_Math.h | 8 ++++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/AP_Math/AP_Math.cpp b/libraries/AP_Math/AP_Math.cpp index f355c5a28a..c7c90f9c44 100644 --- a/libraries/AP_Math/AP_Math.cpp +++ b/libraries/AP_Math/AP_Math.cpp @@ -1,12 +1,6 @@ #include "AP_Math.h" #include -// are two floats equal -bool is_equal(const float &fVal1, const float &fVal2) -{ - return fabs(fVal1 - fVal2) < FLT_EPSILON ? true : false; -} - // 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. diff --git a/libraries/AP_Math/AP_Math.h b/libraries/AP_Math/AP_Math.h index 763d5398a8..0eadd9a34e 100644 --- a/libraries/AP_Math/AP_Math.h +++ b/libraries/AP_Math/AP_Math.h @@ -19,12 +19,13 @@ #include "quaternion.h" #include "polygon.h" #include "edc.h" +#include "float.h" #ifndef M_PI_F #define M_PI_F 3.141592653589793f #endif #ifndef M_2PI_F - #define M_2PI_F 2*M_PI_F + #define M_2PI_F (2*M_PI_F) #endif #ifndef PI # define PI M_PI_F @@ -75,7 +76,10 @@ AP_PARAMDEFV(Matrix3f, Matrix3f, AP_PARAM_MATRIX3F); AP_PARAMDEFV(Vector3f, Vector3f, AP_PARAM_VECTOR3F); // are two floats equal -bool is_equal(const float &fVal1, const float &fVal2); +inline bool is_equal(const float fVal1, const float fVal2) { return fabsf(fVal1 - fVal2) < FLT_EPSILON ? true : false; } + +// are two floats equal +inline bool is_zero(const float fVal1) { return fabsf(fVal1) < FLT_EPSILON ? true : false; } // a varient of asin() that always gives a valid answer. float safe_asin(float v);