According to http://en.cppreference.com/w/cpp/numeric/math/pow , when std::powused with integer parameters, the result is raised to double.
My question is this:
How safe is it to compare an integer type with a result std::pow(int1, int2)? For example, can ifevaluate true?
std::size_t n = 1024;
if(n != std::pow(2, 10))
cout << "Roundoff issues..." << endl;
That is, is it possible that the result on rhs can be approximately the same as 1023.99 ... 9, so when converting to size_t it becomes 1023?
I guess the answer is big NO, but I would like to know for sure. I use such comparisons when checking matrix sizes, etc., and I would not want to use it std::roundeverywhere.
source
share