cmath

Go to the documentation of this file.
00001 // -*- C++ -*- C forwarding header. 00002 00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 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 00035 /** @file cmath 00036 * This is a Standard C++ Library file. You should @c #include this file 00037 * in your programs, rather than any of the "*.h" implementation files. 00038 * 00039 * This is the C++ version of the Standard C Library header @c math.h, 00040 * and its contents are (mostly) the same as that header, but are all 00041 * contained in the namespace @c std. 00042 */ 00043 00044 #ifndef _GLIBCXX_CMATH 00045 #define _GLIBCXX_CMATH 1 00046 00047 #pragma GCC system_header 00048 00049 #include <bits/c++config.h> 00050 #include <bits/cpp_type_traits.h> 00051 00052 #include <math.h> 00053 00054 // Get rid of those macros defined in <math.h> in lieu of real functions. 00055 #undef abs 00056 #undef div 00057 #undef acos 00058 #undef asin 00059 #undef atan 00060 #undef atan2 00061 #undef ceil 00062 #undef cos 00063 #undef cosh 00064 #undef exp 00065 #undef fabs 00066 #undef floor 00067 #undef fmod 00068 #undef frexp 00069 #undef ldexp 00070 #undef log 00071 #undef log10 00072 #undef modf 00073 #undef pow 00074 #undef sin 00075 #undef sinh 00076 #undef sqrt 00077 #undef tan 00078 #undef tanh 00079 00080 00081 namespace std 00082 { 00083 // Forward declaration of a helper function. This really should be 00084 // an `exported' forward declaration. 00085 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int); 00086 00087 inline double 00088 abs(double __x) 00089 { return __builtin_fabs(__x); } 00090 00091 inline float 00092 abs(float __x) 00093 { return __builtin_fabsf(__x); } 00094 00095 inline long double 00096 abs(long double __x) 00097 { return __builtin_fabsl(__x); } 00098 00099 using ::acos; 00100 00101 inline float 00102 acos(float __x) 00103 { return __builtin_acosf(__x); } 00104 00105 inline long double 00106 acos(long double __x) 00107 { return __builtin_acosl(__x); } 00108 00109 template<typename _Tp> 00110 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00111 acos(_Tp __x) 00112 { 00113 return __builtin_acos(__x); 00114 } 00115 00116 using ::asin; 00117 00118 inline float 00119 asin(float __x) 00120 { return __builtin_asinf(__x); } 00121 00122 inline long double 00123 asin(long double __x) 00124 { return __builtin_asinl(__x); } 00125 00126 template<typename _Tp> 00127 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00128 asin(_Tp __x) 00129 { return __builtin_asin(__x); } 00130 00131 using ::atan; 00132 00133 inline float 00134 atan(float __x) 00135 { return __builtin_atanf(__x); } 00136 00137 inline long double 00138 atan(long double __x) 00139 { return __builtin_atanl(__x); } 00140 00141 template<typename _Tp> 00142 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00143 atan(_Tp __x) 00144 { return __builtin_atan(__x); } 00145 00146 using ::atan2; 00147 00148 inline float 00149 atan2(float __y, float __x) 00150 { return __builtin_atan2f(__y, __x); } 00151 00152 inline long double 00153 atan2(long double __y, long double __x) 00154 { return __builtin_atan2l(__y, __x); } 00155 00156 template<typename _Tp, typename _Up> 00157 inline typename __enable_if<double, __is_integer<_Tp>::_M_type 00158 && __is_integer<_Up>::_M_type>::_M_type 00159 atan2(_Tp __y, _Up __x) 00160 { return __builtin_atan2(__y, __x); } 00161 00162 using ::ceil; 00163 00164 inline float 00165 ceil(float __x) 00166 { return __builtin_ceilf(__x); } 00167 00168 inline long double 00169 ceil(long double __x) 00170 { return __builtin_ceill(__x); } 00171 00172 template<typename _Tp> 00173 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00174 ceil(_Tp __x) 00175 { return __builtin_ceil(__x); } 00176 00177 using ::cos; 00178 00179 inline float 00180 cos(float __x) 00181 { return __builtin_cosf(__x); } 00182 00183 inline long double 00184 cos(long double __x) 00185 { return __builtin_cosl(__x); } 00186 00187 template<typename _Tp> 00188 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00189 cos(_Tp __x) 00190 { return __builtin_cos(__x); } 00191 00192 using ::cosh; 00193 00194 inline float 00195 cosh(float __x) 00196 { return __builtin_coshf(__x); } 00197 00198 inline long double 00199 cosh(long double __x) 00200 { return __builtin_coshl(__x); } 00201 00202 template<typename _Tp> 00203 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00204 cosh(_Tp __x) 00205 { return __builtin_cosh(__x); } 00206 00207 using ::exp; 00208 00209 inline float 00210 exp(float __x) 00211 { return __builtin_expf(__x); } 00212 00213 inline long double 00214 exp(long double __x) 00215 { return __builtin_expl(__x); } 00216 00217 template<typename _Tp> 00218 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00219 exp(_Tp __x) 00220 { return __builtin_exp(__x); } 00221 00222 using ::fabs; 00223 00224 inline float 00225 fabs(float __x) 00226 { return __builtin_fabsf(__x); } 00227 00228 inline long double 00229 fabs(long double __x) 00230 { return __builtin_fabsl(__x); } 00231 00232 template<typename _Tp> 00233 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00234 fabs(_Tp __x) 00235 { return __builtin_fabs(__x); } 00236 00237 using ::floor; 00238 00239 inline float 00240 floor(float __x) 00241 { return __builtin_floorf(__x); } 00242 00243 inline long double 00244 floor(long double __x) 00245 { return __builtin_floorl(__x); } 00246 00247 template<typename _Tp> 00248 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00249 floor(_Tp __x) 00250 { return __builtin_floor(__x); } 00251 00252 using ::fmod; 00253 00254 inline float 00255 fmod(float __x, float __y) 00256 { return __builtin_fmodf(__x, __y); } 00257 00258 inline long double 00259 fmod(long double __x, long double __y) 00260 { return __builtin_fmodl(__x, __y); } 00261 00262 using ::frexp; 00263 00264 inline float 00265 frexp(float __x, int* __exp) 00266 { return __builtin_frexpf(__x, __exp); } 00267 00268 inline long double 00269 frexp(long double __x, int* __exp) 00270 { return __builtin_frexpl(__x, __exp); } 00271 00272 template<typename _Tp> 00273 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00274 frexp(_Tp __x, int* __exp) 00275 { return __builtin_frexp(__x, __exp); } 00276 00277 using ::ldexp; 00278 00279 inline float 00280 ldexp(float __x, int __exp) 00281 { return __builtin_ldexpf(__x, __exp); } 00282 00283 inline long double 00284 ldexp(long double __x, int __exp) 00285 { return __builtin_ldexpl(__x, __exp); } 00286 00287 template<typename _Tp> 00288 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00289 ldexp(_Tp __x, int __exp) 00290 { return __builtin_ldexp(__x, __exp); } 00291 00292 using ::log; 00293 00294 inline float 00295 log(float __x) 00296 { return __builtin_logf(__x); } 00297 00298 inline long double 00299 log(long double __x) 00300 { return __builtin_logl(__x); } 00301 00302 template<typename _Tp> 00303 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00304 log(_Tp __x) 00305 { return __builtin_log(__x); } 00306 00307 using ::log10; 00308 00309 inline float 00310 log10(float __x) 00311 { return __builtin_log10f(__x); } 00312 00313 inline long double 00314 log10(long double __x) 00315 { return __builtin_log10l(__x); } 00316 00317 template<typename _Tp> 00318 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00319 log10(_Tp __x) 00320 { return __builtin_log10(__x); } 00321 00322 using ::modf; 00323 00324 inline float 00325 modf(float __x, float* __iptr) 00326 { return __builtin_modff(__x, __iptr); } 00327 00328 inline long double 00329 modf(long double __x, long double* __iptr) 00330 { return __builtin_modfl(__x, __iptr); } 00331 00332 template<typename _Tp> 00333 inline _Tp 00334 __pow_helper(_Tp __x, int __n) 00335 { 00336 return __n < 0 00337 ? _Tp(1)/__cmath_power(__x, -__n) 00338 : __cmath_power(__x, __n); 00339 } 00340 00341 using ::pow; 00342 00343 inline float 00344 pow(float __x, float __y) 00345 { return __builtin_powf(__x, __y); } 00346 00347 inline long double 00348 pow(long double __x, long double __y) 00349 { return __builtin_powl(__x, __y); } 00350 00351 inline double 00352 pow(double __x, int __i) 00353 { return __pow_helper(__x, __i); } 00354 00355 inline float 00356 pow(float __x, int __n) 00357 { return __pow_helper(__x, __n); } 00358 00359 inline long double 00360 pow(long double __x, int __n) 00361 { return __pow_helper(__x, __n); } 00362 00363 using ::sin; 00364 00365 inline float 00366 sin(float __x) 00367 { return __builtin_sinf(__x); } 00368 00369 inline long double 00370 sin(long double __x) 00371 { return __builtin_sinl(__x); } 00372 00373 template<typename _Tp> 00374 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00375 sin(_Tp __x) 00376 { return __builtin_sin(__x); } 00377 00378 using ::sinh; 00379 00380 inline float 00381 sinh(float __x) 00382 { return __builtin_sinhf(__x); } 00383 00384 inline long double 00385 sinh(long double __x) 00386 { return __builtin_sinhl(__x); } 00387 00388 template<typename _Tp> 00389 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00390 sinh(_Tp __x) 00391 { return __builtin_sinh(__x); } 00392 00393 using ::sqrt; 00394 00395 inline float 00396 sqrt(float __x) 00397 { return __builtin_sqrtf(__x); } 00398 00399 inline long double 00400 sqrt(long double __x) 00401 { return __builtin_sqrtl(__x); } 00402 00403 template<typename _Tp> 00404 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00405 sqrt(_Tp __x) 00406 { return __builtin_sqrt(__x); } 00407 00408 using ::tan; 00409 00410 inline float 00411 tan(float __x) 00412 { return __builtin_tanf(__x); } 00413 00414 inline long double 00415 tan(long double __x) 00416 { return __builtin_tanl(__x); } 00417 00418 template<typename _Tp> 00419 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00420 tan(_Tp __x) 00421 { return __builtin_tan(__x); } 00422 00423 using ::tanh; 00424 00425 inline float 00426 tanh(float __x) 00427 { return __builtin_tanhf(__x); } 00428 00429 inline long double 00430 tanh(long double __x) 00431 { return __builtin_tanhl(__x); } 00432 00433 template<typename _Tp> 00434 inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type 00435 tanh(_Tp __x) 00436 { return __builtin_tanh(__x); } 00437 } 00438 00439 #if _GLIBCXX_USE_C99_MATH 00440 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 00441 // These are possible macros imported from C99-land. For strict 00442 // conformance, remove possible C99-injected names from the global 00443 // namespace, and sequester them in the __gnu_cxx extension namespace. 00444 namespace __gnu_cxx 00445 { 00446 template<typename _Tp> 00447 int 00448 __capture_fpclassify(_Tp __f) { return fpclassify(__f); } 00449 00450 template<typename _Tp> 00451 int 00452 __capture_isfinite(_Tp __f) { return isfinite(__f); } 00453 00454 template<typename _Tp> 00455 int 00456 __capture_isinf(_Tp __f) { return isinf(__f); } 00457 00458 template<typename _Tp> 00459 int 00460 __capture_isnan(_Tp __f) { return isnan(__f); } 00461 00462 template<typename _Tp> 00463 int 00464 __capture_isnormal(_Tp __f) { return isnormal(__f); } 00465 00466 template<typename _Tp> 00467 int 00468 __capture_signbit(_Tp __f) { return signbit(__f); } 00469 00470 template<typename _Tp> 00471 int 00472 __capture_isgreater(_Tp __f1, _Tp __f2) 00473 { return isgreater(__f1, __f2); } 00474 00475 template<typename _Tp> 00476 int 00477 __capture_isgreaterequal(_Tp __f1, _Tp __f2) 00478 { return isgreaterequal(__f1, __f2); } 00479 00480 template<typename _Tp> 00481 int 00482 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); } 00483 00484 template<typename _Tp> 00485 int 00486 __capture_islessequal(_Tp __f1, _Tp __f2) 00487 { return islessequal(__f1, __f2); } 00488 00489 template<typename _Tp> 00490 int 00491 __capture_islessgreater(_Tp __f1, _Tp __f2) 00492 { return islessgreater(__f1, __f2); } 00493 00494 template<typename _Tp> 00495 int 00496 __capture_isunordered(_Tp __f1, _Tp __f2) 00497 { return isunordered(__f1, __f2); } 00498 } 00499 00500 // Only undefine the C99 FP macros, if actually captured for namespace movement 00501 #undef fpclassify 00502 #undef isfinite 00503 #undef isinf 00504 #undef isnan 00505 #undef isnormal 00506 #undef signbit 00507 #undef isgreater 00508 #undef isgreaterequal 00509 #undef isless 00510 #undef islessequal 00511 #undef islessgreater 00512 #undef isunordered 00513 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */ 00514 #endif 00515 00516 #if _GLIBCXX_USE_C99_MATH 00517 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 00518 namespace __gnu_cxx 00519 { 00520 template<typename _Tp> 00521 int 00522 fpclassify(_Tp __f) { return __capture_fpclassify(__f); } 00523 00524 template<typename _Tp> 00525 int 00526 isfinite(_Tp __f) { return __capture_isfinite(__f); } 00527 00528 template<typename _Tp> 00529 int 00530 isinf(_Tp __f) { return __capture_isinf(__f); } 00531 00532 template<typename _Tp> 00533 int 00534 isnan(_Tp __f) { return __capture_isnan(__f); } 00535 00536 template<typename _Tp> 00537 int 00538 isnormal(_Tp __f) { return __capture_isnormal(__f); } 00539 00540 template<typename _Tp> 00541 int 00542 signbit(_Tp __f) { return __capture_signbit(__f); } 00543 00544 template<typename _Tp> 00545 int 00546 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); } 00547 00548 template<typename _Tp> 00549 int 00550 isgreaterequal(_Tp __f1, _Tp __f2) 00551 { return __capture_isgreaterequal(__f1, __f2); } 00552 00553 template<typename _Tp> 00554 int 00555 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); } 00556 00557 template<typename _Tp> 00558 int 00559 islessequal(_Tp __f1, _Tp __f2) 00560 { return __capture_islessequal(__f1, __f2); } 00561 00562 template<typename _Tp> 00563 int 00564 islessgreater(_Tp __f1, _Tp __f2) 00565 { return __capture_islessgreater(__f1, __f2); } 00566 00567 template<typename _Tp> 00568 int 00569 isunordered(_Tp __f1, _Tp __f2) 00570 { return __capture_isunordered(__f1, __f2); } 00571 } 00572 00573 namespace std 00574 { 00575 using __gnu_cxx::fpclassify; 00576 using __gnu_cxx::isfinite; 00577 using __gnu_cxx::isinf; 00578 using __gnu_cxx::isnan; 00579 using __gnu_cxx::isnormal; 00580 using __gnu_cxx::signbit; 00581 using __gnu_cxx::isgreater; 00582 using __gnu_cxx::isgreaterequal; 00583 using __gnu_cxx::isless; 00584 using __gnu_cxx::islessequal; 00585 using __gnu_cxx::islessgreater; 00586 using __gnu_cxx::isunordered; 00587 } 00588 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */ 00589 #endif 00590 00591 #ifndef _GLIBCXX_EXPORT_TEMPLATE 00592 # include <bits/cmath.tcc> 00593 #endif 00594 00595 #endif

Generated on Wed Jun 9 11:18:16 2004 for libstdc++-v3 Source by doxygen 1.3.7