According to http://en.cppreference.com/w/cpp/numeric/math/pow , when std::pow
is used with integer parameters, the result is promoted to a double
.
As several answers have pointed out even though for small numbers the result should be exactly representable there are some low quality implementations.
For the case where you are using const expressions such as:
std::pow(2, 10)
many compilers will use builtin functions for example both gcc
and clang
will use builtin functions which will probably use something like a lookup table or a simpler formula for these trivial cases. We can see for the above case using godbolt that gcc
computes the value at compile time:
movl $1024, %esi
These results are more likely to be correct as the question C: i got different results with pow(10,2) and pow(10,j), j=2; demonstrates.