1// TR1 cmath -*- C++ -*- 2 3// Copyright (C) 2006 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 2, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING. If not, write to the Free 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19// USA. 20 21// As a special exception, you may use this file as part of a free software 22// library without restriction. Specifically, if other files instantiate 23// templates or use macros or inline functions from this file, or you compile 24// this file and link it with other files to produce an executable, this 25// file does not by itself cause the resulting executable to be covered by 26// the GNU General Public License. This exception does not however 27// invalidate any other reasons why the executable file might be covered by 28// the GNU General Public License. 29 30/** @file tr1/cmath 31 * This is a TR1 C++ Library header. 32 */ 33 34#ifndef _TR1_CMATH 35#define _TR1_CMATH 1 36 37#include <bits/c++config.h> 38#include <cmath> 39#include <tr1/common.h> 40 41#if _GLIBCXX_USE_C99_MATH_TR1 42 43#undef acosh 44#undef acoshf 45#undef acoshl 46#undef asinh 47#undef asinhf 48#undef asinhl 49#undef atanh 50#undef atanhf 51#undef atanhl 52#undef cbrt 53#undef cbrtf 54#undef cbrtl 55#undef copysign 56#undef copysignf 57#undef copysignl 58#undef erf 59#undef erff 60#undef erfl 61#undef erfc 62#undef erfcf 63#undef erfcl 64#undef exp2 65#undef exp2f 66#undef exp2l 67#undef expm1 68#undef expm1f 69#undef expm1l 70#undef fdim 71#undef fdimf 72#undef fdiml 73#undef fma 74#undef fmaf 75#undef fmal 76#undef fmax 77#undef fmaxf 78#undef fmaxl 79#undef fmin 80#undef fminf 81#undef fminl 82#undef hypot 83#undef hypotf 84#undef hypotl 85#undef ilogb 86#undef ilogbf 87#undef ilogbl 88#undef lgamma 89#undef lgammaf 90#undef lgammal 91#undef llrint 92#undef llrintf 93#undef llrintl 94#undef llround 95#undef llroundf 96#undef llroundl 97#undef log1p 98#undef log1pf 99#undef log1pl 100#undef log2 101#undef log2f 102#undef log2l 103#undef logb 104#undef logbf 105#undef logbl 106#undef lrint 107#undef lrintf 108#undef lrintl 109#undef lround 110#undef lroundf 111#undef lroundl 112#undef nan 113#undef nanf 114#undef nanl 115#undef nearbyint 116#undef nearbyintf 117#undef nearbyintl 118#undef nextafter 119#undef nextafterf 120#undef nextafterl 121#undef nexttoward 122#undef nexttowardf 123#undef nexttowardl 124#undef remainder 125#undef remainderf 126#undef remainderl 127#undef remquo 128#undef remquo 129#undef remquo 130#undef rint 131#undef rintf 132#undef rintl 133#undef round 134#undef roundf 135#undef roundl 136#undef scalbln 137#undef scalblnf 138#undef scalblnl 139#undef scalbn 140#undef scalbnf 141#undef scalbnl 142#undef tgamma 143#undef tgammaf 144#undef tgammal 145#undef trunc 146#undef truncf 147#undef truncl 148 149#endif 150 151// namespace std::tr1 152namespace std 153{ 154_GLIBCXX_BEGIN_NAMESPACE(tr1) 155 156#if _GLIBCXX_USE_C99_MATH_TR1 157 158 // types 159 using ::double_t; 160 using ::float_t; 161 162 // functions 163 using ::acosh; 164 using ::acoshf; 165 using ::acoshl; 166 167 using ::asinh; 168 using ::asinhf; 169 using ::asinhl; 170 171 using ::atanh; 172 using ::atanhf; 173 using ::atanhl; 174 175 using ::cbrt; 176 using ::cbrtf; 177 using ::cbrtl; 178 179 using ::copysign; 180 using ::copysignf; 181 using ::copysignl; 182 183 using ::erf; 184 using ::erff; 185 using ::erfl; 186 187 using ::erfc; 188 using ::erfcf; 189 using ::erfcl; 190 191 using ::exp2; 192 using ::exp2f; 193 using ::exp2l; 194 195 using ::expm1; 196 using ::expm1f; 197 using ::expm1l; 198 199 using ::fdim; 200 using ::fdimf; 201 using ::fdiml; 202 203 using ::fma; 204 using ::fmaf; 205 using ::fmal; 206 207 using ::fmax; 208 using ::fmaxf; 209 using ::fmaxl; 210 211 using ::fmin; 212 using ::fminf; 213 using ::fminl; 214 215 using ::hypot; 216 using ::hypotf; 217 using ::hypotl; 218 219 using ::ilogb; 220 using ::ilogbf; 221 using ::ilogbl; 222 223 using ::lgamma; 224 using ::lgammaf; 225 using ::lgammal; 226 227 using ::llrint; 228 using ::llrintf; 229 using ::llrintl; 230 231 using ::llround; 232 using ::llroundf; 233 using ::llroundl; 234 235 using ::log1p; 236 using ::log1pf; 237 using ::log1pl; 238 239 using ::log2; 240 using ::log2f; 241 using ::log2l; 242 243 using ::logb; 244 using ::logbf; 245 using ::logbl; 246 247 using ::lrint; 248 using ::lrintf; 249 using ::lrintl; 250 251 using ::lround; 252 using ::lroundf; 253 using ::lroundl; 254 255 using ::nan; 256 using ::nanf; 257 using ::nanl; 258 259 using ::nearbyint; 260 using ::nearbyintf; 261 using ::nearbyintl; 262 263 using ::nextafter; 264 using ::nextafterf; 265 using ::nextafterl; 266 267 using ::nexttoward; 268 using ::nexttowardf; 269 using ::nexttowardl; 270 271 using ::remainder; 272 using ::remainderf; 273 using ::remainderl; 274 275 using ::remquo; 276 using ::remquo; 277 using ::remquo; 278 279 using ::rint; 280 using ::rintf; 281 using ::rintl; 282 283 using ::round; 284 using ::roundf; 285 using ::roundl; 286 287 using ::scalbln; 288 using ::scalblnf; 289 using ::scalblnl; 290 291 using ::scalbn; 292 using ::scalbnf; 293 using ::scalbnl; 294 295 using ::tgamma; 296 using ::tgammaf; 297 using ::tgammal; 298 299 using ::trunc; 300 using ::truncf; 301 using ::truncl; 302 303#endif 304 305#if _GLIBCXX_USE_C99_MATH 306#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 307 308 /// @brief Function template definitions [8.16.3]. 309 // 310 using std::signbit; 311 312 using std::fpclassify; 313 314 using std::isfinite; 315 using std::isinf; 316 using std::isnan; 317 using std::isnormal; 318 319 using std::isgreater; 320 using std::isgreaterequal; 321 using std::isless; 322 using std::islessequal; 323 using std::islessgreater; 324 using std::isunordered; 325#endif 326#endif 327 328#if _GLIBCXX_USE_C99_MATH_TR1 329 330 /// @brief Additional overloads [8.16.4]. 331 // 332 using std::acos; 333 334 inline float 335 acosh(float __x) 336 { return __builtin_acoshf(__x); } 337 338 inline long double 339 acosh(long double __x) 340 { return __builtin_acoshl(__x); } 341 342 template<typename _Tp> 343 inline typename __promote<_Tp>::__type 344 acosh(_Tp __x) 345 { 346 typedef typename __promote<_Tp>::__type __type; 347 return acosh(__type(__x)); 348 } 349 350 using std::asin; 351 352 inline float 353 asinh(float __x) 354 { return __builtin_asinhf(__x); } 355 356 inline long double 357 asinh(long double __x) 358 { return __builtin_asinhl(__x); } 359 360 template<typename _Tp> 361 inline typename __promote<_Tp>::__type 362 asinh(_Tp __x) 363 { 364 typedef typename __promote<_Tp>::__type __type; 365 return asinh(__type(__x)); 366 } 367 368 using std::atan; 369 370 // Workaround for c++/21682. 371 namespace __detail 372 { 373 template<typename _Tp, typename _Up> 374 inline typename 375 __gnu_cxx::__enable_if<std::__is_floating<_Tp>::__value 376 || std::__is_floating<_Up>::__value, 377 typename 378 std::tr1::__promote_2<_Tp, _Up>::__type>::__type 379 atan2(_Tp __y, _Up __x) 380 { 381 typedef typename std::tr1::__promote_2<_Tp, _Up>::__type __type; 382 return std::atan2(__type(__y), __type(__x)); 383 } 384 } // namespace __detail 385 386 using std::atan2; 387 using __detail::atan2; 388 389 inline float 390 atanh(float __x) 391 { return __builtin_atanhf(__x); } 392 393 inline long double 394 atanh(long double __x) 395 { return __builtin_atanhl(__x); } 396 397 template<typename _Tp> 398 inline typename __promote<_Tp>::__type 399 atanh(_Tp __x) 400 { 401 typedef typename __promote<_Tp>::__type __type; 402 return atanh(__type(__x)); 403 } 404 405 inline float 406 cbrt(float __x) 407 { return __builtin_cbrtf(__x); } 408 409 inline long double 410 cbrt(long double __x) 411 { return __builtin_cbrtl(__x); } 412 413 template<typename _Tp> 414 inline typename __promote<_Tp>::__type 415 cbrt(_Tp __x) 416 { 417 typedef typename __promote<_Tp>::__type __type; 418 return cbrt(__type(__x)); 419 } 420 421 using std::ceil; 422 423 inline float 424 copysign(float __x, float __y) 425 { return __builtin_copysignf(__x, __y); } 426 427 inline long double 428 copysign(long double __x, long double __y) 429 { return __builtin_copysignl(__x, __y); } 430 431 template<typename _Tp, typename _Up> 432 inline typename __promote_2<_Tp, _Up>::__type 433 copysign(_Tp __x, _Up __y) 434 { 435 typedef typename __promote_2<_Tp, _Up>::__type __type; 436 return copysign(__type(__x), __type(__y)); 437 } 438 439 using std::cos; 440 using std::cosh; 441 442 inline float 443 erf(float __x) 444 { return __builtin_erff(__x); } 445 446 inline long double 447 erf(long double __x) 448 { return __builtin_erfl(__x); } 449 450 template<typename _Tp> 451 inline typename __promote<_Tp>::__type 452 erf(_Tp __x) 453 { 454 typedef typename __promote<_Tp>::__type __type; 455 return erf(__type(__x)); 456 } 457 458 inline float 459 erfc(float __x) 460 { return __builtin_erfcf(__x); } 461 462 inline long double 463 erfc(long double __x) 464 { return __builtin_erfcl(__x); } 465 466 template<typename _Tp> 467 inline typename __promote<_Tp>::__type 468 erfc(_Tp __x) 469 { 470 typedef typename __promote<_Tp>::__type __type; 471 return erfc(__type(__x)); 472 } 473 474 using std::exp; 475 476 inline float 477 exp2(float __x) 478 { return __builtin_exp2f(__x); } 479 480 inline long double 481 exp2(long double __x) 482 { return __builtin_exp2l(__x); } 483 484 template<typename _Tp> 485 inline typename __promote<_Tp>::__type 486 exp2(_Tp __x) 487 { 488 typedef typename __promote<_Tp>::__type __type; 489 return exp2(__type(__x)); 490 } 491 492 inline float 493 expm1(float __x) 494 { return __builtin_expm1f(__x); } 495 496 inline long double 497 expm1(long double __x) 498 { return __builtin_expm1l(__x); } 499 500 template<typename _Tp> 501 inline typename __promote<_Tp>::__type 502 expm1(_Tp __x) 503 { 504 typedef typename __promote<_Tp>::__type __type; 505 return expm1(__type(__x)); 506 } 507 508 using std::fabs; 509 510 inline float 511 fdim(float __x, float __y) 512 { return __builtin_fdimf(__x, __y); } 513 514 inline long double 515 fdim(long double __x, long double __y) 516 { return __builtin_fdiml(__x, __y); } 517 518 template<typename _Tp, typename _Up> 519 inline typename __promote_2<_Tp, _Up>::__type 520 fdim(_Tp __x, _Up __y) 521 { 522 typedef typename __promote_2<_Tp, _Up>::__type __type; 523 return fdim(__type(__x), __type(__y)); 524 } 525 526 using std::floor; 527 528 inline float 529 fma(float __x, float __y, float __z) 530 { return __builtin_fmaf(__x, __y, __z); } 531 532 inline long double 533 fma(long double __x, long double __y, long double __z) 534 { return __builtin_fmal(__x, __y, __z); } 535 536 template<typename _Tp, typename _Up, typename _Vp> 537 inline typename __promote_3<_Tp, _Up, _Vp>::__type 538 fma(_Tp __x, _Up __y, _Vp __z) 539 { 540 typedef typename __promote_3<_Tp, _Up, _Vp>::__type __type; 541 return fma(__type(__x), __type(__y), __type(__z)); 542 } 543 544 inline float 545 fmax(float __x, float __y) 546 { return __builtin_fmaxf(__x, __y); } 547 548 inline long double 549 fmax(long double __x, long double __y) 550 { return __builtin_fmaxl(__x, __y); } 551 552 template<typename _Tp, typename _Up> 553 inline typename __promote_2<_Tp, _Up>::__type 554 fmax(_Tp __x, _Up __y) 555 { 556 typedef typename __promote_2<_Tp, _Up>::__type __type; 557 return fmax(__type(__x), __type(__y)); 558 } 559 560 inline float 561 fmin(float __x, float __y) 562 { return __builtin_fminf(__x, __y); } 563 564 inline long double 565 fmin(long double __x, long double __y) 566 { return __builtin_fminl(__x, __y); } 567 568 template<typename _Tp, typename _Up> 569 inline typename __promote_2<_Tp, _Up>::__type 570 fmin(_Tp __x, _Up __y) 571 { 572 typedef typename __promote_2<_Tp, _Up>::__type __type; 573 return fmin(__type(__x), __type(__y)); 574 } 575 576 using std::fmod; 577 using std::frexp; 578 579 inline float 580 hypot(float __x, float __y) 581 { return __builtin_hypotf(__x, __y); } 582 583 inline long double 584 hypot(long double __x, long double __y) 585 { return __builtin_hypotl(__x, __y); } 586 587 template<typename _Tp, typename _Up> 588 inline typename __promote_2<_Tp, _Up>::__type 589 hypot(_Tp __x, _Up __y) 590 { 591 typedef typename __promote_2<_Tp, _Up>::__type __type; 592 return hypot(__type(__x), __type(__y)); 593 } 594 595 inline int 596 ilogb(float __x) 597 { return __builtin_ilogbf(__x); } 598 599 inline int 600 ilogb(long double __x) 601 { return __builtin_ilogbl(__x); } 602 603 template<typename _Tp> 604 inline int 605 ilogb(_Tp __x) 606 { 607 typedef typename __promote<_Tp>::__type __type; 608 return ilogb(__type(__x)); 609 } 610 611 using std::ldexp; 612 613 inline float 614 lgamma(float __x) 615 { return __builtin_lgammaf(__x); } 616 617 inline long double 618 lgamma(long double __x) 619 { return __builtin_lgammal(__x); } 620 621 template<typename _Tp> 622 inline typename __promote<_Tp>::__type 623 lgamma(_Tp __x) 624 { 625 typedef typename __promote<_Tp>::__type __type; 626 return lgamma(__type(__x)); 627 } 628 629 inline long long 630 llrint(float __x) 631 { return __builtin_llrintf(__x); } 632 633 inline long long 634 llrint(long double __x) 635 { return __builtin_llrintl(__x); } 636 637 template<typename _Tp> 638 inline long long 639 llrint(_Tp __x) 640 { 641 typedef typename __promote<_Tp>::__type __type; 642 return llrint(__type(__x)); 643 } 644 645 inline long long 646 llround(float __x) 647 { return __builtin_llroundf(__x); } 648 649 inline long long 650 llround(long double __x) 651 { return __builtin_llroundl(__x); } 652 653 template<typename _Tp> 654 inline long long 655 llround(_Tp __x) 656 { 657 typedef typename __promote<_Tp>::__type __type; 658 return llround(__type(__x)); 659 } 660 661 using std::log; 662 using std::log10; 663 664 inline float 665 log1p(float __x) 666 { return __builtin_log1pf(__x); } 667 668 inline long double 669 log1p(long double __x) 670 { return __builtin_log1pl(__x); } 671 672 template<typename _Tp> 673 inline typename __promote<_Tp>::__type 674 log1p(_Tp __x) 675 { 676 typedef typename __promote<_Tp>::__type __type; 677 return log1p(__type(__x)); 678 } 679 680 // DR 568. 681 inline float 682 log2(float __x) 683 { return __builtin_log2f(__x); } 684 685 inline long double 686 log2(long double __x) 687 { return __builtin_log2l(__x); } 688 689 template<typename _Tp> 690 inline typename __promote<_Tp>::__type 691 log2(_Tp __x) 692 { 693 typedef typename __promote<_Tp>::__type __type; 694 return log2(__type(__x)); 695 } 696 697 inline float 698 logb(float __x) 699 { return __builtin_logbf(__x); } 700 701 inline long double 702 logb(long double __x) 703 { return __builtin_logbl(__x); } 704 705 template<typename _Tp> 706 inline typename __promote<_Tp>::__type 707 logb(_Tp __x) 708 { 709 typedef typename __promote<_Tp>::__type __type; 710 return logb(__type(__x)); 711 } 712 713 inline long 714 lrint(float __x) 715 { return __builtin_lrintf(__x); } 716 717 inline long 718 lrint(long double __x) 719 { return __builtin_lrintl(__x); } 720 721 template<typename _Tp> 722 inline long 723 lrint(_Tp __x) 724 { 725 typedef typename __promote<_Tp>::__type __type; 726 return lrint(__type(__x)); 727 } 728 729 inline long 730 lround(float __x) 731 { return __builtin_lroundf(__x); } 732 733 inline long 734 lround(long double __x) 735 { return __builtin_lroundl(__x); } 736 737 template<typename _Tp> 738 inline long 739 lround(_Tp __x) 740 { 741 typedef typename __promote<_Tp>::__type __type; 742 return lround(__type(__x)); 743 } 744 745 inline float 746 nearbyint(float __x) 747 { return __builtin_nearbyintf(__x); } 748 749 inline long double 750 nearbyint(long double __x) 751 { return __builtin_nearbyintl(__x); } 752 753 template<typename _Tp> 754 inline typename __promote<_Tp>::__type 755 nearbyint(_Tp __x) 756 { 757 typedef typename __promote<_Tp>::__type __type; 758 return nearbyint(__type(__x)); 759 } 760 761 inline float 762 nextafter(float __x, float __y) 763 { return __builtin_nextafterf(__x, __y); } 764 765 inline long double 766 nextafter(long double __x, long double __y) 767 { return __builtin_nextafterl(__x, __y); } 768 769 template<typename _Tp, typename _Up> 770 inline typename __promote_2<_Tp, _Up>::__type 771 nextafter(_Tp __x, _Up __y) 772 { 773 typedef typename __promote_2<_Tp, _Up>::__type __type; 774 return nextafter(__type(__x), __type(__y)); 775 } 776 777 inline float 778 nexttoward(float __x, long double __y) 779 { return __builtin_nexttowardf(__x, __y); } 780 781 inline long double 782 nexttoward(long double __x, long double __y) 783 { return __builtin_nexttowardl(__x, __y); } 784 785 template<typename _Tp> 786 inline typename __promote<_Tp>::__type 787 nexttoward(_Tp __x, long double __y) 788 { 789 typedef typename __promote<_Tp>::__type __type; 790 return nexttoward(__type(__x), __y); 791 } 792 793 using std::pow; 794 795 // DR 550. 796 template<typename _Tp, typename _Up> 797 inline typename __promote_2<_Tp, _Up>::__type 798 pow(_Tp __x, _Up __y) 799 { 800 typedef typename __promote_2<_Tp, _Up>::__type __type; 801 return pow(__type(__x), __type(__y)); 802 } 803 804 inline float 805 remainder(float __x, float __y) 806 { return __builtin_remainderf(__x, __y); } 807 808 inline long double 809 remainder(long double __x, long double __y) 810 { return __builtin_remainderl(__x, __y); } 811 812 template<typename _Tp, typename _Up> 813 inline typename __promote_2<_Tp, _Up>::__type 814 remainder(_Tp __x, _Up __y) 815 { 816 typedef typename __promote_2<_Tp, _Up>::__type __type; 817 return remainder(__type(__x), __type(__y)); 818 } 819 820 inline float 821 remquo(float __x, float __y, int* __pquo) 822 { return __builtin_remquof(__x, __y, __pquo); } 823 824 inline long double 825 remquo(long double __x, long double __y, int* __pquo) 826 { return __builtin_remquol(__x, __y, __pquo); } 827 828 template<typename _Tp, typename _Up> 829 inline typename __promote_2<_Tp, _Up>::__type 830 remquo(_Tp __x, _Up __y, int* __pquo) 831 { 832 typedef typename __promote_2<_Tp, _Up>::__type __type; 833 return remquo(__type(__x), __type(__y), __pquo); 834 } 835 836 inline float 837 rint(float __x) 838 { return __builtin_rintf(__x); } 839 840 inline long double 841 rint(long double __x) 842 { return __builtin_rintl(__x); } 843 844 template<typename _Tp> 845 inline typename __promote<_Tp>::__type 846 rint(_Tp __x) 847 { 848 typedef typename __promote<_Tp>::__type __type; 849 return rint(__type(__x)); 850 } 851 852 inline float 853 round(float __x) 854 { return __builtin_roundf(__x); } 855 856 inline long double 857 round(long double __x) 858 { return __builtin_roundl(__x); } 859 860 template<typename _Tp> 861 inline typename __promote<_Tp>::__type 862 round(_Tp __x) 863 { 864 typedef typename __promote<_Tp>::__type __type; 865 return round(__type(__x)); 866 } 867 868 inline float 869 scalbln(float __x, long __ex) 870 { return __builtin_scalblnf(__x, __ex); } 871 872 inline long double 873 scalbln(long double __x, long __ex) 874 { return __builtin_scalblnl(__x, __ex); } 875 876 template<typename _Tp> 877 inline typename __promote<_Tp>::__type 878 scalbln(_Tp __x, long __ex) 879 { 880 typedef typename __promote<_Tp>::__type __type; 881 return scalbln(__type(__x), __ex); 882 } 883 884 inline float 885 scalbn(float __x, int __ex) 886 { return __builtin_scalbnf(__x, __ex); } 887 888 inline long double 889 scalbn(long double __x, int __ex) 890 { return __builtin_scalbnl(__x, __ex); } 891 892 template<typename _Tp> 893 inline typename __promote<_Tp>::__type 894 scalbn(_Tp __x, int __ex) 895 { 896 typedef typename __promote<_Tp>::__type __type; 897 return scalbn(__type(__x), __ex); 898 } 899 900 using std::sin; 901 using std::sinh; 902 using std::sqrt; 903 using std::tan; 904 using std::tanh; 905 906 inline float 907 tgamma(float __x) 908 { return __builtin_tgammaf(__x); } 909 910 inline long double 911 tgamma(long double __x) 912 { return __builtin_tgammal(__x); } 913 914 template<typename _Tp> 915 inline typename __promote<_Tp>::__type 916 tgamma(_Tp __x) 917 { 918 typedef typename __promote<_Tp>::__type __type; 919 return tgamma(__type(__x)); 920 } 921 922 inline float 923 trunc(float __x) 924 { return __builtin_truncf(__x); } 925 926 inline long double 927 trunc(long double __x) 928 { return __builtin_truncl(__x); } 929 930 template<typename _Tp> 931 inline typename __promote<_Tp>::__type 932 trunc(_Tp __x) 933 { 934 typedef typename __promote<_Tp>::__type __type; 935 return trunc(__type(__x)); 936 } 937 938#endif 939 940_GLIBCXX_END_NAMESPACE 941} 942 943#endif 944