MCPcopy Create free account
hub / github.com/Dobiasd/FunctionalPlus / round

Function round

include/fplus/numeric.hpp:300–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298// Converts a value to the nearest integer.
299template <typename X, typename Out = int>
300Out round(X x)
301{
302 static_assert(!std::is_integral<X>::value, "type must be non-integral");
303 static_assert(std::is_integral<Out>::value, "type must be integral");
304 if (static_cast<double>(x) < static_cast<double>(std::numeric_limits<Out>::lowest()))
305 return std::numeric_limits<Out>::lowest();
306 if (static_cast<double>(x) > static_cast<double>(std::numeric_limits<Out>::max()))
307 return std::numeric_limits<Out>::max();
308 if (is_negative(x))
309 x -= 1;
310 return static_cast<Out>(x + 0.5);
311}
312
313// API search type: floor : a -> b
314// fwd bind count: 0

Callers 5

print_doubleFunction · 0.50
fwd_test.cppFile · 0.50
maybe_test.cppFile · 0.50
result_test.cppFile · 0.50
numeric_test.cppFile · 0.50

Calls 2

maxFunction · 0.70
is_negativeFunction · 0.70

Tested by 1

print_doubleFunction · 0.40