In C++ 03, using e.g. std::pow(double_val, 6)
was considerably faster than using std::pow(double_val, 6.0)
.
This is no longer the case when compiling with C++11. Looking at the cmath header from gcc's libstdc++-4.8, one can see an explicit pow(double, int) is no longer present, this case is handled by the following template which promotes the int to a double:
template<typename _Tp, typename _Up>
inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
pow(_Tp __x, _Up __y) {
typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
return std::pow(__type(__x), __type(__y));
}
Is this behavior in the C++11 standard or could future libstdc++ implementations return to the faster method?
Secondly, if for standard or implementation reasons the faster behavior is no longer possible, what is the most portable way to achieve it again? I see a power(...)
function in the gcc stdlibc++ under "ext/numeric", but this is marked as a non-standard SGI(rip) extension.