Convert uint32_t to double between 0 and 1 [closed]
8
I have a shamefully naive question: What is the best way to convert a uint32_t
to a double
between 0 and 1?
My naive way is
double myconvert(uint32_t a)
{
double n = static_cast<double>(std::numeric_limits<uint32_t>::max() - std::numeric_limits<uint32_t>::min());
return static_cast<double>(a) / n;
}
But I was wondering if there is a better way?
c++
static_cast<double>
hard to read. I prefer to promote implicitly all the coefficients in a term using1.0
at the start. – Bathsheba Apr 20 at 15:12