24 #ifndef ARM_COMPUTE_UTILS_ROUNDING_H 25 #define ARM_COMPUTE_UTILS_ROUNDING_H 60 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
63 T res = std::floor(std::fabs(value));
64 return (value < 0.f) ? -res : res;
75 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
78 T res = std::ceil(std::fabs(value));
79 return (value < 0.f) ? -res : res;
90 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
93 T res = T(std::ceil(std::fabs(value) - 0.5f));
94 return (value < 0.f) ? -res : res;
105 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
108 T res = T(std::floor(std::fabs(value) + 0.5f));
109 return (value < 0.f) ? -res : res;
120 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
123 return std::floor(value + 0.5f);
134 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
137 return std::ceil(value - 0.5f);
149 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
152 T positive_value = std::abs(value);
154 std::modf(positive_value, &ipart);
156 if(std::abs(positive_value - (ipart + 0.5f)) <
epsilon)
159 if(std::fmod(ipart, 2.f) <
epsilon)
179 template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
182 switch(rounding_mode)
T round_half_down(T value)
Round floating-point value with half value rounding to negative infinity.
Round half towards from zero.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.
T round_half_up(T value)
Round floating-point value with half value rounding to positive infinity.
T round_away_from_zero(T value)
Round floating-point value with round away from zero.
T round_half_away_from_zero(T value)
Round floating-point value with half value rounding away from zero.
T round_half_even(T value, T epsilon=std::numeric_limits< T >::epsilon())
Round floating-point value with half value rounding to nearest even.
Copyright (c) 2017-2021 Arm Limited.
T round_half_to_zero(T value)
Round floating-point value with half value rounding towards zero.
Round half towards negative infinity.
T round_to_zero(T value)
Round floating-point value with round to zero.
Round half towards positive infinity.
Round half towards nearest even.
T round(T value)
Round floating-point value with half value rounding away from zero.
Round half away from zero.
T round(T value, RoundingMode rounding_mode)
Round floating-point value given a rounding mode.
RoundingMode
Rounding mode.