00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
00082
00083 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
00084
00085 inline double
00086 abs(double __x)
00087 { return __builtin_fabs(__x); }
00088
00089 inline float
00090 abs(float __x)
00091 { return __builtin_fabsf(__x); }
00092
00093 inline long double
00094 abs(long double __x)
00095 { return __builtin_fabsl(__x); }
00096
00097 #if _GLIBCPP_HAVE_ACOSF
00098 inline float
00099 acos(float __x) { return ::acosf(__x); }
00100 #else
00101 inline float
00102 acos(float __x) { return ::acos(static_cast<double>(__x)); }
00103 #endif
00104
00105 using ::acos;
00106
00107 #if _GLIBCPP_HAVE_ACOSL
00108 inline long double
00109 acos(long double __x) { return ::acosl(__x); }
00110 #else
00111 inline long double
00112 acos(long double __x) { return ::acos(static_cast<double>(__x)); }
00113 #endif
00114
00115 using ::asin;
00116
00117 #if _GLIBCPP_HAVE_ASINF
00118 inline float
00119 asin(float __x) { return ::asinf(__x); }
00120 #else
00121 inline float
00122 asin(float __x) { return ::asin(static_cast<double>(__x)); }
00123 #endif
00124
00125 #if _GLIBCPP_HAVE_ASINL
00126 inline long double
00127 asin(long double __x) { return ::asinl(__x); }
00128 #else
00129 inline long double
00130 asin(long double __x) { return ::asin(static_cast<double>(__x)); }
00131 #endif
00132
00133 using ::atan;
00134
00135 #if _GLIBCPP_HAVE_ATANF
00136 inline float
00137 atan(float __x) { return ::atanf(__x); }
00138 #else
00139 inline float
00140 atan(float __x) { return ::atan(static_cast<double>(__x)); }
00141 #endif
00142
00143 #if _GLIBCPP_HAVE_ATANL
00144 inline long double
00145 atan(long double __x) { return ::atanl(__x); }
00146 #else
00147 inline long double
00148 atan(long double __x) { return ::atan(static_cast<double>(__x)); }
00149 #endif
00150
00151 using ::atan2;
00152
00153 #if _GLIBCPP_HAVE_ATAN2F
00154 inline float
00155 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
00156 #else
00157 inline float
00158 atan2(float __y, float __x)
00159 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
00160 #endif
00161
00162 #if _GLIBCPP_HAVE_ATAN2L
00163 inline long double
00164 atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
00165 #else
00166 inline long double
00167 atan2(long double __y, long double __x)
00168 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
00169 #endif
00170
00171 using ::ceil;
00172
00173 #if _GLIBCPP_HAVE_CEILF
00174 inline float
00175 ceil(float __x) { return ::ceilf(__x); }
00176 #else
00177 inline float
00178 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
00179 #endif
00180
00181 #if _GLIBCPP_HAVE_CEILL
00182 inline long double
00183 ceil(long double __x) { return ::ceill(__x); }
00184 #else
00185 inline long double
00186 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
00187 #endif
00188
00189 using ::cos;
00190
00191 inline float
00192 cos(float __x)
00193 { return __builtin_cosf(__x); }
00194
00195 inline long double
00196 cos(long double __x)
00197 { return __builtin_cosl(__x); }
00198
00199 using ::cosh;
00200
00201 #if _GLIBCPP_HAVE_COSHF
00202 inline float
00203 cosh(float __x) { return ::coshf(__x); }
00204 #else
00205 inline float
00206 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
00207 #endif
00208
00209 #if _GLIBCPP_HAVE_COSHL
00210 inline long double
00211 cosh(long double __x) { return ::coshl(__x); }
00212 #else
00213 inline long double
00214 cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
00215 #endif
00216
00217 using ::exp;
00218
00219 #if _GLIBCPP_HAVE_EXPF
00220 inline float
00221 exp(float __x) { return ::expf(__x); }
00222 #else
00223 inline float
00224 exp(float __x) { return ::exp(static_cast<double>(__x)); }
00225 #endif
00226
00227 #if _GLIBCPP_HAVE_EXPL
00228 inline long double
00229 exp(long double __x) { return ::expl(__x); }
00230 #else
00231 inline long double
00232 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
00233 #endif
00234
00235 using ::fabs;
00236
00237 inline float
00238 fabs(float __x)
00239 { return __builtin_fabsf(__x); }
00240
00241 inline long double
00242 fabs(long double __x)
00243 { return __builtin_fabsl(__x); }
00244
00245 using ::floor;
00246
00247 #if _GLIBCPP_HAVE_FLOORF
00248 inline float
00249 floor(float __x) { return ::floorf(__x); }
00250 #else
00251 inline float
00252 floor(float __x) { return ::floor(static_cast<double>(__x)); }
00253 #endif
00254
00255 #if _GLIBCPP_HAVE_FLOORL
00256 inline long double
00257 floor(long double __x) { return ::floorl(__x); }
00258 #else
00259 inline long double
00260 floor(long double __x) { return ::floor(static_cast<double>(__x)); }
00261 #endif
00262
00263 using ::fmod;
00264
00265 #if _GLIBCPP_HAVE_FMODF
00266 inline float
00267 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
00268 #else
00269 inline float
00270 fmod(float __x, float __y)
00271 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
00272 #endif
00273
00274 #if _GLIBCPP_HAVE_FMODL
00275 inline long double
00276 fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
00277 #else
00278 inline long double
00279 fmod(long double __x, long double __y)
00280 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
00281 #endif
00282
00283 using ::frexp;
00284
00285 #if _GLIBCPP_HAVE_FREXPF
00286 inline float
00287 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
00288 #else
00289 inline float
00290 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
00291 #endif
00292
00293 #if _GLIBCPP_HAVE_FREXPL
00294 inline long double
00295 frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
00296 #else
00297 inline long double
00298 frexp(long double __x, int* __exp)
00299 { return ::frexp(static_cast<double>(__x), __exp); }
00300 #endif
00301
00302 using ::ldexp;
00303
00304 #if _GLIBCPP_HAVE_LDEXPF
00305 inline float
00306 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
00307 #else
00308 inline float
00309 ldexp(float __x, int __exp)
00310 { return ::ldexp(static_cast<double>(__x), __exp); }
00311 #endif
00312
00313 #if _GLIBCPP_HAVE_LDEXPL
00314 inline long double
00315 ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
00316 #else
00317 inline long double
00318 ldexp(long double __x, int __exp)
00319 { return ::ldexp(static_cast<double>(__x), __exp); }
00320 #endif
00321
00322 using ::log;
00323
00324 #if _GLIBCPP_HAVE_LOGF
00325 inline float
00326 log(float __x) { return ::logf(__x); }
00327 #else
00328 inline float log(float __x)
00329 { return ::log(static_cast<double>(__x)); }
00330 #endif
00331
00332 #if _GLIBCPP_HAVE_LOGL
00333 inline long double
00334 log(long double __x) { return ::logl(__x); }
00335 #else
00336 inline long double
00337 log(long double __x) { return ::log(static_cast<double>(__x)); }
00338 #endif
00339
00340 using ::log10;
00341
00342 #if _GLIBCPP_HAVE_LOG10F
00343 inline float
00344 log10(float __x) { return ::log10f(__x); }
00345 #else
00346 inline float
00347 log10(float __x) { return ::log10(static_cast<double>(__x)); }
00348 #endif
00349
00350 #if _GLIBCPP_HAVE_LOG10L
00351 inline long double
00352 log10(long double __x) { return ::log10l(__x); }
00353 #else
00354 inline long double
00355 log10(long double __x) { return ::log10(static_cast<double>(__x)); }
00356 #endif
00357
00358 using ::modf;
00359
00360 #if _GLIBCPP_HAVE_MODFF
00361 inline float
00362 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
00363 #else
00364 inline float
00365 modf(float __x, float* __iptr)
00366 {
00367 double __tmp;
00368 double __res = ::modf(static_cast<double>(__x), &__tmp);
00369 *__iptr = static_cast<float>(__tmp);
00370 return __res;
00371 }
00372 #endif
00373
00374 #if _GLIBCPP_HAVE_MODFL
00375 inline long double
00376 modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
00377 #else
00378 inline long double
00379 modf(long double __x, long double* __iptr)
00380 {
00381 double __tmp;
00382 double __res = ::modf(static_cast<double>(__x), &__tmp);
00383 * __iptr = static_cast<long double>(__tmp);
00384 return __res;
00385 }
00386 #endif
00387
00388 template<typename _Tp>
00389 inline _Tp
00390 __pow_helper(_Tp __x, int __n)
00391 {
00392 return __n < 0
00393 ? _Tp(1)/__cmath_power(__x, -__n)
00394 : __cmath_power(__x, __n);
00395 }
00396
00397 using ::pow;
00398
00399 #if _GLIBCPP_HAVE_POWF
00400 inline float
00401 pow(float __x, float __y) { return ::powf(__x, __y); }
00402 #else
00403 inline float
00404 pow(float __x, float __y)
00405 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
00406 #endif
00407
00408 #if _GLIBCPP_HAVE_POWL
00409 inline long double
00410 pow(long double __x, long double __y) { return ::powl(__x, __y); }
00411 #else
00412 inline long double
00413 pow(long double __x, long double __y)
00414 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
00415 #endif
00416
00417 inline double
00418 pow(double __x, int __i)
00419 { return __pow_helper(__x, __i); }
00420
00421 inline float
00422 pow(float __x, int __n)
00423 { return __pow_helper(__x, __n); }
00424
00425 inline long double
00426 pow(long double __x, int __n)
00427 { return __pow_helper(__x, __n); }
00428
00429 using ::sin;
00430
00431 inline float
00432 sin(float __x)
00433 { return __builtin_sinf(__x); }
00434
00435 inline long double
00436 sin(long double __x)
00437 { return __builtin_sinl(__x); }
00438
00439 using ::sinh;
00440
00441 #if _GLIBCPP_HAVE_SINHF
00442 inline float
00443 sinh(float __x) { return ::sinhf(__x); }
00444 #else
00445 inline float
00446 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
00447 #endif
00448
00449 #if _GLIBCPP_HAVE_SINHL
00450 inline long double
00451 sinh(long double __x) { return ::sinhl(__x); }
00452 #else
00453 inline long double
00454 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
00455 #endif
00456
00457 using ::sqrt;
00458
00459 inline float
00460 sqrt(float __x)
00461 { return __builtin_sqrtf(__x); }
00462
00463 inline long double
00464 sqrt(long double __x)
00465 { return __builtin_sqrtl(__x); }
00466
00467 using ::tan;
00468
00469 #if _GLIBCPP_HAVE_TANF
00470 inline float
00471 tan(float __x) { return ::tanf(__x); }
00472 #else
00473 inline float
00474 tan(float __x) { return ::tan(static_cast<double>(__x)); }
00475 #endif
00476
00477 #if _GLIBCPP_HAVE_TANL
00478 inline long double
00479 tan(long double __x) { return ::tanl(__x); }
00480 #else
00481 inline long double
00482 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
00483 #endif
00484
00485 using ::tanh;
00486
00487 #if _GLIBCPP_HAVE_TANHF
00488 inline float
00489 tanh(float __x) { return ::tanhf(__x); }
00490 #else
00491 inline float
00492 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
00493 #endif
00494
00495 #if _GLIBCPP_HAVE_TANHL
00496 inline long double
00497 tanh(long double __x) { return ::tanhl(__x); }
00498 #else
00499 inline long double
00500 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
00501 #endif
00502 }
00503
00504
00505 #if _GLIBCPP_USE_C99
00506
00507
00508
00509 namespace __gnu_cxx
00510 {
00511 template<typename _Tp>
00512 int
00513 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
00514
00515 template<typename _Tp>
00516 int
00517 __capture_isfinite(_Tp __f) { return isfinite(__f); }
00518
00519 template<typename _Tp>
00520 int
00521 __capture_isinf(_Tp __f) { return isinf(__f); }
00522
00523 template<typename _Tp>
00524 int
00525 __capture_isnan(_Tp __f) { return isnan(__f); }
00526
00527 template<typename _Tp>
00528 int
00529 __capture_isnormal(_Tp __f) { return isnormal(__f); }
00530
00531 template<typename _Tp>
00532 int
00533 __capture_signbit(_Tp __f) { return signbit(__f); }
00534
00535 template<typename _Tp>
00536 int
00537 __capture_isgreater(_Tp __f1, _Tp __f2)
00538 { return isgreater(__f1, __f2); }
00539
00540 template<typename _Tp>
00541 int
00542 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
00543 { return isgreaterequal(__f1, __f2); }
00544
00545 template<typename _Tp>
00546 int
00547 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
00548
00549 template<typename _Tp>
00550 int
00551 __capture_islessequal(_Tp __f1, _Tp __f2)
00552 { return islessequal(__f1, __f2); }
00553
00554 template<typename _Tp>
00555 int
00556 __capture_islessgreater(_Tp __f1, _Tp __f2)
00557 { return islessgreater(__f1, __f2); }
00558
00559 template<typename _Tp>
00560 int
00561 __capture_isunordered(_Tp __f1, _Tp __f2)
00562 { return isunordered(__f1, __f2); }
00563 }
00564 #endif
00565
00566 #undef fpclassify
00567 #undef isfinite
00568 #undef isinf
00569 #undef isnan
00570 #undef isnormal
00571 #undef signbit
00572 #undef isgreater
00573 #undef isgreaterequal
00574 #undef isless
00575 #undef islessequal
00576 #undef islessgreater
00577 #undef isunordered
00578
00579 #if _GLIBCPP_USE_C99
00580 namespace __gnu_cxx
00581 {
00582 template<typename _Tp>
00583 int
00584 fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
00585
00586 template<typename _Tp>
00587 int
00588 isfinite(_Tp __f) { return __capture_isfinite(__f); }
00589
00590 template<typename _Tp>
00591 int
00592 isinf(_Tp __f) { return __capture_isinf(__f); }
00593
00594 template<typename _Tp>
00595 int
00596 isnan(_Tp __f) { return __capture_isnan(__f); }
00597
00598 template<typename _Tp>
00599 int
00600 isnormal(_Tp __f) { return __capture_isnormal(__f); }
00601
00602 template<typename _Tp>
00603 int
00604 signbit(_Tp __f) { return __capture_signbit(__f); }
00605
00606 template<typename _Tp>
00607 int
00608 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
00609
00610 template<typename _Tp>
00611 int
00612 isgreaterequal(_Tp __f1, _Tp __f2)
00613 { return __capture_isgreaterequal(__f1, __f2); }
00614
00615 template<typename _Tp>
00616 int
00617 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
00618
00619 template<typename _Tp>
00620 int
00621 islessequal(_Tp __f1, _Tp __f2)
00622 { return __capture_islessequal(__f1, __f2); }
00623
00624 template<typename _Tp>
00625 int
00626 islessgreater(_Tp __f1, _Tp __f2)
00627 { return __capture_islessgreater(__f1, __f2); }
00628
00629 template<typename _Tp>
00630 int
00631 isunordered(_Tp __f1, _Tp __f2)
00632 { return __capture_isunordered(__f1, __f2); }
00633 }
00634
00635 namespace std
00636 {
00637 using __gnu_cxx::fpclassify;
00638 using __gnu_cxx::isfinite;
00639 using __gnu_cxx::isinf;
00640 using __gnu_cxx::isnan;
00641 using __gnu_cxx::isnormal;
00642 using __gnu_cxx::signbit;
00643 using __gnu_cxx::isgreater;
00644 using __gnu_cxx::isgreaterequal;
00645 using __gnu_cxx::isless;
00646 using __gnu_cxx::islessequal;
00647 using __gnu_cxx::islessgreater;
00648 using __gnu_cxx::isunordered;
00649 }
00650 #endif
00651
00652 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00653 # define export
00654 # include <bits/cmath.tcc>
00655 #endif
00656
00657 #endif