How do I raise a number to a power?
2^1 2^2 2^3
std::pow in the
<cmath> header has these overloads:
pow(float, float); pow(float, int); pow(double, double); // taken over from C pow(double, int); pow(long double, long double); pow(long double, int);
Now you can't just do
with N being an int, because it doesn't know which of
long double version it should take, and you would get an ambiguity error. All three would need a conversion from int to floating point, and all three are equally costly!
Therefore, be sure to have the first argument typed so it matches one of those three perfectly. I usually use
Some lawyer crap from me again. I've often fallen in this pitfall myself, so I'm going to warn you about it.