First of all, yes this behaviour is consistent with the C++11 standard (though not with C++03), which in section 26.8, paragraph 11 says:
Moreover, there shall be additional overloads sufficient to ensure:
If any argument corresponding to a double parameter has type long double, then all arguments corresponding to double parameters are effectively cast to long double.
Otherwise, if any argument corresponding to a double parameter has type double or an integer type, then all arguments corresponding to double parameters are effectively cast to double.
Otherwise, all arguments corresponding to double parameters are effectively cast to float.
(In addition to the overloads for float
-only, double
-only and long double
-only.)
So the implementation actually has to cast that integer argument into a double
and I don't think there is a possibility for a conforming library to provide a faster std::pow
for integer powers, apart from maybe checking the double
argument for integrality (is that a word?) and using a special path in this case.
In order to provide a platform-independent faster way, the only thing that comes to my mind would be to write a custom wrapper that delegates to this non-standard power
if it is present. Other than that I don't know how you could infuse that behaviour into std::pow
again without writing your own implementation.
EDIT: Yet when looking at this answer it is indeed possible for an implementation to still provide an optimized overload for integer powers as long as it behaves exactly like std::pow(double(x), double(y))
. So there is a possiblity for an implementation to provide that faster version, yet I wouldn't count so much on this as you have done in C++03 (where it was IMHO even part of the standard, but I might be wrong).