我用C++做个开x的n次方根的程序,可是一直不明白pow()函数是什么代码求 pow(x, 1 / n)。
希望回答pow()函数的代码,不是返回另一个函数的那种(递归是可以的),希望能刨根问底到最基础的那层函数。
我最多搜到这里:
using ::pow;
#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
inline _GLIBCXX_CONSTEXPR float
pow(float __x, float __y)
{ return __builtin_powf(__x, __y); }
inline _GLIBCXX_CONSTEXPR long double
pow(long double __x, long double __y)
{ return __builtin_powl(__x, __y); }
#if __cplusplus < 201103L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 550. What should the return type of pow(float,int) be?
inline double
pow(double __x, int __i)
{ return __builtin_powi(__x, __i); }
inline float
pow(float __x, int __n)
{ return __builtin_powif(__x, __n); }
inline long double
pow(long double __x, int __n)
{ return __builtin_powil(__x, __n); }
#endif
#endif
template<typename _Tp, typename _Up>
inline _GLIBCXX_CONSTEXPR
typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
pow(_Tp __x, _Up __y)
{
typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
return pow(__type(__x), __type(__y));
}
感谢每一个回答!