1 #ifndef _theplu_yat_utility_round_ 2 #define _theplu_yat_utility_round_ 46 template<
typename InputIterator,
typename ForwardIterator>
47 void round(InputIterator first, InputIterator last,
48 ForwardIterator result)
50 std::multimap<double, ForwardIterator> map;
51 double result_sum = 0;
53 for (
auto it = first; it != last; ++it) {
57 *result = std::floor(x);
58 map.insert(std::make_pair(*result - x, result));
59 result_sum += *result;
62 double rounded_sum = std::round(input_sum);
64 for (
auto it = map.begin(); result_sum<rounded_sum; ++it) {
65 YAT_ASSERT(it != map.end());
The Department of Theoretical Physics namespace as we define it.
void round(InputIterator first, InputIterator last, ForwardIterator result)
Round a range.
Definition: round.h:47