I seek to convert a uint64_t to double.
The problem is that uint64_t is not neccessarily exactly representable as a double for large uint64_t. So instead I want a range containing lowest and highest doubles surrounding the uint64_t.
So if a cast always rounds down.
#include <cmath>
#include <cstdint>
#include <limits>
#include <tuple>
std::tuple<double, double> Intervall(uint64_t n) {
auto lower = static_cast<double>(n);
auto upper =
RoundUpToDouble(n) == lower
? lower
: std::nextafter(lower, std::numeric_limits<double>::infinity());
return std::make_tuple(lower, upper);
}
So the supplied code is wrong if
static_cast
doesn't round downwardsNeeds
RoundUpToDouble
which I don't know how to implement
What method can I use to get the lower and upper bound?