May-be a template function:
Code:
#include <iostream>
template <class N>
N all_ones()
{
return ~N();
}
int main()
{
unsigned long long a = all_ones<unsigned long>();
unsigned long long b = all_ones<unsigned long long>();
std::cout << std::hex << a << '\n' << b << '\n';
}
This won't work with signed types, though, because the result would be seen as -1 in either case, and the implicit cast from -1L to -1LL would flip the rest of the bits.
However, it also appears to me that you might just want to divide 2.0 by the maximum value of corresponding unsigned type:
Code:
#include <limits>
double d = 2.0 / std::numeric_limits<unsigned long>::max();
Be warned that you could lose some precision with unsigned long long, since its maximum value might not be exactly representable as double.