MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / round_half_even

Function round_half_even

support/Rounding.h:151–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149 */
150template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)>
151inline T round_half_even(T value, T epsilon = std::numeric_limits<T>::epsilon())
152{
153 T positive_value = std::abs(value);
154 T ipart = 0;
155 std::modf(positive_value, &ipart);
156 // If 'value' is exactly halfway between two integers
157 if (std::abs(positive_value - (ipart + 0.5f)) < epsilon)
158 {
159 // If 'ipart' is even then return 'ipart'
160 if (std::fmod(ipart, 2.f) < epsilon)
161 {
162 return support::cpp11::copysign(ipart, value);
163 }
164 // Else return the nearest even integer
165 return support::cpp11::copysign(std::ceil(ipart + 0.5f), value);
166 }
167 // Otherwise use the usual round to closest
168 return support::cpp11::copysign(support::cpp11::round(positive_value), value);
169}
170
171/** Round floating-point value given a rounding mode
172 *

Callers 1

roundFunction · 0.70

Calls 6

absFunction · 0.85
modfFunction · 0.85
fmodFunction · 0.85
ceilFunction · 0.85
copysignFunction · 0.70
roundFunction · 0.70

Tested by

no test coverage detected