1// TR1 cmath -*- C++ -*- 2 3// Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 4// Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// Under Section 7 of GPL version 3, you are granted additional 18// permissions described in the GCC Runtime Library Exception, version 19// 3.1, as published by the Free Software Foundation. 20 21// You should have received a copy of the GNU General Public License and 22// a copy of the GCC Runtime Library Exception along with this program; 23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24// <http://www.gnu.org/licenses/>. 25 26/** @file tr1/cmath 27 * This is a TR1 C++ Library header. 28 */ 29 30#ifndef _GLIBCXX_TR1_CMATH 31#define _GLIBCXX_TR1_CMATH 1 32 33#pragma GCC system_header 34 35#include <cmath> 36 37#ifdef _GLIBCXX_USE_C99_MATH_TR1 38 39#undef acosh 40#undef acoshf 41#undef acoshl 42#undef asinh 43#undef asinhf 44#undef asinhl 45#undef atanh 46#undef atanhf 47#undef atanhl 48#undef cbrt 49#undef cbrtf 50#undef cbrtl 51#undef copysign 52#undef copysignf 53#undef copysignl 54#undef erf 55#undef erff 56#undef erfl 57#undef erfc 58#undef erfcf 59#undef erfcl 60#undef exp2 61#undef exp2f 62#undef exp2l 63#undef expm1 64#undef expm1f 65#undef expm1l 66#undef fdim 67#undef fdimf 68#undef fdiml 69#undef fma 70#undef fmaf 71#undef fmal 72#undef fmax 73#undef fmaxf 74#undef fmaxl 75#undef fmin 76#undef fminf 77#undef fminl 78#undef hypot 79#undef hypotf 80#undef hypotl 81#undef ilogb 82#undef ilogbf 83#undef ilogbl 84#undef lgamma 85#undef lgammaf 86#undef lgammal 87#undef llrint 88#undef llrintf 89#undef llrintl 90#undef llround 91#undef llroundf 92#undef llroundl 93#undef log1p 94#undef log1pf 95#undef log1pl 96#undef log2 97#undef log2f 98#undef log2l 99#undef logb 100#undef logbf 101#undef logbl 102#undef lrint 103#undef lrintf 104#undef lrintl 105#undef lround 106#undef lroundf 107#undef lroundl 108#undef nan 109#undef nanf 110#undef nanl 111#undef nearbyint 112#undef nearbyintf 113#undef nearbyintl 114#undef nextafter 115#undef nextafterf 116#undef nextafterl 117#undef nexttoward 118#undef nexttowardf 119#undef nexttowardl 120#undef remainder 121#undef remainderf 122#undef remainderl 123#undef remquo 124#undef remquof 125#undef remquol 126#undef rint 127#undef rintf 128#undef rintl 129#undef round 130#undef roundf 131#undef roundl 132#undef scalbln 133#undef scalblnf 134#undef scalblnl 135#undef scalbn 136#undef scalbnf 137#undef scalbnl 138#undef tgamma 139#undef tgammaf 140#undef tgammal 141#undef trunc 142#undef truncf 143#undef truncl 144 145#endif 146 147namespace std _GLIBCXX_VISIBILITY(default) 148{ 149namespace tr1 150{ 151_GLIBCXX_BEGIN_NAMESPACE_VERSION 152 153#if _GLIBCXX_USE_C99_MATH_TR1 154 155 // types 156 using ::double_t; 157 using ::float_t; 158 159 // functions 160 using ::acosh; 161 using ::acoshf; 162 using ::acoshl; 163 164 using ::asinh; 165 using ::asinhf; 166 using ::asinhl; 167 168 using ::atanh; 169 using ::atanhf; 170 using ::atanhl; 171 172 using ::cbrt; 173 using ::cbrtf; 174 using ::cbrtl; 175 176 using ::copysign; 177 using ::copysignf; 178 using ::copysignl; 179 180 using ::erf; 181 using ::erff; 182 using ::erfl; 183 184 using ::erfc; 185 using ::erfcf; 186 using ::erfcl; 187 188 using ::exp2; 189 using ::exp2f; 190 using ::exp2l; 191 192 using ::expm1; 193 using ::expm1f; 194 using ::expm1l; 195 196 using ::fdim; 197 using ::fdimf; 198 using ::fdiml; 199 200 using ::fma; 201 using ::fmaf; 202 using ::fmal; 203 204 using ::fmax; 205 using ::fmaxf; 206 using ::fmaxl; 207 208 using ::fmin; 209 using ::fminf; 210 using ::fminl; 211 212 using ::hypot; 213 using ::hypotf; 214 using ::hypotl; 215 216 using ::ilogb; 217 using ::ilogbf; 218 using ::ilogbl; 219 220 using ::lgamma; 221 using ::lgammaf; 222 using ::lgammal; 223 224 using ::llrint; 225 using ::llrintf; 226 using ::llrintl; 227 228 using ::llround; 229 using ::llroundf; 230 using ::llroundl; 231 232 using ::log1p; 233 using ::log1pf; 234 using ::log1pl; 235 236 using ::log2; 237 using ::log2f; 238 using ::log2l; 239 240 using ::logb; 241 using ::logbf; 242 using ::logbl; 243 244 using ::lrint; 245 using ::lrintf; 246 using ::lrintl; 247 248 using ::lround; 249 using ::lroundf; 250 using ::lroundl; 251 252 using ::nan; 253 using ::nanf; 254 using ::nanl; 255 256 using ::nearbyint; 257 using ::nearbyintf; 258 using ::nearbyintl; 259 260 using ::nextafter; 261 using ::nextafterf; 262 using ::nextafterl; 263 264 using ::nexttoward; 265 using ::nexttowardf; 266 using ::nexttowardl; 267 268 using ::remainder; 269 using ::remainderf; 270 using ::remainderl; 271 272 using ::remquo; 273 using ::remquof; 274 using ::remquol; 275 276 using ::rint; 277 using ::rintf; 278 using ::rintl; 279 280 using ::round; 281 using ::roundf; 282 using ::roundl; 283 284 using ::scalbln; 285 using ::scalblnf; 286 using ::scalblnl; 287 288 using ::scalbn; 289 using ::scalbnf; 290 using ::scalbnl; 291 292 using ::tgamma; 293 using ::tgammaf; 294 using ::tgammal; 295 296 using ::trunc; 297 using ::truncf; 298 using ::truncl; 299 300#endif 301 302#if _GLIBCXX_USE_C99_MATH 303#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 304 305 /// Function template definitions [8.16.3]. 306 template<typename _Tp> 307 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 308 int>::__type 309 fpclassify(_Tp __f) 310 { 311 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 312 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, 313 FP_SUBNORMAL, FP_ZERO, __type(__f)); 314 } 315 316 template<typename _Tp> 317 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 318 int>::__type 319 isfinite(_Tp __f) 320 { 321 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 322 return __builtin_isfinite(__type(__f)); 323 } 324 325 template<typename _Tp> 326 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 327 int>::__type 328 isinf(_Tp __f) 329 { 330 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 331 return __builtin_isinf(__type(__f)); 332 } 333 334 template<typename _Tp> 335 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 336 int>::__type 337 isnan(_Tp __f) 338 { 339 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 340 return __builtin_isnan(__type(__f)); 341 } 342 343 template<typename _Tp> 344 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 345 int>::__type 346 isnormal(_Tp __f) 347 { 348 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 349 return __builtin_isnormal(__type(__f)); 350 } 351 352 template<typename _Tp> 353 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 354 int>::__type 355 signbit(_Tp __f) 356 { 357 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 358 return __builtin_signbit(__type(__f)); 359 } 360 361 template<typename _Tp> 362 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 363 int>::__type 364 isgreater(_Tp __f1, _Tp __f2) 365 { 366 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 367 return __builtin_isgreater(__type(__f1), __type(__f2)); 368 } 369 370 template<typename _Tp> 371 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 372 int>::__type 373 isgreaterequal(_Tp __f1, _Tp __f2) 374 { 375 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 376 return __builtin_isgreaterequal(__type(__f1), __type(__f2)); 377 } 378 379 template<typename _Tp> 380 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 381 int>::__type 382 isless(_Tp __f1, _Tp __f2) 383 { 384 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 385 return __builtin_isless(__type(__f1), __type(__f2)); 386 } 387 388 template<typename _Tp> 389 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 390 int>::__type 391 islessequal(_Tp __f1, _Tp __f2) 392 { 393 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 394 return __builtin_islessequal(__type(__f1), __type(__f2)); 395 } 396 397 template<typename _Tp> 398 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 399 int>::__type 400 islessgreater(_Tp __f1, _Tp __f2) 401 { 402 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 403 return __builtin_islessgreater(__type(__f1), __type(__f2)); 404 } 405 406 template<typename _Tp> 407 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 408 int>::__type 409 isunordered(_Tp __f1, _Tp __f2) 410 { 411 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 412 return __builtin_isunordered(__type(__f1), __type(__f2)); 413 } 414 415#endif 416#endif 417 418#if _GLIBCXX_USE_C99_MATH_TR1 419 420 /// Additional overloads [8.16.4]. 421 using std::acos; 422 423 inline float 424 acosh(float __x) 425 { return __builtin_acoshf(__x); } 426 427 inline long double 428 acosh(long double __x) 429 { return __builtin_acoshl(__x); } 430 431 template<typename _Tp> 432 inline typename __gnu_cxx::__promote<_Tp>::__type 433 acosh(_Tp __x) 434 { 435 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 436 return acosh(__type(__x)); 437 } 438 439 using std::asin; 440 441 inline float 442 asinh(float __x) 443 { return __builtin_asinhf(__x); } 444 445 inline long double 446 asinh(long double __x) 447 { return __builtin_asinhl(__x); } 448 449 template<typename _Tp> 450 inline typename __gnu_cxx::__promote<_Tp>::__type 451 asinh(_Tp __x) 452 { 453 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 454 return asinh(__type(__x)); 455 } 456 457 using std::atan; 458 using std::atan2; 459 460 inline float 461 atanh(float __x) 462 { return __builtin_atanhf(__x); } 463 464 inline long double 465 atanh(long double __x) 466 { return __builtin_atanhl(__x); } 467 468 template<typename _Tp> 469 inline typename __gnu_cxx::__promote<_Tp>::__type 470 atanh(_Tp __x) 471 { 472 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 473 return atanh(__type(__x)); 474 } 475 476 inline float 477 cbrt(float __x) 478 { return __builtin_cbrtf(__x); } 479 480 inline long double 481 cbrt(long double __x) 482 { return __builtin_cbrtl(__x); } 483 484 template<typename _Tp> 485 inline typename __gnu_cxx::__promote<_Tp>::__type 486 cbrt(_Tp __x) 487 { 488 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 489 return cbrt(__type(__x)); 490 } 491 492 using std::ceil; 493 494 inline float 495 copysign(float __x, float __y) 496 { return __builtin_copysignf(__x, __y); } 497 498 inline long double 499 copysign(long double __x, long double __y) 500 { return __builtin_copysignl(__x, __y); } 501 502 template<typename _Tp, typename _Up> 503 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 504 copysign(_Tp __x, _Up __y) 505 { 506 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 507 return copysign(__type(__x), __type(__y)); 508 } 509 510 using std::cos; 511 using std::cosh; 512 513 inline float 514 erf(float __x) 515 { return __builtin_erff(__x); } 516 517 inline long double 518 erf(long double __x) 519 { return __builtin_erfl(__x); } 520 521 template<typename _Tp> 522 inline typename __gnu_cxx::__promote<_Tp>::__type 523 erf(_Tp __x) 524 { 525 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 526 return erf(__type(__x)); 527 } 528 529 inline float 530 erfc(float __x) 531 { return __builtin_erfcf(__x); } 532 533 inline long double 534 erfc(long double __x) 535 { return __builtin_erfcl(__x); } 536 537 template<typename _Tp> 538 inline typename __gnu_cxx::__promote<_Tp>::__type 539 erfc(_Tp __x) 540 { 541 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 542 return erfc(__type(__x)); 543 } 544 545 using std::exp; 546 547 inline float 548 exp2(float __x) 549 { return __builtin_exp2f(__x); } 550 551 inline long double 552 exp2(long double __x) 553 { return __builtin_exp2l(__x); } 554 555 template<typename _Tp> 556 inline typename __gnu_cxx::__promote<_Tp>::__type 557 exp2(_Tp __x) 558 { 559 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 560 return exp2(__type(__x)); 561 } 562 563 inline float 564 expm1(float __x) 565 { return __builtin_expm1f(__x); } 566 567 inline long double 568 expm1(long double __x) 569 { return __builtin_expm1l(__x); } 570 571 template<typename _Tp> 572 inline typename __gnu_cxx::__promote<_Tp>::__type 573 expm1(_Tp __x) 574 { 575 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 576 return expm1(__type(__x)); 577 } 578 579 // Note: we deal with fabs in a special way, because an using std::fabs 580 // would bring in also the overloads for complex types, which in C++0x 581 // mode have a different return type. 582 using ::fabs; 583 584 inline float 585 fabs(float __x) 586 { return __builtin_fabsf(__x); } 587 588 inline long double 589 fabs(long double __x) 590 { return __builtin_fabsl(__x); } 591 592 template<typename _Tp> 593 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 594 double>::__type 595 fabs(_Tp __x) 596 { return __builtin_fabs(__x); } 597 598 inline float 599 fdim(float __x, float __y) 600 { return __builtin_fdimf(__x, __y); } 601 602 inline long double 603 fdim(long double __x, long double __y) 604 { return __builtin_fdiml(__x, __y); } 605 606 template<typename _Tp, typename _Up> 607 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 608 fdim(_Tp __x, _Up __y) 609 { 610 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 611 return fdim(__type(__x), __type(__y)); 612 } 613 614 using std::floor; 615 616 inline float 617 fma(float __x, float __y, float __z) 618 { return __builtin_fmaf(__x, __y, __z); } 619 620 inline long double 621 fma(long double __x, long double __y, long double __z) 622 { return __builtin_fmal(__x, __y, __z); } 623 624 template<typename _Tp, typename _Up, typename _Vp> 625 inline typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type 626 fma(_Tp __x, _Up __y, _Vp __z) 627 { 628 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type; 629 return fma(__type(__x), __type(__y), __type(__z)); 630 } 631 632 inline float 633 fmax(float __x, float __y) 634 { return __builtin_fmaxf(__x, __y); } 635 636 inline long double 637 fmax(long double __x, long double __y) 638 { return __builtin_fmaxl(__x, __y); } 639 640 template<typename _Tp, typename _Up> 641 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 642 fmax(_Tp __x, _Up __y) 643 { 644 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 645 return fmax(__type(__x), __type(__y)); 646 } 647 648 inline float 649 fmin(float __x, float __y) 650 { return __builtin_fminf(__x, __y); } 651 652 inline long double 653 fmin(long double __x, long double __y) 654 { return __builtin_fminl(__x, __y); } 655 656 template<typename _Tp, typename _Up> 657 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 658 fmin(_Tp __x, _Up __y) 659 { 660 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 661 return fmin(__type(__x), __type(__y)); 662 } 663 664 using std::fmod; 665 using std::frexp; 666 667 inline float 668 hypot(float __x, float __y) 669 { return __builtin_hypotf(__x, __y); } 670 671 inline long double 672 hypot(long double __x, long double __y) 673 { return __builtin_hypotl(__x, __y); } 674 675 template<typename _Tp, typename _Up> 676 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 677 hypot(_Tp __x, _Up __y) 678 { 679 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 680 return hypot(__type(__x), __type(__y)); 681 } 682 683 inline int 684 ilogb(float __x) 685 { return __builtin_ilogbf(__x); } 686 687 inline int 688 ilogb(long double __x) 689 { return __builtin_ilogbl(__x); } 690 691 template<typename _Tp> 692 inline int 693 ilogb(_Tp __x) 694 { 695 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 696 return ilogb(__type(__x)); 697 } 698 699 using std::ldexp; 700 701 inline float 702 lgamma(float __x) 703 { return __builtin_lgammaf(__x); } 704 705 inline long double 706 lgamma(long double __x) 707 { return __builtin_lgammal(__x); } 708 709 template<typename _Tp> 710 inline typename __gnu_cxx::__promote<_Tp>::__type 711 lgamma(_Tp __x) 712 { 713 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 714 return lgamma(__type(__x)); 715 } 716 717 inline long long 718 llrint(float __x) 719 { return __builtin_llrintf(__x); } 720 721 inline long long 722 llrint(long double __x) 723 { return __builtin_llrintl(__x); } 724 725 template<typename _Tp> 726 inline long long 727 llrint(_Tp __x) 728 { 729 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 730 return llrint(__type(__x)); 731 } 732 733 inline long long 734 llround(float __x) 735 { return __builtin_llroundf(__x); } 736 737 inline long long 738 llround(long double __x) 739 { return __builtin_llroundl(__x); } 740 741 template<typename _Tp> 742 inline long long 743 llround(_Tp __x) 744 { 745 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 746 return llround(__type(__x)); 747 } 748 749 using std::log; 750 using std::log10; 751 752 inline float 753 log1p(float __x) 754 { return __builtin_log1pf(__x); } 755 756 inline long double 757 log1p(long double __x) 758 { return __builtin_log1pl(__x); } 759 760 template<typename _Tp> 761 inline typename __gnu_cxx::__promote<_Tp>::__type 762 log1p(_Tp __x) 763 { 764 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 765 return log1p(__type(__x)); 766 } 767 768 // DR 568. 769 inline float 770 log2(float __x) 771 { return __builtin_log2f(__x); } 772 773 inline long double 774 log2(long double __x) 775 { return __builtin_log2l(__x); } 776 777 template<typename _Tp> 778 inline typename __gnu_cxx::__promote<_Tp>::__type 779 log2(_Tp __x) 780 { 781 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 782 return log2(__type(__x)); 783 } 784 785 inline float 786 logb(float __x) 787 { return __builtin_logbf(__x); } 788 789 inline long double 790 logb(long double __x) 791 { return __builtin_logbl(__x); } 792 793 template<typename _Tp> 794 inline typename __gnu_cxx::__promote<_Tp>::__type 795 logb(_Tp __x) 796 { 797 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 798 return logb(__type(__x)); 799 } 800 801 inline long 802 lrint(float __x) 803 { return __builtin_lrintf(__x); } 804 805 inline long 806 lrint(long double __x) 807 { return __builtin_lrintl(__x); } 808 809 template<typename _Tp> 810 inline long 811 lrint(_Tp __x) 812 { 813 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 814 return lrint(__type(__x)); 815 } 816 817 inline long 818 lround(float __x) 819 { return __builtin_lroundf(__x); } 820 821 inline long 822 lround(long double __x) 823 { return __builtin_lroundl(__x); } 824 825 template<typename _Tp> 826 inline long 827 lround(_Tp __x) 828 { 829 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 830 return lround(__type(__x)); 831 } 832 833 inline float 834 nearbyint(float __x) 835 { return __builtin_nearbyintf(__x); } 836 837 inline long double 838 nearbyint(long double __x) 839 { return __builtin_nearbyintl(__x); } 840 841 template<typename _Tp> 842 inline typename __gnu_cxx::__promote<_Tp>::__type 843 nearbyint(_Tp __x) 844 { 845 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 846 return nearbyint(__type(__x)); 847 } 848 849 inline float 850 nextafter(float __x, float __y) 851 { return __builtin_nextafterf(__x, __y); } 852 853 inline long double 854 nextafter(long double __x, long double __y) 855 { return __builtin_nextafterl(__x, __y); } 856 857 template<typename _Tp, typename _Up> 858 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 859 nextafter(_Tp __x, _Up __y) 860 { 861 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 862 return nextafter(__type(__x), __type(__y)); 863 } 864 865 inline float 866 nexttoward(float __x, long double __y) 867 { return __builtin_nexttowardf(__x, __y); } 868 869 inline long double 870 nexttoward(long double __x, long double __y) 871 { return __builtin_nexttowardl(__x, __y); } 872 873 template<typename _Tp> 874 inline typename __gnu_cxx::__promote<_Tp>::__type 875 nexttoward(_Tp __x, long double __y) 876 { 877 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 878 return nexttoward(__type(__x), __y); 879 } 880 881 // DR 550. What should the return type of pow(float,int) be? 882 // NB: C++0x and TR1 != C++03. 883 // using std::pow; 884 885 inline float 886 remainder(float __x, float __y) 887 { return __builtin_remainderf(__x, __y); } 888 889 inline long double 890 remainder(long double __x, long double __y) 891 { return __builtin_remainderl(__x, __y); } 892 893 template<typename _Tp, typename _Up> 894 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 895 remainder(_Tp __x, _Up __y) 896 { 897 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 898 return remainder(__type(__x), __type(__y)); 899 } 900 901 inline float 902 remquo(float __x, float __y, int* __pquo) 903 { return __builtin_remquof(__x, __y, __pquo); } 904 905 inline long double 906 remquo(long double __x, long double __y, int* __pquo) 907 { return __builtin_remquol(__x, __y, __pquo); } 908 909 template<typename _Tp, typename _Up> 910 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 911 remquo(_Tp __x, _Up __y, int* __pquo) 912 { 913 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 914 return remquo(__type(__x), __type(__y), __pquo); 915 } 916 917 inline float 918 rint(float __x) 919 { return __builtin_rintf(__x); } 920 921 inline long double 922 rint(long double __x) 923 { return __builtin_rintl(__x); } 924 925 template<typename _Tp> 926 inline typename __gnu_cxx::__promote<_Tp>::__type 927 rint(_Tp __x) 928 { 929 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 930 return rint(__type(__x)); 931 } 932 933 inline float 934 round(float __x) 935 { return __builtin_roundf(__x); } 936 937 inline long double 938 round(long double __x) 939 { return __builtin_roundl(__x); } 940 941 template<typename _Tp> 942 inline typename __gnu_cxx::__promote<_Tp>::__type 943 round(_Tp __x) 944 { 945 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 946 return round(__type(__x)); 947 } 948 949 inline float 950 scalbln(float __x, long __ex) 951 { return __builtin_scalblnf(__x, __ex); } 952 953 inline long double 954 scalbln(long double __x, long __ex) 955 { return __builtin_scalblnl(__x, __ex); } 956 957 template<typename _Tp> 958 inline typename __gnu_cxx::__promote<_Tp>::__type 959 scalbln(_Tp __x, long __ex) 960 { 961 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 962 return scalbln(__type(__x), __ex); 963 } 964 965 inline float 966 scalbn(float __x, int __ex) 967 { return __builtin_scalbnf(__x, __ex); } 968 969 inline long double 970 scalbn(long double __x, int __ex) 971 { return __builtin_scalbnl(__x, __ex); } 972 973 template<typename _Tp> 974 inline typename __gnu_cxx::__promote<_Tp>::__type 975 scalbn(_Tp __x, int __ex) 976 { 977 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 978 return scalbn(__type(__x), __ex); 979 } 980 981 using std::sin; 982 using std::sinh; 983 using std::sqrt; 984 using std::tan; 985 using std::tanh; 986 987 inline float 988 tgamma(float __x) 989 { return __builtin_tgammaf(__x); } 990 991 inline long double 992 tgamma(long double __x) 993 { return __builtin_tgammal(__x); } 994 995 template<typename _Tp> 996 inline typename __gnu_cxx::__promote<_Tp>::__type 997 tgamma(_Tp __x) 998 { 999 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1000 return tgamma(__type(__x)); 1001 } 1002 1003 inline float 1004 trunc(float __x) 1005 { return __builtin_truncf(__x); } 1006 1007 inline long double 1008 trunc(long double __x) 1009 { return __builtin_truncl(__x); } 1010 1011 template<typename _Tp> 1012 inline typename __gnu_cxx::__promote<_Tp>::__type 1013 trunc(_Tp __x) 1014 { 1015 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1016 return trunc(__type(__x)); 1017 } 1018 1019#endif 1020_GLIBCXX_END_NAMESPACE_VERSION 1021} 1022} 1023 1024namespace std _GLIBCXX_VISIBILITY(default) 1025{ 1026namespace tr1 1027{ 1028_GLIBCXX_BEGIN_NAMESPACE_VERSION 1029 1030 // DR 550. What should the return type of pow(float,int) be? 1031 // NB: C++0x and TR1 != C++03. 1032 inline double 1033 pow(double __x, double __y) 1034 { return std::pow(__x, __y); } 1035 1036 inline float 1037 pow(float __x, float __y) 1038 { return std::pow(__x, __y); } 1039 1040 inline long double 1041 pow(long double __x, long double __y) 1042 { return std::pow(__x, __y); } 1043 1044 template<typename _Tp, typename _Up> 1045 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type 1046 pow(_Tp __x, _Up __y) 1047 { 1048 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 1049 return std::pow(__type(__x), __type(__y)); 1050 } 1051 1052_GLIBCXX_END_NAMESPACE_VERSION 1053} 1054} 1055 1056#include <bits/stl_algobase.h> 1057#include <limits> 1058#include <tr1/type_traits> 1059 1060#include <tr1/gamma.tcc> 1061#include <tr1/bessel_function.tcc> 1062#include <tr1/beta_function.tcc> 1063#include <tr1/ell_integral.tcc> 1064#include <tr1/exp_integral.tcc> 1065#include <tr1/hypergeometric.tcc> 1066#include <tr1/legendre_function.tcc> 1067#include <tr1/modified_bessel_func.tcc> 1068#include <tr1/poly_hermite.tcc> 1069#include <tr1/poly_laguerre.tcc> 1070#include <tr1/riemann_zeta.tcc> 1071 1072namespace std _GLIBCXX_VISIBILITY(default) 1073{ 1074namespace tr1 1075{ 1076_GLIBCXX_BEGIN_NAMESPACE_VERSION 1077 1078 /** 1079 * @defgroup tr1_math_spec_func Mathematical Special Functions 1080 * @ingroup numerics 1081 * 1082 * A collection of advanced mathematical special functions. 1083 * @{ 1084 */ 1085 1086 inline float 1087 assoc_laguerref(unsigned int __n, unsigned int __m, float __x) 1088 { return __detail::__assoc_laguerre<float>(__n, __m, __x); } 1089 1090 inline long double 1091 assoc_laguerrel(unsigned int __n, unsigned int __m, long double __x) 1092 { 1093 return __detail::__assoc_laguerre<long double>(__n, __m, __x); 1094 } 1095 1096 /// 5.2.1.1 Associated Laguerre polynomials. 1097 template<typename _Tp> 1098 inline typename __gnu_cxx::__promote<_Tp>::__type 1099 assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x) 1100 { 1101 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1102 return __detail::__assoc_laguerre<__type>(__n, __m, __x); 1103 } 1104 1105 inline float 1106 assoc_legendref(unsigned int __l, unsigned int __m, float __x) 1107 { return __detail::__assoc_legendre_p<float>(__l, __m, __x); } 1108 1109 inline long double 1110 assoc_legendrel(unsigned int __l, unsigned int __m, long double __x) 1111 { return __detail::__assoc_legendre_p<long double>(__l, __m, __x); } 1112 1113 /// 5.2.1.2 Associated Legendre functions. 1114 template<typename _Tp> 1115 inline typename __gnu_cxx::__promote<_Tp>::__type 1116 assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x) 1117 { 1118 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1119 return __detail::__assoc_legendre_p<__type>(__l, __m, __x); 1120 } 1121 1122 inline float 1123 betaf(float __x, float __y) 1124 { return __detail::__beta<float>(__x, __y); } 1125 1126 inline long double 1127 betal(long double __x, long double __y) 1128 { return __detail::__beta<long double>(__x, __y); } 1129 1130 /// 5.2.1.3 Beta functions. 1131 template<typename _Tpx, typename _Tpy> 1132 inline typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type 1133 beta(_Tpx __x, _Tpy __y) 1134 { 1135 typedef typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type __type; 1136 return __detail::__beta<__type>(__x, __y); 1137 } 1138 1139 inline float 1140 comp_ellint_1f(float __k) 1141 { return __detail::__comp_ellint_1<float>(__k); } 1142 1143 inline long double 1144 comp_ellint_1l(long double __k) 1145 { return __detail::__comp_ellint_1<long double>(__k); } 1146 1147 /// 5.2.1.4 Complete elliptic integrals of the first kind. 1148 template<typename _Tp> 1149 inline typename __gnu_cxx::__promote<_Tp>::__type 1150 comp_ellint_1(_Tp __k) 1151 { 1152 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1153 return __detail::__comp_ellint_1<__type>(__k); 1154 } 1155 1156 inline float 1157 comp_ellint_2f(float __k) 1158 { return __detail::__comp_ellint_2<float>(__k); } 1159 1160 inline long double 1161 comp_ellint_2l(long double __k) 1162 { return __detail::__comp_ellint_2<long double>(__k); } 1163 1164 /// 5.2.1.5 Complete elliptic integrals of the second kind. 1165 template<typename _Tp> 1166 inline typename __gnu_cxx::__promote<_Tp>::__type 1167 comp_ellint_2(_Tp __k) 1168 { 1169 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1170 return __detail::__comp_ellint_2<__type>(__k); 1171 } 1172 1173 inline float 1174 comp_ellint_3f(float __k, float __nu) 1175 { return __detail::__comp_ellint_3<float>(__k, __nu); } 1176 1177 inline long double 1178 comp_ellint_3l(long double __k, long double __nu) 1179 { return __detail::__comp_ellint_3<long double>(__k, __nu); } 1180 1181 /// 5.2.1.6 Complete elliptic integrals of the third kind. 1182 template<typename _Tp, typename _Tpn> 1183 inline typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type 1184 comp_ellint_3(_Tp __k, _Tpn __nu) 1185 { 1186 typedef typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type __type; 1187 return __detail::__comp_ellint_3<__type>(__k, __nu); 1188 } 1189 1190 inline float 1191 conf_hypergf(float __a, float __c, float __x) 1192 { return __detail::__conf_hyperg<float>(__a, __c, __x); } 1193 1194 inline long double 1195 conf_hypergl(long double __a, long double __c, long double __x) 1196 { return __detail::__conf_hyperg<long double>(__a, __c, __x); } 1197 1198 /// 5.2.1.7 Confluent hypergeometric functions. 1199 template<typename _Tpa, typename _Tpc, typename _Tp> 1200 inline typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type 1201 conf_hyperg(_Tpa __a, _Tpc __c, _Tp __x) 1202 { 1203 typedef typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type __type; 1204 return __detail::__conf_hyperg<__type>(__a, __c, __x); 1205 } 1206 1207 inline float 1208 cyl_bessel_if(float __nu, float __x) 1209 { return __detail::__cyl_bessel_i<float>(__nu, __x); } 1210 1211 inline long double 1212 cyl_bessel_il(long double __nu, long double __x) 1213 { return __detail::__cyl_bessel_i<long double>(__nu, __x); } 1214 1215 /// 5.2.1.8 Regular modified cylindrical Bessel functions. 1216 template<typename _Tpnu, typename _Tp> 1217 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type 1218 cyl_bessel_i(_Tpnu __nu, _Tp __x) 1219 { 1220 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; 1221 return __detail::__cyl_bessel_i<__type>(__nu, __x); 1222 } 1223 1224 inline float 1225 cyl_bessel_jf(float __nu, float __x) 1226 { return __detail::__cyl_bessel_j<float>(__nu, __x); } 1227 1228 inline long double 1229 cyl_bessel_jl(long double __nu, long double __x) 1230 { return __detail::__cyl_bessel_j<long double>(__nu, __x); } 1231 1232 /// 5.2.1.9 Cylindrical Bessel functions (of the first kind). 1233 template<typename _Tpnu, typename _Tp> 1234 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type 1235 cyl_bessel_j(_Tpnu __nu, _Tp __x) 1236 { 1237 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; 1238 return __detail::__cyl_bessel_j<__type>(__nu, __x); 1239 } 1240 1241 inline float 1242 cyl_bessel_kf(float __nu, float __x) 1243 { return __detail::__cyl_bessel_k<float>(__nu, __x); } 1244 1245 inline long double 1246 cyl_bessel_kl(long double __nu, long double __x) 1247 { return __detail::__cyl_bessel_k<long double>(__nu, __x); } 1248 1249 /// 5.2.1.10 Irregular modified cylindrical Bessel functions. 1250 template<typename _Tpnu, typename _Tp> 1251 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type 1252 cyl_bessel_k(_Tpnu __nu, _Tp __x) 1253 { 1254 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; 1255 return __detail::__cyl_bessel_k<__type>(__nu, __x); 1256 } 1257 1258 inline float 1259 cyl_neumannf(float __nu, float __x) 1260 { return __detail::__cyl_neumann_n<float>(__nu, __x); } 1261 1262 inline long double 1263 cyl_neumannl(long double __nu, long double __x) 1264 { return __detail::__cyl_neumann_n<long double>(__nu, __x); } 1265 1266 /// 5.2.1.11 Cylindrical Neumann functions. 1267 template<typename _Tpnu, typename _Tp> 1268 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type 1269 cyl_neumann(_Tpnu __nu, _Tp __x) 1270 { 1271 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; 1272 return __detail::__cyl_neumann_n<__type>(__nu, __x); 1273 } 1274 1275 inline float 1276 ellint_1f(float __k, float __phi) 1277 { return __detail::__ellint_1<float>(__k, __phi); } 1278 1279 inline long double 1280 ellint_1l(long double __k, long double __phi) 1281 { return __detail::__ellint_1<long double>(__k, __phi); } 1282 1283 /// 5.2.1.12 Incomplete elliptic integrals of the first kind. 1284 template<typename _Tp, typename _Tpp> 1285 inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type 1286 ellint_1(_Tp __k, _Tpp __phi) 1287 { 1288 typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type; 1289 return __detail::__ellint_1<__type>(__k, __phi); 1290 } 1291 1292 inline float 1293 ellint_2f(float __k, float __phi) 1294 { return __detail::__ellint_2<float>(__k, __phi); } 1295 1296 inline long double 1297 ellint_2l(long double __k, long double __phi) 1298 { return __detail::__ellint_2<long double>(__k, __phi); } 1299 1300 /// 5.2.1.13 Incomplete elliptic integrals of the second kind. 1301 template<typename _Tp, typename _Tpp> 1302 inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type 1303 ellint_2(_Tp __k, _Tpp __phi) 1304 { 1305 typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type; 1306 return __detail::__ellint_2<__type>(__k, __phi); 1307 } 1308 1309 inline float 1310 ellint_3f(float __k, float __nu, float __phi) 1311 { return __detail::__ellint_3<float>(__k, __nu, __phi); } 1312 1313 inline long double 1314 ellint_3l(long double __k, long double __nu, long double __phi) 1315 { return __detail::__ellint_3<long double>(__k, __nu, __phi); } 1316 1317 /// 5.2.1.14 Incomplete elliptic integrals of the third kind. 1318 template<typename _Tp, typename _Tpn, typename _Tpp> 1319 inline typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type 1320 ellint_3(_Tp __k, _Tpn __nu, _Tpp __phi) 1321 { 1322 typedef typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type __type; 1323 return __detail::__ellint_3<__type>(__k, __nu, __phi); 1324 } 1325 1326 inline float 1327 expintf(float __x) 1328 { return __detail::__expint<float>(__x); } 1329 1330 inline long double 1331 expintl(long double __x) 1332 { return __detail::__expint<long double>(__x); } 1333 1334 /// 5.2.1.15 Exponential integrals. 1335 template<typename _Tp> 1336 inline typename __gnu_cxx::__promote<_Tp>::__type 1337 expint(_Tp __x) 1338 { 1339 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1340 return __detail::__expint<__type>(__x); 1341 } 1342 1343 inline float 1344 hermitef(unsigned int __n, float __x) 1345 { return __detail::__poly_hermite<float>(__n, __x); } 1346 1347 inline long double 1348 hermitel(unsigned int __n, long double __x) 1349 { return __detail::__poly_hermite<long double>(__n, __x); } 1350 1351 /// 5.2.1.16 Hermite polynomials. 1352 template<typename _Tp> 1353 inline typename __gnu_cxx::__promote<_Tp>::__type 1354 hermite(unsigned int __n, _Tp __x) 1355 { 1356 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1357 return __detail::__poly_hermite<__type>(__n, __x); 1358 } 1359 1360 inline float 1361 hypergf(float __a, float __b, float __c, float __x) 1362 { return __detail::__hyperg<float>(__a, __b, __c, __x); } 1363 1364 inline long double 1365 hypergl(long double __a, long double __b, long double __c, long double __x) 1366 { return __detail::__hyperg<long double>(__a, __b, __c, __x); } 1367 1368 /// 5.2.1.17 Hypergeometric functions. 1369 template<typename _Tpa, typename _Tpb, typename _Tpc, typename _Tp> 1370 inline typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type 1371 hyperg(_Tpa __a, _Tpb __b, _Tpc __c, _Tp __x) 1372 { 1373 typedef typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type; 1374 return __detail::__hyperg<__type>(__a, __b, __c, __x); 1375 } 1376 1377 inline float 1378 laguerref(unsigned int __n, float __x) 1379 { return __detail::__laguerre<float>(__n, __x); } 1380 1381 inline long double 1382 laguerrel(unsigned int __n, long double __x) 1383 { return __detail::__laguerre<long double>(__n, __x); } 1384 1385 /// 5.2.1.18 Laguerre polynomials. 1386 template<typename _Tp> 1387 inline typename __gnu_cxx::__promote<_Tp>::__type 1388 laguerre(unsigned int __n, _Tp __x) 1389 { 1390 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1391 return __detail::__laguerre<__type>(__n, __x); 1392 } 1393 1394 inline float 1395 legendref(unsigned int __n, float __x) 1396 { return __detail::__poly_legendre_p<float>(__n, __x); } 1397 1398 inline long double 1399 legendrel(unsigned int __n, long double __x) 1400 { return __detail::__poly_legendre_p<long double>(__n, __x); } 1401 1402 /// 5.2.1.19 Legendre polynomials. 1403 template<typename _Tp> 1404 inline typename __gnu_cxx::__promote<_Tp>::__type 1405 legendre(unsigned int __n, _Tp __x) 1406 { 1407 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1408 return __detail::__poly_legendre_p<__type>(__n, __x); 1409 } 1410 1411 inline float 1412 riemann_zetaf(float __x) 1413 { return __detail::__riemann_zeta<float>(__x); } 1414 1415 inline long double 1416 riemann_zetal(long double __x) 1417 { return __detail::__riemann_zeta<long double>(__x); } 1418 1419 /// 5.2.1.20 Riemann zeta function. 1420 template<typename _Tp> 1421 inline typename __gnu_cxx::__promote<_Tp>::__type 1422 riemann_zeta(_Tp __x) 1423 { 1424 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1425 return __detail::__riemann_zeta<__type>(__x); 1426 } 1427 1428 inline float 1429 sph_besself(unsigned int __n, float __x) 1430 { return __detail::__sph_bessel<float>(__n, __x); } 1431 1432 inline long double 1433 sph_bessell(unsigned int __n, long double __x) 1434 { return __detail::__sph_bessel<long double>(__n, __x); } 1435 1436 /// 5.2.1.21 Spherical Bessel functions. 1437 template<typename _Tp> 1438 inline typename __gnu_cxx::__promote<_Tp>::__type 1439 sph_bessel(unsigned int __n, _Tp __x) 1440 { 1441 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1442 return __detail::__sph_bessel<__type>(__n, __x); 1443 } 1444 1445 inline float 1446 sph_legendref(unsigned int __l, unsigned int __m, float __theta) 1447 { return __detail::__sph_legendre<float>(__l, __m, __theta); } 1448 1449 inline long double 1450 sph_legendrel(unsigned int __l, unsigned int __m, long double __theta) 1451 { return __detail::__sph_legendre<long double>(__l, __m, __theta); } 1452 1453 /// 5.2.1.22 Spherical associated Legendre functions. 1454 template<typename _Tp> 1455 inline typename __gnu_cxx::__promote<_Tp>::__type 1456 sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta) 1457 { 1458 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1459 return __detail::__sph_legendre<__type>(__l, __m, __theta); 1460 } 1461 1462 inline float 1463 sph_neumannf(unsigned int __n, float __x) 1464 { return __detail::__sph_neumann<float>(__n, __x); } 1465 1466 inline long double 1467 sph_neumannl(unsigned int __n, long double __x) 1468 { return __detail::__sph_neumann<long double>(__n, __x); } 1469 1470 /// 5.2.1.23 Spherical Neumann functions. 1471 template<typename _Tp> 1472 inline typename __gnu_cxx::__promote<_Tp>::__type 1473 sph_neumann(unsigned int __n, _Tp __x) 1474 { 1475 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 1476 return __detail::__sph_neumann<__type>(__n, __x); 1477 } 1478 1479 /* @} */ // tr1_math_spec_func 1480_GLIBCXX_END_NAMESPACE_VERSION 1481} 1482} 1483 1484#endif // _GLIBCXX_TR1_CMATH 1485