cmath 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. // TR1 cmath -*- C++ -*-
  2. // Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file tr1/cmath
  21. * This is a TR1 C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_TR1_CMATH
  24. #define _GLIBCXX_TR1_CMATH 1
  25. #pragma GCC system_header
  26. #if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
  27. # error TR1 header cannot be included from C++0x header
  28. #endif
  29. #include <cmath>
  30. #if defined(_GLIBCXX_INCLUDE_AS_TR1)
  31. # include <tr1_impl/cmath>
  32. #else
  33. # define _GLIBCXX_INCLUDE_AS_TR1
  34. # define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
  35. # define _GLIBCXX_END_NAMESPACE_TR1 }
  36. # define _GLIBCXX_TR1 tr1::
  37. # include <tr1_impl/cmath>
  38. # undef _GLIBCXX_TR1
  39. # undef _GLIBCXX_END_NAMESPACE_TR1
  40. # undef _GLIBCXX_BEGIN_NAMESPACE_TR1
  41. # undef _GLIBCXX_INCLUDE_AS_TR1
  42. #endif
  43. namespace std
  44. {
  45. namespace tr1
  46. {
  47. // DR 550. What should the return type of pow(float,int) be?
  48. // NB: C++0x and TR1 != C++03.
  49. inline double
  50. pow(double __x, double __y)
  51. { return std::pow(__x, __y); }
  52. inline float
  53. pow(float __x, float __y)
  54. { return std::pow(__x, __y); }
  55. inline long double
  56. pow(long double __x, long double __y)
  57. { return std::pow(__x, __y); }
  58. template<typename _Tp, typename _Up>
  59. inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
  60. pow(_Tp __x, _Up __y)
  61. {
  62. typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
  63. return std::pow(__type(__x), __type(__y));
  64. }
  65. }
  66. }
  67. #include <bits/stl_algobase.h>
  68. #include <limits>
  69. #include <tr1/type_traits>
  70. #include <tr1/gamma.tcc>
  71. #include <tr1/bessel_function.tcc>
  72. #include <tr1/beta_function.tcc>
  73. #include <tr1/ell_integral.tcc>
  74. #include <tr1/exp_integral.tcc>
  75. #include <tr1/hypergeometric.tcc>
  76. #include <tr1/legendre_function.tcc>
  77. #include <tr1/modified_bessel_func.tcc>
  78. #include <tr1/poly_hermite.tcc>
  79. #include <tr1/poly_laguerre.tcc>
  80. #include <tr1/riemann_zeta.tcc>
  81. namespace std
  82. {
  83. namespace tr1
  84. {
  85. /**
  86. * @defgroup tr1_math_spec_func Mathematical Special Functions
  87. * @ingroup numerics
  88. *
  89. * A collection of advanced mathematical special functions.
  90. * @{
  91. */
  92. inline float
  93. assoc_laguerref(unsigned int __n, unsigned int __m, float __x)
  94. { return __detail::__assoc_laguerre<float>(__n, __m, __x); }
  95. inline long double
  96. assoc_laguerrel(unsigned int __n, unsigned int __m, long double __x)
  97. {
  98. return __detail::__assoc_laguerre<long double>(__n, __m, __x);
  99. }
  100. /// 5.2.1.1 Associated Laguerre polynomials.
  101. template<typename _Tp>
  102. inline typename __gnu_cxx::__promote<_Tp>::__type
  103. assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x)
  104. {
  105. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  106. return __detail::__assoc_laguerre<__type>(__n, __m, __x);
  107. }
  108. inline float
  109. assoc_legendref(unsigned int __l, unsigned int __m, float __x)
  110. { return __detail::__assoc_legendre_p<float>(__l, __m, __x); }
  111. inline long double
  112. assoc_legendrel(unsigned int __l, unsigned int __m, long double __x)
  113. { return __detail::__assoc_legendre_p<long double>(__l, __m, __x); }
  114. /// 5.2.1.2 Associated Legendre functions.
  115. template<typename _Tp>
  116. inline typename __gnu_cxx::__promote<_Tp>::__type
  117. assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x)
  118. {
  119. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  120. return __detail::__assoc_legendre_p<__type>(__l, __m, __x);
  121. }
  122. inline float
  123. betaf(float __x, float __y)
  124. { return __detail::__beta<float>(__x, __y); }
  125. inline long double
  126. betal(long double __x, long double __y)
  127. { return __detail::__beta<long double>(__x, __y); }
  128. /// 5.2.1.3 Beta functions.
  129. template<typename _Tpx, typename _Tpy>
  130. inline typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type
  131. beta(_Tpx __x, _Tpy __y)
  132. {
  133. typedef typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type __type;
  134. return __detail::__beta<__type>(__x, __y);
  135. }
  136. inline float
  137. comp_ellint_1f(float __k)
  138. { return __detail::__comp_ellint_1<float>(__k); }
  139. inline long double
  140. comp_ellint_1l(long double __k)
  141. { return __detail::__comp_ellint_1<long double>(__k); }
  142. /// 5.2.1.4 Complete elliptic integrals of the first kind.
  143. template<typename _Tp>
  144. inline typename __gnu_cxx::__promote<_Tp>::__type
  145. comp_ellint_1(_Tp __k)
  146. {
  147. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  148. return __detail::__comp_ellint_1<__type>(__k);
  149. }
  150. inline float
  151. comp_ellint_2f(float __k)
  152. { return __detail::__comp_ellint_2<float>(__k); }
  153. inline long double
  154. comp_ellint_2l(long double __k)
  155. { return __detail::__comp_ellint_2<long double>(__k); }
  156. /// 5.2.1.5 Complete elliptic integrals of the second kind.
  157. template<typename _Tp>
  158. inline typename __gnu_cxx::__promote<_Tp>::__type
  159. comp_ellint_2(_Tp __k)
  160. {
  161. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  162. return __detail::__comp_ellint_2<__type>(__k);
  163. }
  164. inline float
  165. comp_ellint_3f(float __k, float __nu)
  166. { return __detail::__comp_ellint_3<float>(__k, __nu); }
  167. inline long double
  168. comp_ellint_3l(long double __k, long double __nu)
  169. { return __detail::__comp_ellint_3<long double>(__k, __nu); }
  170. /// 5.2.1.6 Complete elliptic integrals of the third kind.
  171. template<typename _Tp, typename _Tpn>
  172. inline typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type
  173. comp_ellint_3(_Tp __k, _Tpn __nu)
  174. {
  175. typedef typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type __type;
  176. return __detail::__comp_ellint_3<__type>(__k, __nu);
  177. }
  178. inline float
  179. conf_hypergf(float __a, float __c, float __x)
  180. { return __detail::__conf_hyperg<float>(__a, __c, __x); }
  181. inline long double
  182. conf_hypergl(long double __a, long double __c, long double __x)
  183. { return __detail::__conf_hyperg<long double>(__a, __c, __x); }
  184. /// 5.2.1.7 Confluent hypergeometric functions.
  185. template<typename _Tpa, typename _Tpc, typename _Tp>
  186. inline typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type
  187. conf_hyperg(_Tpa __a, _Tpc __c, _Tp __x)
  188. {
  189. typedef typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type __type;
  190. return __detail::__conf_hyperg<__type>(__a, __c, __x);
  191. }
  192. inline float
  193. cyl_bessel_if(float __nu, float __x)
  194. { return __detail::__cyl_bessel_i<float>(__nu, __x); }
  195. inline long double
  196. cyl_bessel_il(long double __nu, long double __x)
  197. { return __detail::__cyl_bessel_i<long double>(__nu, __x); }
  198. /// 5.2.1.8 Regular modified cylindrical Bessel functions.
  199. template<typename _Tpnu, typename _Tp>
  200. inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
  201. cyl_bessel_i(_Tpnu __nu, _Tp __x)
  202. {
  203. typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
  204. return __detail::__cyl_bessel_i<__type>(__nu, __x);
  205. }
  206. inline float
  207. cyl_bessel_jf(float __nu, float __x)
  208. { return __detail::__cyl_bessel_j<float>(__nu, __x); }
  209. inline long double
  210. cyl_bessel_jl(long double __nu, long double __x)
  211. { return __detail::__cyl_bessel_j<long double>(__nu, __x); }
  212. /// 5.2.1.9 Cylindrical Bessel functions (of the first kind).
  213. template<typename _Tpnu, typename _Tp>
  214. inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
  215. cyl_bessel_j(_Tpnu __nu, _Tp __x)
  216. {
  217. typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
  218. return __detail::__cyl_bessel_j<__type>(__nu, __x);
  219. }
  220. inline float
  221. cyl_bessel_kf(float __nu, float __x)
  222. { return __detail::__cyl_bessel_k<float>(__nu, __x); }
  223. inline long double
  224. cyl_bessel_kl(long double __nu, long double __x)
  225. { return __detail::__cyl_bessel_k<long double>(__nu, __x); }
  226. /// 5.2.1.10 Irregular modified cylindrical Bessel functions.
  227. template<typename _Tpnu, typename _Tp>
  228. inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
  229. cyl_bessel_k(_Tpnu __nu, _Tp __x)
  230. {
  231. typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
  232. return __detail::__cyl_bessel_k<__type>(__nu, __x);
  233. }
  234. inline float
  235. cyl_neumannf(float __nu, float __x)
  236. { return __detail::__cyl_neumann_n<float>(__nu, __x); }
  237. inline long double
  238. cyl_neumannl(long double __nu, long double __x)
  239. { return __detail::__cyl_neumann_n<long double>(__nu, __x); }
  240. /// 5.2.1.11 Cylindrical Neumann functions.
  241. template<typename _Tpnu, typename _Tp>
  242. inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
  243. cyl_neumann(_Tpnu __nu, _Tp __x)
  244. {
  245. typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
  246. return __detail::__cyl_neumann_n<__type>(__nu, __x);
  247. }
  248. inline float
  249. ellint_1f(float __k, float __phi)
  250. { return __detail::__ellint_1<float>(__k, __phi); }
  251. inline long double
  252. ellint_1l(long double __k, long double __phi)
  253. { return __detail::__ellint_1<long double>(__k, __phi); }
  254. /// 5.2.1.12 Incomplete elliptic integrals of the first kind.
  255. template<typename _Tp, typename _Tpp>
  256. inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
  257. ellint_1(_Tp __k, _Tpp __phi)
  258. {
  259. typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
  260. return __detail::__ellint_1<__type>(__k, __phi);
  261. }
  262. inline float
  263. ellint_2f(float __k, float __phi)
  264. { return __detail::__ellint_2<float>(__k, __phi); }
  265. inline long double
  266. ellint_2l(long double __k, long double __phi)
  267. { return __detail::__ellint_2<long double>(__k, __phi); }
  268. /// 5.2.1.13 Incomplete elliptic integrals of the second kind.
  269. template<typename _Tp, typename _Tpp>
  270. inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
  271. ellint_2(_Tp __k, _Tpp __phi)
  272. {
  273. typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
  274. return __detail::__ellint_2<__type>(__k, __phi);
  275. }
  276. inline float
  277. ellint_3f(float __k, float __nu, float __phi)
  278. { return __detail::__ellint_3<float>(__k, __nu, __phi); }
  279. inline long double
  280. ellint_3l(long double __k, long double __nu, long double __phi)
  281. { return __detail::__ellint_3<long double>(__k, __nu, __phi); }
  282. /// 5.2.1.14 Incomplete elliptic integrals of the third kind.
  283. template<typename _Tp, typename _Tpn, typename _Tpp>
  284. inline typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type
  285. ellint_3(_Tp __k, _Tpn __nu, _Tpp __phi)
  286. {
  287. typedef typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type __type;
  288. return __detail::__ellint_3<__type>(__k, __nu, __phi);
  289. }
  290. inline float
  291. expintf(float __x)
  292. { return __detail::__expint<float>(__x); }
  293. inline long double
  294. expintl(long double __x)
  295. { return __detail::__expint<long double>(__x); }
  296. /// 5.2.1.15 Exponential integrals.
  297. template<typename _Tp>
  298. inline typename __gnu_cxx::__promote<_Tp>::__type
  299. expint(_Tp __x)
  300. {
  301. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  302. return __detail::__expint<__type>(__x);
  303. }
  304. inline float
  305. hermitef(unsigned int __n, float __x)
  306. { return __detail::__poly_hermite<float>(__n, __x); }
  307. inline long double
  308. hermitel(unsigned int __n, long double __x)
  309. { return __detail::__poly_hermite<long double>(__n, __x); }
  310. /// 5.2.1.16 Hermite polynomials.
  311. template<typename _Tp>
  312. inline typename __gnu_cxx::__promote<_Tp>::__type
  313. hermite(unsigned int __n, _Tp __x)
  314. {
  315. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  316. return __detail::__poly_hermite<__type>(__n, __x);
  317. }
  318. inline float
  319. hypergf(float __a, float __b, float __c, float __x)
  320. { return __detail::__hyperg<float>(__a, __b, __c, __x); }
  321. inline long double
  322. hypergl(long double __a, long double __b, long double __c, long double __x)
  323. { return __detail::__hyperg<long double>(__a, __b, __c, __x); }
  324. /// 5.2.1.17 Hypergeometric functions.
  325. template<typename _Tpa, typename _Tpb, typename _Tpc, typename _Tp>
  326. inline typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type
  327. hyperg(_Tpa __a, _Tpb __b, _Tpc __c, _Tp __x)
  328. {
  329. typedef typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type;
  330. return __detail::__hyperg<__type>(__a, __b, __c, __x);
  331. }
  332. inline float
  333. laguerref(unsigned int __n, float __x)
  334. { return __detail::__laguerre<float>(__n, __x); }
  335. inline long double
  336. laguerrel(unsigned int __n, long double __x)
  337. { return __detail::__laguerre<long double>(__n, __x); }
  338. /// 5.2.1.18 Laguerre polynomials.
  339. template<typename _Tp>
  340. inline typename __gnu_cxx::__promote<_Tp>::__type
  341. laguerre(unsigned int __n, _Tp __x)
  342. {
  343. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  344. return __detail::__laguerre<__type>(__n, __x);
  345. }
  346. inline float
  347. legendref(unsigned int __n, float __x)
  348. { return __detail::__poly_legendre_p<float>(__n, __x); }
  349. inline long double
  350. legendrel(unsigned int __n, long double __x)
  351. { return __detail::__poly_legendre_p<long double>(__n, __x); }
  352. /// 5.2.1.19 Legendre polynomials.
  353. template<typename _Tp>
  354. inline typename __gnu_cxx::__promote<_Tp>::__type
  355. legendre(unsigned int __n, _Tp __x)
  356. {
  357. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  358. return __detail::__poly_legendre_p<__type>(__n, __x);
  359. }
  360. inline float
  361. riemann_zetaf(float __x)
  362. { return __detail::__riemann_zeta<float>(__x); }
  363. inline long double
  364. riemann_zetal(long double __x)
  365. { return __detail::__riemann_zeta<long double>(__x); }
  366. /// 5.2.1.20 Riemann zeta function.
  367. template<typename _Tp>
  368. inline typename __gnu_cxx::__promote<_Tp>::__type
  369. riemann_zeta(_Tp __x)
  370. {
  371. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  372. return __detail::__riemann_zeta<__type>(__x);
  373. }
  374. inline float
  375. sph_besself(unsigned int __n, float __x)
  376. { return __detail::__sph_bessel<float>(__n, __x); }
  377. inline long double
  378. sph_bessell(unsigned int __n, long double __x)
  379. { return __detail::__sph_bessel<long double>(__n, __x); }
  380. /// 5.2.1.21 Spherical Bessel functions.
  381. template<typename _Tp>
  382. inline typename __gnu_cxx::__promote<_Tp>::__type
  383. sph_bessel(unsigned int __n, _Tp __x)
  384. {
  385. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  386. return __detail::__sph_bessel<__type>(__n, __x);
  387. }
  388. inline float
  389. sph_legendref(unsigned int __l, unsigned int __m, float __theta)
  390. { return __detail::__sph_legendre<float>(__l, __m, __theta); }
  391. inline long double
  392. sph_legendrel(unsigned int __l, unsigned int __m, long double __theta)
  393. { return __detail::__sph_legendre<long double>(__l, __m, __theta); }
  394. /// 5.2.1.22 Spherical associated Legendre functions.
  395. template<typename _Tp>
  396. inline typename __gnu_cxx::__promote<_Tp>::__type
  397. sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta)
  398. {
  399. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  400. return __detail::__sph_legendre<__type>(__l, __m, __theta);
  401. }
  402. inline float
  403. sph_neumannf(unsigned int __n, float __x)
  404. { return __detail::__sph_neumann<float>(__n, __x); }
  405. inline long double
  406. sph_neumannl(unsigned int __n, long double __x)
  407. { return __detail::__sph_neumann<long double>(__n, __x); }
  408. /// 5.2.1.23 Spherical Neumann functions.
  409. template<typename _Tp>
  410. inline typename __gnu_cxx::__promote<_Tp>::__type
  411. sph_neumann(unsigned int __n, _Tp __x)
  412. {
  413. typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
  414. return __detail::__sph_neumann<__type>(__n, __x);
  415. }
  416. /* @} */ // tr1_math_spec_func
  417. }
  418. }
  419. #endif // _GLIBCXX_TR1_CMATH