From 82d9dd1c750d9a9a64650239b6ed3f955555a728 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Mon, 10 Jun 2019 16:45:40 +0100 Subject: COMPMID-2380: Create utility functions for is_one and is_zero with float Change-Id: If5b968e19cf830d5472395a1b43bf72a456fd331 Signed-off-by: Gian Marco Iodice Reviewed-on: https://review.mlplatform.org/c/1322 Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- arm_compute/core/utils/helpers/float_ops.h | 34 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'arm_compute/core/utils') diff --git a/arm_compute/core/utils/helpers/float_ops.h b/arm_compute/core/utils/helpers/float_ops.h index 5012c8ef84..9d164150f5 100644 --- a/arm_compute/core/utils/helpers/float_ops.h +++ b/arm_compute/core/utils/helpers/float_ops.h @@ -73,25 +73,43 @@ union RawFloat * * @param[in] a First number to compare * @param[in] b Second number to compare - * @param[in] max_allowed_ulps Number of allowed ULPs + * @param[in] max_allowed_ulps (Optional) Number of allowed ULPs * * @return True if number is close else false */ -bool is_equal_ulps(float a, float b, int max_allowed_ulps = 0) +inline bool is_equal_ulps(float a, float b, int max_allowed_ulps = 0) { RawFloat ra(a); RawFloat rb(b); - // Early check for sign - if(ra.sign() != rb.sign()) - { - return (a == b); - } - // Check ULP distance const int ulps = std::abs(ra.i32 - rb.i32); return ulps <= max_allowed_ulps; } + +/** Checks if the input floating point number is 1.0f checking if the difference is within a range defined with epsilon + * + * @param[in] a Input floating point number + * @param[in] epsilon (Optional) Epsilon used to define the error bounds + * + * @return True if number is close to 1.0f + */ +inline bool is_one(float a, float epsilon = 0.00001f) +{ + return std::abs(1.0f - a) <= epsilon; +} + +/** Checks if the input floating point number is 0.0f checking if the difference is within a range defined with epsilon + * + * @param[in] a Input floating point number + * @param[in] epsilon (Optional) Epsilon used to define the error bounds + * + * @return True if number is close to 0.0f + */ +inline bool is_zero(float a, float epsilon = 0.00001f) +{ + return std::abs(0.0f - a) <= epsilon; +} } // namespace float_ops } // namespace helpers } // namespace arm_compute -- cgit v1.2.1