# tr1/cmath

Go to the documentation of this file.

    00001 // TR1 cmath -*- C++ -*-
    00002
    00003 // Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 3, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // Under Section 7 of GPL version 3, you are granted additional
    00017 // permissions described in the GCC Runtime Library Exception, version
    00018 // 3.1, as published by the Free Software Foundation.
    00019
    00020 // You should have received a copy of the GNU General Public License and
    00021 // a copy of the GCC Runtime Library Exception along with this program;
    00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00023 // <http://www.gnu.org/licenses/>.
    00024
    00025 /** @file tr1/cmath
    00026  *  This is a TR1 C++ Library header.
    00027  */
    00028
    00029 #ifndef _GLIBCXX_TR1_CMATH
    00030 #define _GLIBCXX_TR1_CMATH 1
    00031
    00032 #pragma GCC system_header
    00033
    00034 #if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
    00035 #  error TR1 header cannot be included from C++0x header
    00036 #endif
    00037
    00038 #include <cmath>
    00039
    00040 #if defined(_GLIBCXX_INCLUDE_AS_TR1)
    00041 #  include <tr1_impl/cmath>
    00042 #else
    00043 #  define _GLIBCXX_INCLUDE_AS_TR1
    00044 #  define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
    00045 #  define _GLIBCXX_END_NAMESPACE_TR1 }
    00046 #  define _GLIBCXX_TR1 tr1::
    00047 #  include <tr1_impl/cmath>
    00048 #  undef _GLIBCXX_TR1
    00049 #  undef _GLIBCXX_END_NAMESPACE_TR1
    00050 #  undef _GLIBCXX_BEGIN_NAMESPACE_TR1
    00051 #  undef _GLIBCXX_INCLUDE_AS_TR1
    00052 #endif
    00053
    00054 namespace std
    00055 {
    00056 namespace tr1
    00057 {
    00058   // DR 550. What should the return type of pow(float,int) be?
    00059   // NB: C++0x and TR1 != C++03.
    00060   inline double
    00061   pow(double __x, double __y)
    00062   { return std::pow(__x, __y); }
    00063
    00064   inline float
    00065   pow(float __x, float __y)
    00066   { return std::pow(__x, __y); }
    00067
    00068   inline long double
    00069   pow(long double __x, long double __y)
    00070   { return std::pow(__x, __y); }
    00071
    00072   template<typename _Tp, typename _Up>
    00073     inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
    00074     pow(_Tp __x, _Up __y)
    00075     {
    00076       typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
    00077       return std::pow(__type(__x), __type(__y));
    00078     }
    00079 }
    00080 }
    00081
    00082 #include <bits/stl_algobase.h>
    00083 #include <limits>
    00084 #include <tr1/type_traits>
    00085
    00086 #include <tr1/gamma.tcc>
    00087 #include <tr1/bessel_function.tcc>
    00088 #include <tr1/beta_function.tcc>
    00089 #include <tr1/ell_integral.tcc>
    00090 #include <tr1/exp_integral.tcc>
    00091 #include <tr1/hypergeometric.tcc>
    00092 #include <tr1/legendre_function.tcc>
    00093 #include <tr1/modified_bessel_func.tcc>
    00094 #include <tr1/poly_hermite.tcc>
    00095 #include <tr1/poly_laguerre.tcc>
    00096 #include <tr1/riemann_zeta.tcc>
    00097
    00098 namespace std
    00099 {
    00100 namespace tr1
    00101 {
    00102   /**
    00103    * @defgroup tr1_math_spec_func Mathematical Special Functions
    00104    * @ingroup numerics
    00105    *
    00106    * A collection of advanced mathematical special functions.
    00107    * @{
    00108    */
    00109
    00110   inline float
    00111   assoc_laguerref(unsigned int __n, unsigned int __m, float __x)
    00112   { return __detail::__assoc_laguerre<float>(__n, __m, __x); }
    00113
    00114   inline long double
    00115   assoc_laguerrel(unsigned int __n, unsigned int __m, long double __x)
    00116   {
    00117     return __detail::__assoc_laguerre<long double>(__n, __m, __x);
    00118   }
    00119
    00120   ///  5.2.1.1  Associated Laguerre polynomials.
    00121   template<typename _Tp>
    00122     inline typename __gnu_cxx::__promote<_Tp>::__type
    00123     assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x)
    00124     {
    00125       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00126       return __detail::__assoc_laguerre<__type>(__n, __m, __x);
    00127     }
    00128
    00129   inline float
    00130   assoc_legendref(unsigned int __l, unsigned int __m, float __x)
    00131   { return __detail::__assoc_legendre_p<float>(__l, __m, __x); }
    00132
    00133   inline long double
    00134   assoc_legendrel(unsigned int __l, unsigned int __m, long double __x)
    00135   { return __detail::__assoc_legendre_p<long double>(__l, __m, __x); }
    00136
    00137   ///  5.2.1.2  Associated Legendre functions.
    00138   template<typename _Tp>
    00139     inline typename __gnu_cxx::__promote<_Tp>::__type
    00140     assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x)
    00141     {
    00142       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00143       return __detail::__assoc_legendre_p<__type>(__l, __m, __x);
    00144     }
    00145
    00146   inline float
    00147   betaf(float __x, float __y)
    00148   { return __detail::__beta<float>(__x, __y); }
    00149
    00150   inline long double
    00151   betal(long double __x, long double __y)
    00152   { return __detail::__beta<long double>(__x, __y); }
    00153
    00154   ///  5.2.1.3  Beta functions.
    00155   template<typename _Tpx, typename _Tpy>
    00156     inline typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type
    00157     beta(_Tpx __x, _Tpy __y)
    00158     {
    00159       typedef typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type __type;
    00160       return __detail::__beta<__type>(__x, __y);
    00161     }
    00162
    00163   inline float
    00164   comp_ellint_1f(float __k)
    00165   { return __detail::__comp_ellint_1<float>(__k); }
    00166
    00167   inline long double
    00168   comp_ellint_1l(long double __k)
    00169   { return __detail::__comp_ellint_1<long double>(__k); }
    00170
    00171   ///  5.2.1.4  Complete elliptic integrals of the first kind.
    00172   template<typename _Tp>
    00173     inline typename __gnu_cxx::__promote<_Tp>::__type
    00174     comp_ellint_1(_Tp __k)
    00175     {
    00176       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00177       return __detail::__comp_ellint_1<__type>(__k);
    00178     }
    00179
    00180   inline float
    00181   comp_ellint_2f(float __k)
    00182   { return __detail::__comp_ellint_2<float>(__k); }
    00183
    00184   inline long double
    00185   comp_ellint_2l(long double __k)
    00186   { return __detail::__comp_ellint_2<long double>(__k); }
    00187
    00188   ///  5.2.1.5  Complete elliptic integrals of the second kind.
    00189   template<typename _Tp>
    00190     inline typename __gnu_cxx::__promote<_Tp>::__type
    00191     comp_ellint_2(_Tp __k)
    00192     {
    00193       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00194       return __detail::__comp_ellint_2<__type>(__k);
    00195     }
    00196
    00197   inline float
    00198   comp_ellint_3f(float __k, float __nu)
    00199   { return __detail::__comp_ellint_3<float>(__k, __nu); }
    00200
    00201   inline long double
    00202   comp_ellint_3l(long double __k, long double __nu)
    00203   { return __detail::__comp_ellint_3<long double>(__k, __nu); }
    00204
    00205   ///  5.2.1.6  Complete elliptic integrals of the third kind.
    00206   template<typename _Tp, typename _Tpn>
    00207     inline typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type
    00208     comp_ellint_3(_Tp __k, _Tpn __nu)
    00209     {
    00210       typedef typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type __type;
    00211       return __detail::__comp_ellint_3<__type>(__k, __nu);
    00212     }
    00213
    00214   inline float
    00215   conf_hypergf(float __a, float __c, float __x)
    00216   { return __detail::__conf_hyperg<float>(__a, __c, __x); }
    00217
    00218   inline long double
    00219   conf_hypergl(long double __a, long double __c, long double __x)
    00220   { return __detail::__conf_hyperg<long double>(__a, __c, __x); }
    00221
    00222   ///  5.2.1.7  Confluent hypergeometric functions.
    00223   template<typename _Tpa, typename _Tpc, typename _Tp>
    00224     inline typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type
    00225     conf_hyperg(_Tpa __a, _Tpc __c, _Tp __x)
    00226     {
    00227       typedef typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type __type;
    00228       return __detail::__conf_hyperg<__type>(__a, __c, __x);
    00229     }
    00230
    00231   inline float
    00232   cyl_bessel_if(float __nu, float __x)
    00233   { return __detail::__cyl_bessel_i<float>(__nu, __x); }
    00234
    00235   inline long double
    00236   cyl_bessel_il(long double __nu, long double __x)
    00237   { return __detail::__cyl_bessel_i<long double>(__nu, __x); }
    00238
    00239   ///  5.2.1.8  Regular modified cylindrical Bessel functions.
    00240   template<typename _Tpnu, typename _Tp>
    00241     inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
    00242     cyl_bessel_i(_Tpnu __nu, _Tp __x)
    00243     {
    00244       typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
    00245       return __detail::__cyl_bessel_i<__type>(__nu, __x);
    00246     }
    00247
    00248   inline float
    00249   cyl_bessel_jf(float __nu, float __x)
    00250   { return __detail::__cyl_bessel_j<float>(__nu, __x); }
    00251
    00252   inline long double
    00253   cyl_bessel_jl(long double __nu, long double __x)
    00254   { return __detail::__cyl_bessel_j<long double>(__nu, __x); }
    00255
    00256   ///  5.2.1.9  Cylindrical Bessel functions (of the first kind).
    00257   template<typename _Tpnu, typename _Tp>
    00258     inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
    00259     cyl_bessel_j(_Tpnu __nu, _Tp __x)
    00260     {
    00261       typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
    00262       return __detail::__cyl_bessel_j<__type>(__nu, __x);
    00263     }
    00264
    00265   inline float
    00266   cyl_bessel_kf(float __nu, float __x)
    00267   { return __detail::__cyl_bessel_k<float>(__nu, __x); }
    00268
    00269   inline long double
    00270   cyl_bessel_kl(long double __nu, long double __x)
    00271   { return __detail::__cyl_bessel_k<long double>(__nu, __x); }
    00272
    00273   ///  5.2.1.10  Irregular modified cylindrical Bessel functions.
    00274   template<typename _Tpnu, typename _Tp>
    00275     inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
    00276     cyl_bessel_k(_Tpnu __nu, _Tp __x)
    00277     {
    00278       typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
    00279       return __detail::__cyl_bessel_k<__type>(__nu, __x);
    00280     }
    00281
    00282   inline float
    00283   cyl_neumannf(float __nu, float __x)
    00284   { return __detail::__cyl_neumann_n<float>(__nu, __x); }
    00285
    00286   inline long double
    00287   cyl_neumannl(long double __nu, long double __x)
    00288   { return __detail::__cyl_neumann_n<long double>(__nu, __x); }
    00289
    00290   ///  5.2.1.11  Cylindrical Neumann functions.
    00291   template<typename _Tpnu, typename _Tp>
    00292     inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
    00293     cyl_neumann(_Tpnu __nu, _Tp __x)
    00294     {
    00295       typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
    00296       return __detail::__cyl_neumann_n<__type>(__nu, __x);
    00297     }
    00298
    00299   inline float
    00300   ellint_1f(float __k, float __phi)
    00301   { return __detail::__ellint_1<float>(__k, __phi); }
    00302
    00303   inline long double
    00304   ellint_1l(long double __k, long double __phi)
    00305   { return __detail::__ellint_1<long double>(__k, __phi); }
    00306
    00307   ///  5.2.1.12  Incomplete elliptic integrals of the first kind.
    00308   template<typename _Tp, typename _Tpp>
    00309     inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
    00310     ellint_1(_Tp __k, _Tpp __phi)
    00311     {
    00312       typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
    00313       return __detail::__ellint_1<__type>(__k, __phi);
    00314     }
    00315
    00316   inline float
    00317   ellint_2f(float __k, float __phi)
    00318   { return __detail::__ellint_2<float>(__k, __phi); }
    00319
    00320   inline long double
    00321   ellint_2l(long double __k, long double __phi)
    00322   { return __detail::__ellint_2<long double>(__k, __phi); }
    00323
    00324   ///  5.2.1.13  Incomplete elliptic integrals of the second kind.
    00325   template<typename _Tp, typename _Tpp>
    00326     inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
    00327     ellint_2(_Tp __k, _Tpp __phi)
    00328     {
    00329       typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
    00330       return __detail::__ellint_2<__type>(__k, __phi);
    00331     }
    00332
    00333   inline float
    00334   ellint_3f(float __k, float __nu, float __phi)
    00335   { return __detail::__ellint_3<float>(__k, __nu, __phi); }
    00336
    00337   inline long double
    00338   ellint_3l(long double __k, long double __nu, long double __phi)
    00339   { return __detail::__ellint_3<long double>(__k, __nu, __phi); }
    00340
    00341   ///  5.2.1.14  Incomplete elliptic integrals of the third kind.
    00342   template<typename _Tp, typename _Tpn, typename _Tpp>
    00343     inline typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type
    00344     ellint_3(_Tp __k, _Tpn __nu, _Tpp __phi)
    00345     {
    00346       typedef typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type __type;
    00347       return __detail::__ellint_3<__type>(__k, __nu, __phi);
    00348     }
    00349
    00350   inline float
    00351   expintf(float __x)
    00352   { return __detail::__expint<float>(__x); }
    00353
    00354   inline long double
    00355   expintl(long double __x)
    00356   { return __detail::__expint<long double>(__x); }
    00357
    00358   ///  5.2.1.15  Exponential integrals.
    00359   template<typename _Tp>
    00360     inline typename __gnu_cxx::__promote<_Tp>::__type
    00361     expint(_Tp __x)
    00362     {
    00363       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00364       return __detail::__expint<__type>(__x);
    00365     }
    00366
    00367   inline float
    00368   hermitef(unsigned int __n, float __x)
    00369   { return __detail::__poly_hermite<float>(__n, __x); }
    00370
    00371   inline long double
    00372   hermitel(unsigned int __n, long double __x)
    00373   { return __detail::__poly_hermite<long double>(__n, __x); }
    00374
    00375   ///  5.2.1.16  Hermite polynomials.
    00376   template<typename _Tp>
    00377     inline typename __gnu_cxx::__promote<_Tp>::__type
    00378     hermite(unsigned int __n, _Tp __x)
    00379     {
    00380       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00381       return __detail::__poly_hermite<__type>(__n, __x);
    00382     }
    00383
    00384   inline float
    00385   hypergf(float __a, float __b, float __c, float __x)
    00386   { return __detail::__hyperg<float>(__a, __b, __c, __x); }
    00387
    00388   inline long double
    00389   hypergl(long double __a, long double __b, long double __c, long double __x)
    00390   { return __detail::__hyperg<long double>(__a, __b, __c, __x); }
    00391
    00392   ///  5.2.1.17  Hypergeometric functions.
    00393   template<typename _Tpa, typename _Tpb, typename _Tpc, typename _Tp>
    00394     inline typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type
    00395     hyperg(_Tpa __a, _Tpb __b, _Tpc __c, _Tp __x)
    00396     {
    00397       typedef typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type;
    00398       return __detail::__hyperg<__type>(__a, __b, __c, __x);
    00399     }
    00400
    00401   inline float
    00402   laguerref(unsigned int __n, float __x)
    00403   { return __detail::__laguerre<float>(__n, __x); }
    00404
    00405   inline long double
    00406   laguerrel(unsigned int __n, long double __x)
    00407   { return __detail::__laguerre<long double>(__n, __x); }
    00408
    00409   ///  5.2.1.18  Laguerre polynomials.
    00410   template<typename _Tp>
    00411     inline typename __gnu_cxx::__promote<_Tp>::__type
    00412     laguerre(unsigned int __n, _Tp __x)
    00413     {
    00414       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00415       return __detail::__laguerre<__type>(__n, __x);
    00416     }
    00417
    00418   inline float
    00419   legendref(unsigned int __n, float __x)
    00420   { return __detail::__poly_legendre_p<float>(__n, __x); }
    00421
    00422   inline long double
    00423   legendrel(unsigned int __n, long double __x)
    00424   { return __detail::__poly_legendre_p<long double>(__n, __x); }
    00425
    00426   ///  5.2.1.19  Legendre polynomials.
    00427   template<typename _Tp>
    00428     inline typename __gnu_cxx::__promote<_Tp>::__type
    00429     legendre(unsigned int __n, _Tp __x)
    00430     {
    00431       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00432       return __detail::__poly_legendre_p<__type>(__n, __x);
    00433     }
    00434
    00435   inline float
    00436   riemann_zetaf(float __x)
    00437   { return __detail::__riemann_zeta<float>(__x); }
    00438
    00439   inline long double
    00440   riemann_zetal(long double __x)
    00441   { return __detail::__riemann_zeta<long double>(__x); }
    00442
    00443   ///  5.2.1.20  Riemann zeta function.
    00444   template<typename _Tp>
    00445     inline typename __gnu_cxx::__promote<_Tp>::__type
    00446     riemann_zeta(_Tp __x)
    00447     {
    00448       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00449       return __detail::__riemann_zeta<__type>(__x);
    00450     }
    00451
    00452   inline float
    00453   sph_besself(unsigned int __n, float __x)
    00454   { return __detail::__sph_bessel<float>(__n, __x); }
    00455
    00456   inline long double
    00457   sph_bessell(unsigned int __n, long double __x)
    00458   { return __detail::__sph_bessel<long double>(__n, __x); }
    00459
    00460   ///  5.2.1.21  Spherical Bessel functions.
    00461   template<typename _Tp>
    00462     inline typename __gnu_cxx::__promote<_Tp>::__type
    00463     sph_bessel(unsigned int __n, _Tp __x)
    00464     {
    00465       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00466       return __detail::__sph_bessel<__type>(__n, __x);
    00467     }
    00468
    00469   inline float
    00470   sph_legendref(unsigned int __l, unsigned int __m, float __theta)
    00471   { return __detail::__sph_legendre<float>(__l, __m, __theta); }
    00472
    00473   inline long double
    00474   sph_legendrel(unsigned int __l, unsigned int __m, long double __theta)
    00475   { return __detail::__sph_legendre<long double>(__l, __m, __theta); }
    00476
    00477   ///  5.2.1.22  Spherical associated Legendre functions.
    00478   template<typename _Tp>
    00479     inline typename __gnu_cxx::__promote<_Tp>::__type
    00480     sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta)
    00481     {
    00482       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00483       return __detail::__sph_legendre<__type>(__l, __m, __theta);
    00484     }
    00485
    00486   inline float
    00487   sph_neumannf(unsigned int __n, float __x)
    00488   { return __detail::__sph_neumann<float>(__n, __x); }
    00489
    00490   inline long double
    00491   sph_neumannl(unsigned int __n, long double __x)
    00492   { return __detail::__sph_neumann<long double>(__n, __x); }
    00493
    00494   ///  5.2.1.23  Spherical Neumann functions.
    00495   template<typename _Tp>
    00496     inline typename __gnu_cxx::__promote<_Tp>::__type
    00497     sph_neumann(unsigned int __n, _Tp __x)
    00498     {
    00499       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
    00500       return __detail::__sph_neumann<__type>(__n, __x);
    00501     }
    00502
    00503   /* @} */ // tr1_math_spec_func
    00504 }
    00505 }
    00506
    00507 #endif // _GLIBCXX_TR1_CMATH