cmath

Go to the documentation of this file.
00001 // -*- C++ -*- C forwarding header.
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 //
00032 // ISO C++ 14882: 26.5  C library
00033 //
00034 
00044 #ifndef _CPP_CMATH
00045 #define _CPP_CMATH 1
00046 
00047 #pragma GCC system_header
00048 
00049 #include <bits/c++config.h>
00050 
00051 #include <math.h>
00052 
00053 // Get rid of those macros defined in <math.h> in lieu of real functions.
00054 #undef abs
00055 #undef div
00056 #undef acos
00057 #undef asin
00058 #undef atan
00059 #undef atan2
00060 #undef ceil
00061 #undef cos
00062 #undef cosh
00063 #undef exp
00064 #undef fabs
00065 #undef floor
00066 #undef fmod
00067 #undef frexp
00068 #undef ldexp
00069 #undef log
00070 #undef log10
00071 #undef modf
00072 #undef pow
00073 #undef sin
00074 #undef sinh
00075 #undef sqrt
00076 #undef tan
00077 #undef tanh
00078 
00079 namespace std 
00080 {
00081   // Forward declaration of a helper function.  This really should be
00082   // an `exported' forward declaration.
00083   template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
00084 
00085   template<typename _Tp>
00086   inline _Tp
00087     __cmath_abs(_Tp __x)
00088     {
00089       return __x < _Tp() ? -__x : __x;
00090     }
00091 
00092   inline double
00093   abs(double __x)
00094   { return __builtin_fabs(__x); }
00095 
00096   inline float
00097   abs(float __x)
00098   { return __builtin_fabsf(__x); }
00099 
00100   inline long double
00101   abs(long double __x)
00102   { return __builtin_fabsl(__x); }
00103 
00104 #if _GLIBCPP_HAVE_ACOSF
00105   inline float 
00106   acos(float __x) { return ::acosf(__x); }
00107 #else
00108   inline float 
00109   acos(float __x) { return ::acos(static_cast<double>(__x)); }
00110 #endif
00111 
00112   using ::acos;
00113   
00114 #if _GLIBCPP_HAVE_ACOSL
00115   inline long double 
00116   acos(long double __x) { return ::acosl(__x); }
00117 #else
00118   inline long double 
00119   acos(long double __x) { return ::acos(static_cast<double>(__x)); }
00120 #endif
00121 
00122   using ::asin;
00123 
00124 #if _GLIBCPP_HAVE_ASINF
00125   inline float 
00126   asin(float __x) { return ::asinf(__x); }
00127 #else
00128   inline float 
00129   asin(float __x) { return ::asin(static_cast<double>(__x)); }
00130 #endif
00131 
00132 #if _GLIBCPP_HAVE_ASINL
00133   inline long double 
00134   asin(long double __x) { return ::asinl(__x); }
00135 #else
00136   inline long double 
00137   asin(long double __x) { return ::asin(static_cast<double>(__x)); }
00138 #endif
00139 
00140   using ::atan;
00141 
00142 #if _GLIBCPP_HAVE_ATANF
00143   inline float 
00144   atan(float __x) { return ::atanf(__x); }
00145 #else
00146   inline float 
00147   atan(float __x) { return ::atan(static_cast<double>(__x)); }
00148 #endif
00149 
00150 #if _GLIBCPP_HAVE_ATANL
00151   inline long double 
00152   atan(long double __x) { return ::atanl(__x); }
00153 #else
00154   inline long double 
00155   atan(long double __x) { return ::atan(static_cast<double>(__x)); }
00156 #endif
00157 
00158   using ::atan2;
00159 
00160 #if _GLIBCPP_HAVE_ATAN2F
00161   inline float 
00162   atan2(float __y, float __x) { return ::atan2f(__y, __x); }
00163 #else
00164   inline float 
00165   atan2(float __y, float __x)
00166   { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
00167 #endif
00168 
00169 #if _GLIBCPP_HAVE_ATAN2L
00170   inline long double 
00171   atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
00172 #else
00173   inline long double 
00174   atan2(long double __y, long double __x) 
00175   { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
00176 #endif
00177 
00178   using ::ceil;
00179 
00180 #if _GLIBCPP_HAVE_CEILF
00181   inline float 
00182   ceil(float __x) { return ::ceilf(__x); }
00183 #else
00184   inline float 
00185   ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
00186 #endif
00187 
00188 #if _GLIBCPP_HAVE_CEILL
00189   inline long double 
00190   ceil(long double __x) { return ::ceill(__x); }
00191 #else
00192   inline long double 
00193   ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
00194 #endif
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   using ::cosh;
00207 
00208 #if _GLIBCPP_HAVE_COSHF
00209   inline float 
00210   cosh(float __x) { return ::coshf(__x); }
00211 #else
00212   inline float 
00213   cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
00214 #endif
00215 
00216 #if _GLIBCPP_HAVE_COSHL
00217   inline long double 
00218   cosh(long double __x) { return ::coshl(__x); }
00219 #else
00220   inline long double 
00221   cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
00222 #endif
00223 
00224   using ::exp;
00225 
00226 #if _GLIBCPP_HAVE_EXPF
00227   inline float 
00228   exp(float __x) { return ::expf(__x); }
00229 #else
00230   inline float 
00231   exp(float __x) { return ::exp(static_cast<double>(__x)); }
00232 #endif
00233 
00234 #if _GLIBCPP_HAVE_EXPL
00235   inline long double 
00236   exp(long double __x) { return ::expl(__x); }
00237 #else
00238   inline long double 
00239   exp(long double __x) { return ::exp(static_cast<double>(__x)); }
00240 #endif
00241 
00242   using ::fabs;
00243 
00244   inline float
00245   fabs(float __x)
00246   { return __builtin_fabsf(__x); }
00247 
00248   inline long double
00249   fabs(long double __x)
00250   { return __builtin_fabsl(__x); }
00251 
00252   using ::floor;
00253 
00254 #if _GLIBCPP_HAVE_FLOORF
00255   inline float 
00256   floor(float __x) { return ::floorf(__x); }
00257 #else
00258   inline float 
00259   floor(float __x) { return ::floor(static_cast<double>(__x)); }
00260 #endif
00261 
00262 #if _GLIBCPP_HAVE_FLOORL
00263   inline long double 
00264   floor(long double __x) { return ::floorl(__x); }
00265 #else
00266   inline long double 
00267   floor(long double __x) { return ::floor(static_cast<double>(__x)); }
00268 #endif
00269 
00270   using ::fmod;
00271 
00272 #if _GLIBCPP_HAVE_FMODF
00273   inline float 
00274   fmod(float __x, float __y) { return ::fmodf(__x, __y); }
00275 #else
00276   inline float 
00277   fmod(float __x, float __y)
00278   { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
00279 #endif
00280 
00281 #if _GLIBCPP_HAVE_FMODL
00282   inline long double 
00283   fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
00284 #else
00285   inline long double 
00286   fmod(long double __x, long double __y) 
00287   { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
00288 #endif
00289 
00290   using ::frexp;
00291 
00292 #if _GLIBCPP_HAVE_FREXPF
00293   inline float 
00294   frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
00295 #else
00296   inline float 
00297   frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
00298 #endif
00299 
00300 #if _GLIBCPP_HAVE_FREXPL
00301   inline long double 
00302   frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
00303 #else
00304   inline long double 
00305   frexp(long double __x, int* __exp) 
00306   { return ::frexp(static_cast<double>(__x), __exp); }
00307 #endif
00308 
00309   using ::ldexp;
00310 
00311 #if _GLIBCPP_HAVE_LDEXPF
00312   inline float 
00313   ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
00314 #else
00315   inline float 
00316   ldexp(float __x, int __exp)
00317   { return ::ldexp(static_cast<double>(__x), __exp); }
00318 #endif
00319 
00320 #if _GLIBCPP_HAVE_LDEXPL
00321   inline long double 
00322   ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
00323 #else
00324   inline long double 
00325   ldexp(long double __x, int __exp) 
00326   { return ::ldexp(static_cast<double>(__x), __exp); }
00327 #endif
00328 
00329   using ::log;
00330 
00331 #if _GLIBCPP_HAVE_LOGF
00332   inline float 
00333   log(float __x) { return ::logf(__x); }
00334 #else
00335   inline float log(float __x)
00336   { return ::log(static_cast<double>(__x)); }
00337 #endif
00338 
00339 #if _GLIBCPP_HAVE_LOGL
00340   inline long double 
00341   log(long double __x) { return ::logl(__x); }
00342 #else
00343   inline long double 
00344   log(long double __x) { return ::log(static_cast<double>(__x)); }
00345 #endif
00346 
00347   using ::log10;
00348 
00349 #if _GLIBCPP_HAVE_LOG10F
00350   inline float 
00351   log10(float __x) { return ::log10f(__x); }
00352 #else
00353   inline float 
00354   log10(float __x) { return ::log10(static_cast<double>(__x)); }
00355 #endif
00356 
00357 #if _GLIBCPP_HAVE_LOG10L
00358   inline long double 
00359   log10(long double __x) { return ::log10l(__x); }
00360 #else
00361   inline long double 
00362   log10(long double __x) { return ::log10(static_cast<double>(__x)); }
00363 #endif
00364 
00365   using ::modf;
00366 
00367 #if _GLIBCPP_HAVE_MODFF
00368   inline float 
00369   modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
00370 #else
00371   inline float 
00372   modf(float __x, float* __iptr)
00373   {
00374     double __tmp;
00375     double __res = ::modf(static_cast<double>(__x), &__tmp);
00376     *__iptr = static_cast<float>(__tmp);
00377     return __res;
00378   }
00379 #endif
00380 
00381 #if _GLIBCPP_HAVE_MODFL
00382   inline long double 
00383   modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
00384 #else
00385   inline long double 
00386   modf(long double __x, long double* __iptr) 
00387   { 
00388     double __tmp;
00389     double __res = ::modf(static_cast<double>(__x), &__tmp);
00390     * __iptr = static_cast<long double>(__tmp);
00391     return __res;
00392   }
00393 #endif
00394 
00395   template<typename _Tp>
00396     inline _Tp
00397     __pow_helper(_Tp __x, int __n)
00398     {
00399       return __n < 0
00400         ? _Tp(1)/__cmath_power(__x, -__n)
00401         : __cmath_power(__x, __n);
00402     }
00403 
00404   using ::pow;
00405 
00406 #if _GLIBCPP_HAVE_POWF
00407   inline float 
00408   pow(float __x, float __y) { return ::powf(__x, __y); }
00409 #else
00410   inline float 
00411   pow(float __x, float __y)
00412   { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
00413 #endif
00414 
00415 #if _GLIBCPP_HAVE_POWL
00416   inline long double 
00417   pow(long double __x, long double __y) { return ::powl(__x, __y); }
00418 #else
00419   inline long double 
00420   pow(long double __x, long double __y) 
00421   { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
00422 #endif
00423 
00424   inline double 
00425   pow(double __x, int __i)
00426   { return __pow_helper(__x, __i); }
00427 
00428   inline float 
00429   pow(float __x, int __n)
00430   { return __pow_helper(__x, __n); }
00431 
00432   inline long double 
00433   pow(long double __x, int __n)
00434   { return __pow_helper(__x, __n); }
00435 
00436   using ::sin;
00437 
00438   inline float
00439   sin(float __x)
00440   { return __builtin_sinf(__x); }
00441 
00442   inline long double
00443   sin(long double __x)
00444   { return __builtin_sinl(__x); }
00445 
00446   using ::sinh;
00447 
00448 #if _GLIBCPP_HAVE_SINHF
00449   inline float 
00450   sinh(float __x) { return ::sinhf(__x); }
00451 #else
00452   inline float 
00453   sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
00454 #endif
00455 
00456 #if _GLIBCPP_HAVE_SINHL
00457   inline long double 
00458   sinh(long double __x) { return ::sinhl(__x); }
00459 #else
00460   inline long double 
00461   sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
00462 #endif
00463 
00464   using ::sqrt;
00465 
00466   inline float
00467   sqrt(float __x)
00468   { return __builtin_sqrtf(__x); }
00469 
00470   inline long double
00471   sqrt(long double __x)
00472   { return __builtin_sqrtl(__x); }
00473 
00474   using ::tan;
00475 
00476 #if _GLIBCPP_HAVE_TANF
00477   inline float 
00478   tan(float __x) { return ::tanf(__x); }
00479 #else
00480   inline float 
00481   tan(float __x) { return ::tan(static_cast<double>(__x)); }
00482 #endif
00483 
00484 #if _GLIBCPP_HAVE_TANL
00485   inline long double 
00486   tan(long double __x) { return ::tanl(__x); }
00487 #else
00488   inline long double 
00489   tan(long double __x) { return ::tan(static_cast<double>(__x)); }
00490 #endif
00491 
00492   using ::tanh;
00493 
00494 #if _GLIBCPP_HAVE_TANHF
00495   inline float 
00496   tanh(float __x) { return ::tanhf(__x); }
00497 #else
00498   inline float 
00499   tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
00500 #endif
00501 
00502 #if _GLIBCPP_HAVE_TANHL
00503   inline long double 
00504   tanh(long double __x) { return ::tanhl(__x); }
00505 #else
00506   inline long double 
00507   tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
00508 #endif
00509 } 
00510 
00511 
00512 #if _GLIBCPP_USE_C99
00513 // These are possible macros imported from C99-land. For strict
00514 // conformance, remove possible C99-injected names from the global
00515 // namespace, and sequester them in the __gnu_cxx extension namespace. 
00516 namespace __gnu_cxx
00517 {
00518   template<typename _Tp>
00519     int 
00520     __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
00521 
00522   template<typename _Tp>
00523     int 
00524     __capture_isfinite(_Tp __f) { return isfinite(__f); }
00525 
00526   template<typename _Tp>
00527     int 
00528     __capture_isinf(_Tp __f) { return isinf(__f); }
00529 
00530   template<typename _Tp>
00531     int 
00532     __capture_isnan(_Tp __f) { return isnan(__f); }
00533 
00534   template<typename _Tp>
00535     int 
00536     __capture_isnormal(_Tp __f) { return isnormal(__f); }
00537 
00538   template<typename _Tp>
00539     int 
00540     __capture_signbit(_Tp __f) { return signbit(__f); }
00541 
00542   template<typename _Tp>
00543     int 
00544     __capture_isgreater(_Tp __f1, _Tp __f2)
00545     { return isgreater(__f1, __f2); }
00546 
00547   template<typename _Tp>
00548      int 
00549      __capture_isgreaterequal(_Tp __f1, _Tp __f2) 
00550      { return isgreaterequal(__f1, __f2); }
00551 
00552   template<typename _Tp>
00553      int 
00554      __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
00555 
00556   template<typename _Tp>
00557      int 
00558      __capture_islessequal(_Tp __f1, _Tp __f2) 
00559      { return islessequal(__f1, __f2); }
00560 
00561   template<typename _Tp>
00562      int 
00563      __capture_islessgreater(_Tp __f1, _Tp __f2) 
00564      { return islessgreater(__f1, __f2); }
00565 
00566   template<typename _Tp>
00567      int 
00568      __capture_isunordered(_Tp __f1, _Tp __f2) 
00569      { return isunordered(__f1, __f2); }
00570 } 
00571 #endif
00572 
00573 #undef fpclassify
00574 #undef isfinite
00575 #undef isinf
00576 #undef isnan
00577 #undef isnormal
00578 #undef signbit
00579 #undef isgreater
00580 #undef isgreaterequal
00581 #undef isless
00582 #undef islessequal
00583 #undef islessgreater
00584 #undef isunordered
00585 
00586 #if _GLIBCPP_USE_C99
00587 namespace __gnu_cxx
00588 {
00589   template<typename _Tp>
00590     int
00591     fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
00592 
00593   template<typename _Tp>
00594     int
00595     isfinite(_Tp __f) { return __capture_isfinite(__f); }
00596 
00597   template<typename _Tp>
00598     int 
00599     isinf(_Tp __f) { return __capture_isinf(__f); }
00600 
00601   template<typename _Tp>
00602     int 
00603     isnan(_Tp __f) { return __capture_isnan(__f); }
00604 
00605   template<typename _Tp>
00606     int 
00607     isnormal(_Tp __f) { return __capture_isnormal(__f); }
00608 
00609   template<typename _Tp>
00610     int 
00611     signbit(_Tp __f) { return __capture_signbit(__f); }
00612 
00613   template<typename _Tp>
00614     int 
00615     isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
00616 
00617   template<typename _Tp>
00618     int 
00619     isgreaterequal(_Tp __f1, _Tp __f2) 
00620     { return __capture_isgreaterequal(__f1, __f2); }
00621 
00622   template<typename _Tp>
00623     int 
00624     isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
00625 
00626   template<typename _Tp>
00627     int 
00628     islessequal(_Tp __f1, _Tp __f2) 
00629     { return __capture_islessequal(__f1, __f2); }
00630 
00631   template<typename _Tp>
00632     int 
00633     islessgreater(_Tp __f1, _Tp __f2) 
00634     { return __capture_islessgreater(__f1, __f2); }
00635 
00636   template<typename _Tp>
00637     int 
00638     isunordered(_Tp __f1, _Tp __f2) 
00639     { return __capture_isunordered(__f1, __f2); }
00640 }
00641 
00642 namespace std
00643 {
00644   using __gnu_cxx::fpclassify;
00645   using __gnu_cxx::isfinite;
00646   using __gnu_cxx::isinf;
00647   using __gnu_cxx::isnan;
00648   using __gnu_cxx::isnormal;
00649   using __gnu_cxx::signbit;
00650   using __gnu_cxx::isgreater;
00651   using __gnu_cxx::isgreaterequal;
00652   using __gnu_cxx::isless;
00653   using __gnu_cxx::islessequal;
00654   using __gnu_cxx::islessgreater;
00655   using __gnu_cxx::isunordered;
00656 }
00657 #endif
00658   
00659 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00660 #  define export
00661 #  include <bits/cmath.tcc>
00662 #endif
00663 
00664 #endif

Generated on Wed May 1 19:19:30 2002 for libstdc++-v3 Source by doxygen1.2.15