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
00035
00036 #ifndef _CPP_CMATH
00037 #define _CPP_CMATH 1
00038
00039 #include <bits/c++config.h>
00040 #include <bits/std_cstdlib.h>
00041
00042 #pragma GCC system_header
00043 #include <math.h>
00044
00045
00046 #undef abs
00047 #undef div
00048 #undef acos
00049 #undef asin
00050 #undef atan
00051 #undef atan2
00052 #undef ceil
00053 #undef cos
00054 #undef cosh
00055 #undef exp
00056 #undef fabs
00057 #undef floor
00058 #undef fmod
00059 #undef frexp
00060 #undef ldexp
00061 #undef log
00062 #undef log10
00063 #undef modf
00064 #undef pow
00065 #undef sin
00066 #undef sinh
00067 #undef tan
00068 #undef tanh
00069
00070 namespace std
00071 {
00072
00073
00074 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
00075
00076 template<typename _Tp>
00077 inline _Tp
00078 __cmath_abs(_Tp __x)
00079 {
00080 return __x < _Tp() ? -__x : __x;
00081 }
00082
00083 #if _GLIBCPP_HAVE___BUILTIN_FABSF
00084 inline float
00085 abs(float __x) { return __builtin_fabsf(__x); }
00086 #elif _GLIBCPP_HAVE_FABSF
00087 inline float
00088 abs(float __x) { return ::fabsf(__x); }
00089 #else
00090 inline float
00091 abs(float __x) { return __cmath_abs(__x); }
00092 #endif
00093
00094 #if _GLIBCPP_HAVE_ACOSF
00095 inline float
00096 acos(float __x) { return ::acosf(__x); }
00097 #else
00098 inline float
00099 acos(float __x) { return ::acos(static_cast<double>(__x)); }
00100 #endif
00101
00102 #if _GLIBCPP_HAVE_ASINF
00103 inline float
00104 asin(float __x) { return ::asinf(__x); }
00105 #else
00106 inline float
00107 asin(float __x) { return ::asin(static_cast<double>(__x)); }
00108 #endif
00109
00110 #if _GLIBCPP_HAVE_ATANF
00111 inline float
00112 atan(float __x) { return ::atanf(__x); }
00113 #else
00114 inline float
00115 atan(float __x) { return ::atan(static_cast<double>(__x)); }
00116 #endif
00117
00118 #if _GLIBCPP_HAVE_ATAN2F
00119 inline float
00120 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
00121 #else
00122 inline float
00123 atan2(float __y, float __x)
00124 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
00125 #endif
00126
00127 #if _GLIBCPP_HAVE_CEILF
00128 inline float
00129 ceil(float __x) { return ::ceilf(__x); }
00130 #else
00131 inline float
00132 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
00133 #endif
00134
00135 #if _GLIBCPP_HAVE___BUILTIN_COSF
00136 inline float
00137 cos(float __x) { return __builtin_cosf(__x); }
00138 #elif _GLIBCPP_HAVE_COSF
00139 inline float
00140 cos(float __x) { return ::cosf(__x); }
00141 #else
00142 inline float
00143 cos(float __x) { return ::cos(static_cast<double>(__x)); }
00144 #endif
00145
00146 #if _GLIBCPP_HAVE_COSHF
00147 inline float
00148 cosh(float __x) { return ::coshf(__x); }
00149 #else
00150 inline float
00151 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
00152 #endif
00153
00154 #if _GLIBCPP_HAVE_EXPF
00155 inline float
00156 exp(float __x) { return ::expf(__x); }
00157 #else
00158 inline float
00159 exp(float __x) { return ::exp(static_cast<double>(__x)); }
00160 #endif
00161
00162 #if _GLIBCPP_HAVE___BUILTIN_FABSF
00163 inline float
00164 fabs(float __x) { return __builtin_fabsf(__x); }
00165 #elif _GLIBCPP_HAVE_FABSF
00166 inline float
00167 fabs(float __x) { return ::fabsf(__x); }
00168 #else
00169 inline float
00170 fabs(float __x) { return __cmath_abs(__x); }
00171 #endif
00172
00173 #if _GLIBCPP_HAVE_FLOORF
00174 inline float
00175 floor(float __x) { return ::floorf(__x); }
00176 #else
00177 inline float
00178 floor(float __x) { return ::floor(static_cast<double>(__x)); }
00179 #endif
00180
00181 #if _GLIBCPP_HAVE_FMODF
00182 inline float
00183 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
00184 #else
00185 inline float
00186 fmod(float __x, float __y)
00187 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
00188 #endif
00189
00190 #if _GLIBCPP_HAVE_FREXPF
00191 inline float
00192 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
00193 #else
00194 inline float
00195 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
00196 #endif
00197
00198 #if _GLIBCPP_HAVE_LDEXPF
00199 inline float
00200 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
00201 #else
00202 inline float
00203 ldexp(float __x, int __exp)
00204 { return ::ldexp(static_cast<double>(__x), __exp); }
00205 #endif
00206
00207 #if _GLIBCPP_HAVE_LOGF
00208 inline float
00209 log(float __x) { return ::logf(__x); }
00210 #else
00211 inline float log(float __x)
00212 { return ::log(static_cast<double>(__x)); }
00213 #endif
00214
00215 #if _GLIBCPP_HAVE_LOG10F
00216 inline float
00217 log10(float __x) { return ::log10f(__x); }
00218 #else
00219 inline float
00220 log10(float __x) { return ::log10(static_cast<double>(__x)); }
00221 #endif
00222
00223 #if _GLIBCPP_HAVE_MODFF
00224 inline float
00225 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
00226 #else
00227 inline float
00228 modf(float __x, float* __iptr)
00229 {
00230 double __tmp;
00231 double __res = ::modf(static_cast<double>(__x), &__tmp);
00232 *__iptr = static_cast<float>(__tmp);
00233 return __res;
00234 }
00235 #endif
00236
00237 template<typename _Tp>
00238 inline _Tp
00239 __pow_helper(_Tp __x, int __n)
00240 {
00241 return __n < 0
00242 ? _Tp(1)/__cmath_power(__x, -__n)
00243 : __cmath_power(__x, __n);
00244 }
00245
00246 #if _GLIBCPP_HAVE_POWF
00247 inline float
00248 pow(float __x, float __y) { return ::powf(__x, __y); }
00249 #else
00250 inline float
00251 pow(float __x, float __y)
00252 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
00253 #endif
00254
00255 inline float
00256 pow(float __x, int __n)
00257 {
00258 return __pow_helper(__x, __n);
00259 }
00260
00261 #if _GLIBCPP_HAVE___BUILTIN_SINF
00262 inline float
00263 sin(float __x) { return __builtin_sinf(__x); }
00264 #elif _GLIBCPP_HAVE_SINF
00265 inline float
00266 sin(float __x) { return ::sinf(__x); }
00267 #else
00268 inline float
00269 sin(float __x) { return ::sin(static_cast<double>(__x)); }
00270 #endif
00271
00272 #if _GLIBCPP_HAVE_SINHF
00273 inline float
00274 sinh(float __x) { return ::sinhf(__x); }
00275 #else
00276 inline float
00277 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
00278 #endif
00279
00280 #if _GLIBCPP_HAVE___BUILTIN_SQRTF
00281 inline float
00282 sqrt(float __x) { return __builtin_sqrtf(__x); }
00283 #elif _GLIBCPP_HAVE_SQRTF
00284 inline float
00285 sqrt(float __x) { return ::sqrtf(__x); }
00286 #else
00287 inline float
00288 sqrt(float __x) { return ::sqrt(static_cast<double>(__x)); }
00289 #endif
00290
00291 #if _GLIBCPP_HAVE_TANF
00292 inline float
00293 tan(float __x) { return ::tanf(__x); }
00294 #else
00295 inline float
00296 tan(float __x) { return ::tan(static_cast<double>(__x)); }
00297 #endif
00298
00299 #if _GLIBCPP_HAVE_TANHF
00300 inline float
00301 tanh(float __x) { return ::tanhf(__x); }
00302 #else
00303 inline float
00304 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
00305 #endif
00306
00307
00308 extern "C" double acos(double __x);
00309
00310 extern "C" double asin(double __x);
00311
00312 extern "C" double atan(double __x);
00313
00314 extern "C" double atan2(double __y, double __x);
00315
00316 extern "C" double ceil(double __x);
00317
00318 #if _GLIBCPP_HAVE___BUILTIN_COS
00319 inline double
00320 cos(double __x) { return __builtin_cos(__x); }
00321 #else
00322 extern "C" double cos(double __x);
00323 #endif
00324
00325 extern "C" double cosh(double __x);
00326
00327 extern "C" double exp(double __x);
00328
00329 #if _GLIBCPP_HAVE___BUILTIN_FABS
00330 inline double
00331 fabs(double __x) { return __builtin_fabs(__x); }
00332 #else
00333 extern "C" double fabs(double __x);
00334 #endif
00335
00336 #if _GLIBCPP_HAVE___BUILTIN_FABS
00337 inline double
00338 abs(double __x) { return __builtin_fabs(__x); }
00339 #else
00340 inline double
00341 abs(double __x) { return fabs(__x); }
00342 #endif
00343
00344 extern "C" double floor(double __x);
00345
00346 extern "C" double fmod(double __x, double __y);
00347
00348 extern "C" double frexp(double __x, int* __exp);
00349
00350 extern "C" double ldexp(double __x, int __exp);
00351
00352 extern "C" double log(double __x);
00353
00354 extern "C" double log10(double __x);
00355
00356 extern "C" double modf(double __x, double* __iptr);
00357
00358 extern "C" double pow(double __x, double __y);
00359
00360 inline double
00361 pow(double __x, int __i)
00362 {
00363 return __pow_helper(__x, __i);
00364 }
00365
00366 #if _GLIBCPP_HAVE___BUILTIN_SIN
00367 inline double
00368 sin(double __x) { return __builtin_sin(__x); }
00369 #else
00370 extern "C" double sin(double __x);
00371 #endif
00372
00373 extern "C" double sinh(double __x);
00374
00375 #if _GLIBCPP_HAVE___BUILTIN_SQRT
00376 inline double
00377 sqrt(double __x) { return __builtin_fsqrt(__x); }
00378 #else
00379 extern "C" double sqrt(double __x);
00380 #endif
00381
00382 extern "C" double tan(double __x);
00383
00384 extern "C" double tanh(double __x);
00385
00386
00387 #if _GLIBCPP_HAVE___BUILTIN_FABSL
00388 inline long double
00389 abs(long double __x) { return __builtin_fabsl(__x); }
00390 #elif _GLIBCPP_HAVE_FABSL
00391 inline long double
00392 abs(long double __x) { return ::fabsl(__x); }
00393 #else
00394 inline long double
00395 abs(long double __x) { return __cmath_abs(__x); }
00396 #endif
00397
00398 #if _GLIBCPP_HAVE_ACOSL
00399 inline long double
00400 acos(long double __x) { return ::acosl(__x); }
00401 #else
00402 inline long double
00403 acos(long double __x) { return ::acos(static_cast<double>(__x)); }
00404 #endif
00405
00406 #if _GLIBCPP_HAVE_ASINL
00407 inline long double
00408 asin(long double __x) { return ::asinl(__x); }
00409 #else
00410 inline long double
00411 asin(long double __x) { return ::asin(static_cast<double>(__x)); }
00412 #endif
00413
00414 #if _GLIBCPP_HAVE_ATANL
00415 inline long double
00416 atan(long double __x) { return ::atanl(__x); }
00417 #else
00418 inline long double
00419 atan(long double __x) { return ::atan(static_cast<double>(__x)); }
00420 #endif
00421
00422 #if _GLIBCPP_HAVE_ATAN2L
00423 inline long double
00424 atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
00425 #else
00426 inline long double
00427 atan2(long double __y, long double __x)
00428 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
00429 #endif
00430
00431 #if _GLIBCPP_HAVE_CEILL
00432 inline long double
00433 ceil(long double __x) { return ::ceill(__x); }
00434 #else
00435 inline long double
00436 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
00437 #endif
00438
00439 #if _GLIBCPP_HAVE___BUILTIN_COSL
00440 inline long double
00441 cos(long double __x) { return __builtin_cosl(__x); }
00442 #elif _GLIBCPP_HAVE_COSL
00443 inline long double
00444 cos(long double __x) { return ::cosl(__x); }
00445 #else
00446 inline long double
00447 cos(long double __x) { return ::cos(static_cast<double>(__x)); }
00448 #endif
00449
00450 #if _GLIBCPP_HAVE_COSHL
00451 inline long double
00452 cosh(long double __x) { return ::coshl(__x); }
00453 #else
00454 inline long double
00455 cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
00456 #endif
00457
00458 #if _GLIBCPP_HAVE_EXPL
00459 inline long double
00460 exp(long double __x) { return ::expl(__x); }
00461 #else
00462 inline long double
00463 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
00464 #endif
00465
00466 #if _GLIBCPP_HAVE___BUILTIN_FABSL
00467 inline long double
00468 fabs(long double __x) { return __builtin_fabsl(__x); }
00469 #elif _GLIBCPP_HAVE_FABSL
00470 inline long double
00471 fabs(long double __x) { return ::fabsl(__x); }
00472 #else
00473 inline long double
00474 fabs(long double __x) { return __cmath_abs(__x); }
00475 #endif
00476
00477 #if _GLIBCPP_HAVE_FLOORL
00478 inline long double
00479 floor(long double __x) { return ::floorl(__x); }
00480 #else
00481 inline long double
00482 floor(long double __x) { return ::floor(static_cast<double>(__x)); }
00483 #endif
00484
00485 #if _GLIBCPP_HAVE_FMODL
00486 inline long double
00487 fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
00488 #else
00489 inline long double
00490 fmod(long double __x, long double __y)
00491 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
00492 #endif
00493
00494 #if _GLIBCPP_HAVE_FREXPL
00495 inline long double
00496 frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
00497 #else
00498 inline long double
00499 frexp(long double __x, int* __exp)
00500 { return ::frexp(static_cast<double>(__x), __exp); }
00501 #endif
00502
00503 #if _GLIBCPP_HAVE_LDEXPL
00504 inline long double
00505 ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
00506 #else
00507 inline long double
00508 ldexp(long double __x, int __exp)
00509 { return ::ldexp(static_cast<double>(__x), __exp); }
00510 #endif
00511
00512 #if _GLIBCPP_HAVE_LOGL
00513 inline long double
00514 log(long double __x) { return ::logl(__x); }
00515 #else
00516 inline long double
00517 log(long double __x) { return ::log(static_cast<double>(__x)); }
00518 #endif
00519
00520 #if _GLIBCPP_HAVE_LOG10L
00521 inline long double
00522 log10(long double __x) { return ::log10l(__x); }
00523 #else
00524 inline long double
00525 log10(long double __x) { return ::log10(static_cast<double>(__x)); }
00526 #endif
00527
00528 #if _GLIBCPP_HAVE_MODFL
00529 inline long double
00530 modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
00531 #else
00532 inline long double
00533 modf(long double __x, long double* __iptr)
00534 {
00535 double __tmp;
00536 double __res = ::modf(static_cast<double>(__x), &__tmp);
00537 * __iptr = static_cast<long double>(__tmp);
00538 return __res;
00539 }
00540 #endif
00541
00542 #if _GLIBCPP_HAVE_POWL
00543 inline long double
00544 pow(long double __x, long double __y) { return ::powl(__x, __y); }
00545 #else
00546 inline long double
00547 pow(long double __x, long double __y)
00548 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
00549 #endif
00550
00551 inline long double
00552 pow(long double __x, int __n)
00553 {
00554 return __pow_helper(__x, __n);
00555 }
00556
00557 #if _GLIBCPP_HAVE___BUILTIN_SINL
00558 inline long double
00559 sin(long double __x) { return __builtin_sinl(__x); }
00560 #elif _GLIBCPP_HAVE_SINL
00561 inline long double
00562 sin(long double __x) { return ::sinl(__x); }
00563 #else
00564 inline long double
00565 sin(long double __x) { return ::sin(static_cast<double>(__x)); }
00566 #endif
00567
00568 #if _GLIBCPP_HAVE_SINHL
00569 inline long double
00570 sinh(long double __x) { return ::sinhl(__x); }
00571 #else
00572 inline long double
00573 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
00574 #endif
00575
00576 #if _GLIBCPP_HAVE___BUILTIN_SQRTL
00577 inline long double
00578 sqrt(long double __x) { return __builtin_sqrtl(__x); }
00579 #elif _GLIBCPP_HAVE_SQRTL
00580 inline long double
00581 sqrt(long double __x) { return ::sqrtl(__x); }
00582 #else
00583 inline long double
00584 sqrt(long double __x) { return ::sqrt(static_cast<double>(__x)); }
00585 #endif
00586
00587 #if _GLIBCPP_HAVE_TANL
00588 inline long double
00589 tan(long double __x) { return ::tanl(__x); }
00590 #else
00591 inline long double
00592 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
00593 #endif
00594
00595 #if _GLIBCPP_HAVE_TANHL
00596 inline long double
00597 tanh(long double __x) { return ::tanhl(__x); }
00598 #else
00599 inline long double
00600 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
00601 #endif
00602 }
00603
00604
00605 #if _GLIBCPP_USE_C99
00606
00607
00608
00609 namespace c99
00610 {
00611 template<typename _Tp>
00612 int
00613 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
00614
00615 template<typename _Tp>
00616 int
00617 __capture_isfinite(_Tp __f) { return isfinite(__f); }
00618
00619 template<typename _Tp>
00620 int
00621 __capture_isinf(_Tp __f) { return isinf(__f); }
00622
00623 template<typename _Tp>
00624 int
00625 __capture_isnan(_Tp __f) { return isnan(__f); }
00626
00627 template<typename _Tp>
00628 int
00629 __capture_isnormal(_Tp __f) { return isnormal(__f); }
00630
00631 template<typename _Tp>
00632 int
00633 __capture_signbit(_Tp __f) { return signbit(__f); }
00634
00635 template<typename _Tp>
00636 int
00637 __capture_isgreater(_Tp __f1, _Tp __f2) { return isgreater(__f1, __f2); }
00638
00639 template<typename _Tp>
00640 int
00641 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
00642 { return isgreaterequal(__f1, __f2); }
00643
00644 template<typename _Tp>
00645 int
00646 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
00647
00648 template<typename _Tp>
00649 int
00650 __capture_islessequal(_Tp __f1, _Tp __f2)
00651 { return islessequal(__f1, __f2); }
00652
00653 template<typename _Tp>
00654 int
00655 __capture_islessgreater(_Tp __f1, _Tp __f2)
00656 { return islessgreater(__f1, __f2); }
00657
00658 template<typename _Tp>
00659 int
00660 __capture_isunordered(_Tp __f1, _Tp __f2)
00661 { return isunordered(__f1, __f2); }
00662 }
00663 #endif
00664
00665 #undef fpclassify
00666 #undef isfinite
00667 #undef isinf
00668 #undef isnan
00669 #undef isnormal
00670 #undef signbit
00671 #undef isgreater
00672 #undef isgreaterequal
00673 #undef isless
00674 #undef islessequal
00675 #undef islessgreater
00676 #undef isunordered
00677
00678 #if _GLIBCPP_USE_C99
00679 namespace c99
00680 {
00681 template<typename _Tp>
00682 int
00683 fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
00684
00685 template<typename _Tp>
00686 int
00687 isfinite(_Tp __f) { return __capture_isfinite(__f); }
00688
00689 template<typename _Tp>
00690 int
00691 isinf(_Tp __f) { return __capture_isinf(__f); }
00692
00693 template<typename _Tp>
00694 int
00695 isnan(_Tp __f) { return __capture_isnan(__f); }
00696
00697 template<typename _Tp>
00698 int
00699 isnormal(_Tp __f) { return __capture_isnormal(__f); }
00700
00701 template<typename _Tp>
00702 int
00703 signbit(_Tp __f) { return __capture_signbit(__f); }
00704
00705 template<typename _Tp>
00706 int
00707 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
00708
00709 template<typename _Tp>
00710 int
00711 isgreaterequal(_Tp __f1, _Tp __f2)
00712 { return __capture_isgreaterequal(__f1, __f2); }
00713
00714 template<typename _Tp>
00715 int
00716 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
00717
00718 template<typename _Tp>
00719 int
00720 islessequal(_Tp __f1, _Tp __f2)
00721 { return __capture_islessequal(__f1, __f2); }
00722
00723 template<typename _Tp>
00724 int
00725 islessgreater(_Tp __f1, _Tp __f2)
00726 { return __capture_islessgreater(__f1, __f2); }
00727
00728 template<typename _Tp>
00729 int
00730 isunordered(_Tp __f1, _Tp __f2)
00731 { return __capture_isunordered(__f1, __f2); }
00732 }
00733
00734 namespace std
00735 {
00736 using c99::fpclassify;
00737 using c99::isfinite;
00738 using c99::isinf;
00739 using c99::isnan;
00740 using c99::isnormal;
00741 using c99::signbit;
00742 using c99::isgreater;
00743 using c99::isgreaterequal;
00744 using c99::isless;
00745 using c99::islessequal;
00746 using c99::islessgreater;
00747 using c99::isunordered;
00748 }
00749 #endif
00750
00751 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00752 # define export
00753 # include <bits/cmath.tcc>
00754 #endif
00755
00756 #endif