cmath

Go to the documentation of this file.
00001 // -*- C++ -*- C forwarding header.
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00004 // 2006, 2007
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 2, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // You should have received a copy of the GNU General Public License
00019 // along with this library; see the file COPYING.  If not, write to
00020 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
00021 // Boston, MA 02110-1301, USA.
00022 
00023 // As a special exception, you may use this file as part of a free software
00024 // library without restriction.  Specifically, if other files instantiate
00025 // templates or use macros or inline functions from this file, or you compile
00026 // this file and link it with other files to produce an executable, this
00027 // file does not by itself cause the resulting executable to be covered by
00028 // the GNU General Public License.  This exception does not however
00029 // invalidate any other reasons why the executable file might be covered by
00030 // the GNU General Public License.
00031 
00032 /** @file include/cmath
00033  *  This is a Standard C++ Library file.  You should @c #include this file
00034  *  in your programs, rather than any of the "*.h" implementation files.
00035  *
00036  *  This is the C++ version of the Standard C Library header @c math.h,
00037  *  and its contents are (mostly) the same as that header, but are all
00038  *  contained in the namespace @c std (except for names which are defined
00039  *  as macros in C).
00040  */
00041 
00042 //
00043 // ISO C++ 14882: 26.5  C library
00044 //
00045 
00046 #pragma GCC system_header
00047 
00048 #include <bits/c++config.h>
00049 #include <bits/cpp_type_traits.h>
00050 #include <ext/type_traits.h>
00051 #include_next <math.h>
00052 
00053 #ifndef _GLIBCXX_CMATH
00054 #define _GLIBCXX_CMATH 1
00055 
00056 // Get rid of those macros defined in <math.h> in lieu of real functions.
00057 #undef abs
00058 #undef div
00059 #undef acos
00060 #undef asin
00061 #undef atan
00062 #undef atan2
00063 #undef ceil
00064 #undef cos
00065 #undef cosh
00066 #undef exp
00067 #undef fabs
00068 #undef floor
00069 #undef fmod
00070 #undef frexp
00071 #undef ldexp
00072 #undef log
00073 #undef log10
00074 #undef modf
00075 #undef pow
00076 #undef sin
00077 #undef sinh
00078 #undef sqrt
00079 #undef tan
00080 #undef tanh
00081 
00082 _GLIBCXX_BEGIN_NAMESPACE(std)
00083 
00084   // Forward declaration of a helper function.  This really should be
00085   // an `exported' forward declaration.
00086   template<typename _Tp>
00087     _Tp __cmath_power(_Tp, unsigned int);
00088 
00089   template<typename _Tp>
00090     inline _Tp
00091     __pow_helper(_Tp __x, int __n)
00092     {
00093       return __n < 0
00094         ? _Tp(1)/__cmath_power(__x, -__n)
00095         : __cmath_power(__x, __n);
00096     }
00097 
00098   inline double
00099   abs(double __x)
00100   { return __builtin_fabs(__x); }
00101 
00102   inline float
00103   abs(float __x)
00104   { return __builtin_fabsf(__x); }
00105 
00106   inline long double
00107   abs(long double __x)
00108   { return __builtin_fabsl(__x); }
00109 
00110   using ::acos;
00111 
00112   inline float
00113   acos(float __x)
00114   { return __builtin_acosf(__x); }
00115 
00116   inline long double
00117   acos(long double __x)
00118   { return __builtin_acosl(__x); }
00119 
00120   template<typename _Tp>
00121     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00122                        double>::__type
00123     acos(_Tp __x)
00124     { return __builtin_acos(__x); }
00125 
00126   using ::asin;
00127 
00128   inline float
00129   asin(float __x)
00130   { return __builtin_asinf(__x); }
00131 
00132   inline long double
00133   asin(long double __x)
00134   { return __builtin_asinl(__x); }
00135 
00136   template<typename _Tp>
00137     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
00138                        double>::__type
00139     asin(_Tp __x)
00140     { return __builtin_asin(__x); }
00141 
00142   using ::atan;
00143 
00144   inline float
00145   atan(float __x)
00146   { return __builtin_atanf(__x); }
00147 
00148   inline long double
00149   atan(long double __x)
00150   { return __builtin_atanl(__x); }
00151 
00152   template<typename _Tp>
00153     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00154                        double>::__type
00155     atan(_Tp __x)
00156     { return __builtin_atan(__x); }
00157 
00158   using ::atan2;
00159 
00160   inline float
00161   atan2(float __y, float __x)
00162   { return __builtin_atan2f(__y, __x); }
00163 
00164   inline long double
00165   atan2(long double __y, long double __x)
00166   { return __builtin_atan2l(__y, __x); }
00167 
00168   template<typename _Tp, typename _Up>
00169     inline
00170     typename __gnu_cxx::__promote_2<
00171     typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
00172                     && __is_arithmetic<_Up>::__value,
00173                     _Tp>::__type, _Up>::__type
00174     atan2(_Tp __y, _Up __x)
00175     {
00176       typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
00177       return atan2(__type(__y), __type(__x));
00178     }
00179 
00180   using ::ceil;
00181 
00182   inline float
00183   ceil(float __x)
00184   { return __builtin_ceilf(__x); }
00185 
00186   inline long double
00187   ceil(long double __x)
00188   { return __builtin_ceill(__x); }
00189 
00190   template<typename _Tp>
00191     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00192                        double>::__type
00193     ceil(_Tp __x)
00194     { return __builtin_ceil(__x); }
00195 
00196   using ::cos;
00197 
00198   inline float
00199   cos(float __x)
00200   { return __builtin_cosf(__x); }
00201 
00202   inline long double
00203   cos(long double __x)
00204   { return __builtin_cosl(__x); }
00205 
00206   template<typename _Tp>
00207     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00208                        double>::__type
00209     cos(_Tp __x)
00210     { return __builtin_cos(__x); }
00211 
00212   using ::cosh;
00213 
00214   inline float
00215   cosh(float __x)
00216   { return __builtin_coshf(__x); }
00217 
00218   inline long double
00219   cosh(long double __x)
00220   { return __builtin_coshl(__x); }
00221 
00222   template<typename _Tp>
00223     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00224                        double>::__type
00225     cosh(_Tp __x)
00226     { return __builtin_cosh(__x); }
00227 
00228   using ::exp;
00229 
00230   inline float
00231   exp(float __x)
00232   { return __builtin_expf(__x); }
00233 
00234   inline long double
00235   exp(long double __x)
00236   { return __builtin_expl(__x); }
00237 
00238   template<typename _Tp>
00239     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00240                        double>::__type
00241     exp(_Tp __x)
00242     { return __builtin_exp(__x); }
00243 
00244   using ::fabs;
00245 
00246   inline float
00247   fabs(float __x)
00248   { return __builtin_fabsf(__x); }
00249 
00250   inline long double
00251   fabs(long double __x)
00252   { return __builtin_fabsl(__x); }
00253 
00254   template<typename _Tp>
00255     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00256                        double>::__type
00257     fabs(_Tp __x)
00258     { return __builtin_fabs(__x); }
00259 
00260   using ::floor;
00261 
00262   inline float
00263   floor(float __x)
00264   { return __builtin_floorf(__x); }
00265 
00266   inline long double
00267   floor(long double __x)
00268   { return __builtin_floorl(__x); }
00269 
00270   template<typename _Tp>
00271     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00272                        double>::__type
00273     floor(_Tp __x)
00274     { return __builtin_floor(__x); }
00275 
00276   using ::fmod;
00277 
00278   inline float
00279   fmod(float __x, float __y)
00280   { return __builtin_fmodf(__x, __y); }
00281 
00282   inline long double
00283   fmod(long double __x, long double __y)
00284   { return __builtin_fmodl(__x, __y); }
00285 
00286   using ::frexp;
00287 
00288   inline float
00289   frexp(float __x, int* __exp)
00290   { return __builtin_frexpf(__x, __exp); }
00291 
00292   inline long double
00293   frexp(long double __x, int* __exp)
00294   { return __builtin_frexpl(__x, __exp); }
00295 
00296   template<typename _Tp>
00297     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00298                        double>::__type
00299     frexp(_Tp __x, int* __exp)
00300     { return __builtin_frexp(__x, __exp); }
00301 
00302   using ::ldexp;
00303 
00304   inline float
00305   ldexp(float __x, int __exp)
00306   { return __builtin_ldexpf(__x, __exp); }
00307 
00308   inline long double
00309   ldexp(long double __x, int __exp)
00310   { return __builtin_ldexpl(__x, __exp); }
00311 
00312   template<typename _Tp>
00313     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00314                        double>::__type
00315   ldexp(_Tp __x, int __exp)
00316   { return __builtin_ldexp(__x, __exp); }
00317 
00318   using ::log;
00319 
00320   inline float
00321   log(float __x)
00322   { return __builtin_logf(__x); }
00323 
00324   inline long double
00325   log(long double __x)
00326   { return __builtin_logl(__x); }
00327 
00328   template<typename _Tp>
00329     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00330                        double>::__type
00331     log(_Tp __x)
00332     { return __builtin_log(__x); }
00333 
00334   using ::log10;
00335 
00336   inline float
00337   log10(float __x)
00338   { return __builtin_log10f(__x); }
00339 
00340   inline long double
00341   log10(long double __x)
00342   { return __builtin_log10l(__x); }
00343 
00344   template<typename _Tp>
00345     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00346                        double>::__type
00347     log10(_Tp __x)
00348     { return __builtin_log10(__x); }
00349 
00350   using ::modf;
00351 
00352   inline float
00353   modf(float __x, float* __iptr)
00354   { return __builtin_modff(__x, __iptr); }
00355 
00356   inline long double
00357   modf(long double __x, long double* __iptr)
00358   { return __builtin_modfl(__x, __iptr); }
00359 
00360   using ::pow;
00361 
00362   inline float
00363   pow(float __x, float __y)
00364   { return __builtin_powf(__x, __y); }
00365 
00366   inline long double
00367   pow(long double __x, long double __y)
00368   { return __builtin_powl(__x, __y); }
00369 
00370   // DR 550.
00371   inline double
00372   pow(double __x, int __i)
00373   { return __builtin_powi(__x, __i); }
00374 
00375   inline float
00376   pow(float __x, int __n)
00377   { return __builtin_powif(__x, __n); }
00378 
00379   inline long double
00380   pow(long double __x, int __n)
00381   { return __builtin_powil(__x, __n); }
00382 
00383   template<typename _Tp, typename _Up>
00384     inline
00385     typename __gnu_cxx::__promote_2<
00386     typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
00387                     && __is_arithmetic<_Up>::__value,
00388                     _Tp>::__type, _Up>::__type
00389     pow(_Tp __x, _Up __y)
00390     {
00391       typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
00392       return pow(__type(__x), __type(__y));
00393     }
00394 
00395   using ::sin;
00396 
00397   inline float
00398   sin(float __x)
00399   { return __builtin_sinf(__x); }
00400 
00401   inline long double
00402   sin(long double __x)
00403   { return __builtin_sinl(__x); }
00404 
00405   template<typename _Tp>
00406     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00407                        double>::__type
00408     sin(_Tp __x)
00409     { return __builtin_sin(__x); }
00410 
00411   using ::sinh;
00412 
00413   inline float
00414   sinh(float __x)
00415   { return __builtin_sinhf(__x); }
00416 
00417   inline long double
00418   sinh(long double __x)
00419   { return __builtin_sinhl(__x); }
00420 
00421   template<typename _Tp>
00422     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00423                        double>::__type
00424     sinh(_Tp __x)
00425     { return __builtin_sinh(__x); }
00426 
00427   using ::sqrt;
00428 
00429   inline float
00430   sqrt(float __x)
00431   { return __builtin_sqrtf(__x); }
00432 
00433   inline long double
00434   sqrt(long double __x)
00435   { return __builtin_sqrtl(__x); }
00436 
00437   template<typename _Tp>
00438     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00439                        double>::__type
00440     sqrt(_Tp __x)
00441     { return __builtin_sqrt(__x); }
00442 
00443   using ::tan;
00444 
00445   inline float
00446   tan(float __x)
00447   { return __builtin_tanf(__x); }
00448 
00449   inline long double
00450   tan(long double __x)
00451   { return __builtin_tanl(__x); }
00452 
00453   template<typename _Tp>
00454     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00455                        double>::__type
00456     tan(_Tp __x)
00457     { return __builtin_tan(__x); }
00458 
00459   using ::tanh;
00460 
00461   inline float
00462   tanh(float __x)
00463   { return __builtin_tanhf(__x); }
00464 
00465   inline long double
00466   tanh(long double __x)
00467   { return __builtin_tanhl(__x); }
00468 
00469   template<typename _Tp>
00470     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
00471                        double>::__type
00472     tanh(_Tp __x)
00473     { return __builtin_tanh(__x); }
00474 
00475 _GLIBCXX_END_NAMESPACE
00476 
00477 #if _GLIBCXX_USE_C99_MATH
00478 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
00479 // These are possible macros imported from C99-land. For strict
00480 // conformance, remove possible C99-injected names from the global
00481 // namespace, and sequester them in the __gnu_cxx extension namespace.
00482 
00483 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00484 
00485   template<typename _Tp>
00486     inline int
00487     __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
00488 
00489 _GLIBCXX_END_NAMESPACE
00490 
00491 // Only undefine the C99 FP macros, if actually captured for namespace movement
00492 #undef fpclassify
00493 #undef isfinite
00494 #undef isinf
00495 #undef isnan
00496 #undef isnormal
00497 #undef signbit
00498 #undef isgreater
00499 #undef isgreaterequal
00500 #undef isless
00501 #undef islessequal
00502 #undef islessgreater
00503 #undef isunordered
00504 
00505 _GLIBCXX_BEGIN_NAMESPACE(std)
00506 
00507   template<typename _Tp>
00508     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00509                        int>::__type
00510     fpclassify(_Tp __f)
00511     {
00512       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00513       return ::__gnu_cxx::__capture_fpclassify(__type(__f));
00514     }
00515 
00516   template<typename _Tp>
00517     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00518                        int>::__type
00519     isfinite(_Tp __f)
00520     {
00521       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00522       return __builtin_isfinite(__type(__f));
00523     }
00524 
00525   template<typename _Tp>
00526     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00527                        int>::__type
00528     isinf(_Tp __f)
00529     {
00530       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00531       return __builtin_isinf(__type(__f));
00532     }
00533 
00534   template<typename _Tp>
00535     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00536                        int>::__type
00537     isnan(_Tp __f)
00538     {
00539       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00540       return __builtin_isnan(__type(__f));
00541     }
00542 
00543   template<typename _Tp>
00544     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00545                        int>::__type
00546     isnormal(_Tp __f)
00547     {
00548       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00549       return __builtin_isnormal(__type(__f));
00550     }
00551 
00552   template<typename _Tp>
00553     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00554                        int>::__type
00555     signbit(_Tp __f)
00556     {
00557       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00558       return __builtin_signbit(__type(__f));
00559     }
00560 
00561   template<typename _Tp>
00562     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00563                        int>::__type
00564     isgreater(_Tp __f1, _Tp __f2)
00565     {
00566       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00567       return __builtin_isgreater(__type(__f1), __type(__f2));
00568     }
00569 
00570   template<typename _Tp>
00571     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00572                        int>::__type
00573     isgreaterequal(_Tp __f1, _Tp __f2)
00574     {
00575       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00576       return __builtin_isgreaterequal(__type(__f1), __type(__f2));
00577     }
00578 
00579   template<typename _Tp>
00580     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00581                        int>::__type
00582     isless(_Tp __f1, _Tp __f2)
00583     {
00584       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00585       return __builtin_isless(__type(__f1), __type(__f2));
00586     }
00587 
00588   template<typename _Tp>
00589     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00590                        int>::__type
00591     islessequal(_Tp __f1, _Tp __f2)
00592     {
00593       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00594       return __builtin_islessequal(__type(__f1), __type(__f2));
00595     }
00596 
00597   template<typename _Tp>
00598     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00599                        int>::__type
00600     islessgreater(_Tp __f1, _Tp __f2)
00601     {
00602       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00603       return __builtin_islessgreater(__type(__f1), __type(__f2));
00604     }
00605 
00606   template<typename _Tp>
00607     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
00608                        int>::__type
00609     isunordered(_Tp __f1, _Tp __f2)
00610     {
00611       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
00612       return __builtin_isunordered(__type(__f1), __type(__f2));
00613     }
00614 
00615 _GLIBCXX_END_NAMESPACE
00616 
00617 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
00618 #endif
00619 
00620 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00621 # include <bits/cmath.tcc>
00622 #endif
00623 
00624 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00625 #  if defined(_GLIBCXX_INCLUDE_AS_TR1)
00626 #    error C++0x header cannot be included from TR1 header
00627 #  endif
00628 #  if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
00629 #    include <tr1_impl/cmath>
00630 #  else
00631 #    define _GLIBCXX_INCLUDE_AS_CXX0X
00632 #    define _GLIBCXX_BEGIN_NAMESPACE_TR1
00633 #    define _GLIBCXX_END_NAMESPACE_TR1
00634 #    define _GLIBCXX_TR1
00635 #    include <tr1_impl/cmath>
00636 #    undef _GLIBCXX_TR1
00637 #    undef _GLIBCXX_END_NAMESPACE_TR1
00638 #    undef _GLIBCXX_BEGIN_NAMESPACE_TR1
00639 #    undef _GLIBCXX_INCLUDE_AS_CXX0X
00640 #  endif
00641 #endif
00642 
00643 #endif

Generated on Wed Mar 26 00:42:55 2008 for libstdc++ by  doxygen 1.5.1