std::pow in the <cmath> header has the following overloads:
pow(float, float); pow(float, int); pow(double, double);
Now you canβt just do
pow(2, N)
with N being int, because it does not know which of the float , double or long double versions it should accept, and you get an ambiguity error. All three will need to convert from int to floating point, and all three are equally expensive!
Therefore, be sure to type the first argument so that it matches perfectly with one of these three. I usually use double
pow(2.0, N)
Some lawyer shit from me again. I myself often fell into this trap, so I am going to warn you about this.
Johannes Schaub - litb May 10 '09 at 19:41 2009-05-10 19:41
source share