28 #include "../../common.h"
30 bool same(
double a,
double b)
33 return std::abs(a - b) < 1e-10;
36 template <
typename Int>
bool same(Int a, Int b) {
return a == b; }
38 template <
typename T>
void check(T in,
int prec, T out)
40 std::cout <<
"Checking that " << in <<
" rounded to precision: " << prec <<
" is equal to "
42 assert(same(dccl::round(in, prec), out));
47 check(1.234, 2, 1.23);
51 check<int>(1239, -1, 1240);
52 check<int>(1351, -2, 1400);
53 check<int>(1450, -2, 1500);
54 check<int>(1344, -3, 1000);
56 check(1239.0, -1, 1240.0);
57 check(1351.0, -2, 1400.0);
58 check(1450.0, -2, 1500.0);
59 check(1344.0, -3, 1000.0);
61 check<int>(-499000, -3, -499000);
62 check<int>(-500000, -3, -500000);
64 check(-500000.0, -3, -500000.0);
72 check<dccl::int64>(1409165969804999ull, -3, 1409165969805000ull);
74 std::cout <<
"all tests passed" << std::endl;