diff options
author | Gian Marco Iodice <gianmarco.iodice@arm.com> | 2019-06-10 16:45:40 +0100 |
---|---|---|
committer | Gian Marco Iodice <gianmarco.iodice@arm.com> | 2019-06-11 14:42:21 +0000 |
commit | 82d9dd1c750d9a9a64650239b6ed3f955555a728 (patch) | |
tree | e2b56bd2381defc64e50a8e97d5e5c5f293bbb35 /arm_compute | |
parent | 62404a58d4b6f5ddbf0e551764b314d1b2da2478 (diff) | |
download | ComputeLibrary-82d9dd1c750d9a9a64650239b6ed3f955555a728.tar.gz |
COMPMID-2380: Create utility functions for is_one and is_zero with float
Change-Id: If5b968e19cf830d5472395a1b43bf72a456fd331
Signed-off-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Reviewed-on: https://review.mlplatform.org/c/1322
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute')
-rw-r--r-- | arm_compute/core/utils/helpers/float_ops.h | 34 |
1 files changed, 26 insertions, 8 deletions
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 |