From 33231bf9b5a4edd8e8f1be2a44085726c8d3c13a Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Thu, 18 May 2017 19:47:56 -0700 Subject: [PATCH] AP_Math: Add is_negative and is_positive helpers --- libraries/AP_Math/AP_Math.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libraries/AP_Math/AP_Math.h b/libraries/AP_Math/AP_Math.h index 2969e10577..3e7c60897f 100644 --- a/libraries/AP_Math/AP_Math.h +++ b/libraries/AP_Math/AP_Math.h @@ -42,6 +42,28 @@ inline bool is_zero(const T fVal1) { return (fabsf(static_cast(fVal1)) < FLT_EPSILON); } +/* + * @brief: Check whether a float is greater than zero + */ +template +inline bool is_positive(const T fVal1) { + static_assert(std::is_floating_point::value || std::is_base_of::value, + "Template parameter not of type float"); + return (static_cast(fVal1) > FLT_EPSILON); +} + + +/* + * @brief: Check whether a float is less than zero + */ +template +inline bool is_negative(const T fVal1) { + static_assert(std::is_floating_point::value || std::is_base_of::value, + "Template parameter not of type float"); + return (static_cast(fVal1) < (-1.0 * FLT_EPSILON)); +} + + /* * A variant of asin() that checks the input ranges and ensures a valid angle * as output. If nan is given as input then zero is returned.