1 // TR1 cmath -*- C++ -*-
3 // Copyright (C) 2006 Free Software Foundation, Inc.
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)
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.
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,
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.
31 * This is a TR1 C++ Library header.
37 #include <bits/c++config.h>
39 #include <tr1/common.h>
41 #if _GLIBCXX_USE_C99_MATH_TR1
151 // namespace std::tr1
154 _GLIBCXX_BEGIN_NAMESPACE(tr1)
156 #if _GLIBCXX_USE_C99_MATH_TR1
305 #if _GLIBCXX_USE_C99_MATH
306 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
308 /// @brief Function template definitions [8.16.3].
312 using std::fpclassify;
319 using std::isgreater;
320 using std::isgreaterequal;
322 using std::islessequal;
323 using std::islessgreater;
324 using std::isunordered;
328 #if _GLIBCXX_USE_C99_MATH_TR1
330 /// @brief Additional overloads [8.16.4].
336 { return __builtin_acoshf(__x); }
339 acosh(long double __x)
340 { return __builtin_acoshl(__x); }
342 template<typename _Tp>
343 inline typename __promote<_Tp>::__type
346 typedef typename __promote<_Tp>::__type __type;
347 return acosh(__type(__x));
354 { return __builtin_asinhf(__x); }
357 asinh(long double __x)
358 { return __builtin_asinhl(__x); }
360 template<typename _Tp>
361 inline typename __promote<_Tp>::__type
364 typedef typename __promote<_Tp>::__type __type;
365 return asinh(__type(__x));
370 // Workaround for c++/21682.
373 template<typename _Tp, typename _Up>
375 __gnu_cxx::__enable_if<std::__is_floating<_Tp>::__value
376 || std::__is_floating<_Up>::__value,
378 std::tr1::__promote_2<_Tp, _Up>::__type>::__type
379 atan2(_Tp __y, _Up __x)
381 typedef typename std::tr1::__promote_2<_Tp, _Up>::__type __type;
382 return std::atan2(__type(__y), __type(__x));
384 } // namespace __detail
387 using __detail::atan2;
391 { return __builtin_atanhf(__x); }
394 atanh(long double __x)
395 { return __builtin_atanhl(__x); }
397 template<typename _Tp>
398 inline typename __promote<_Tp>::__type
401 typedef typename __promote<_Tp>::__type __type;
402 return atanh(__type(__x));
407 { return __builtin_cbrtf(__x); }
410 cbrt(long double __x)
411 { return __builtin_cbrtl(__x); }
413 template<typename _Tp>
414 inline typename __promote<_Tp>::__type
417 typedef typename __promote<_Tp>::__type __type;
418 return cbrt(__type(__x));
424 copysign(float __x, float __y)
425 { return __builtin_copysignf(__x, __y); }
428 copysign(long double __x, long double __y)
429 { return __builtin_copysignl(__x, __y); }
431 template<typename _Tp, typename _Up>
432 inline typename __promote_2<_Tp, _Up>::__type
433 copysign(_Tp __x, _Up __y)
435 typedef typename __promote_2<_Tp, _Up>::__type __type;
436 return copysign(__type(__x), __type(__y));
444 { return __builtin_erff(__x); }
448 { return __builtin_erfl(__x); }
450 template<typename _Tp>
451 inline typename __promote<_Tp>::__type
454 typedef typename __promote<_Tp>::__type __type;
455 return erf(__type(__x));
460 { return __builtin_erfcf(__x); }
463 erfc(long double __x)
464 { return __builtin_erfcl(__x); }
466 template<typename _Tp>
467 inline typename __promote<_Tp>::__type
470 typedef typename __promote<_Tp>::__type __type;
471 return erfc(__type(__x));
478 { return __builtin_exp2f(__x); }
481 exp2(long double __x)
482 { return __builtin_exp2l(__x); }
484 template<typename _Tp>
485 inline typename __promote<_Tp>::__type
488 typedef typename __promote<_Tp>::__type __type;
489 return exp2(__type(__x));
494 { return __builtin_expm1f(__x); }
497 expm1(long double __x)
498 { return __builtin_expm1l(__x); }
500 template<typename _Tp>
501 inline typename __promote<_Tp>::__type
504 typedef typename __promote<_Tp>::__type __type;
505 return expm1(__type(__x));
511 fdim(float __x, float __y)
512 { return __builtin_fdimf(__x, __y); }
515 fdim(long double __x, long double __y)
516 { return __builtin_fdiml(__x, __y); }
518 template<typename _Tp, typename _Up>
519 inline typename __promote_2<_Tp, _Up>::__type
520 fdim(_Tp __x, _Up __y)
522 typedef typename __promote_2<_Tp, _Up>::__type __type;
523 return fdim(__type(__x), __type(__y));
529 fma(float __x, float __y, float __z)
530 { return __builtin_fmaf(__x, __y, __z); }
533 fma(long double __x, long double __y, long double __z)
534 { return __builtin_fmal(__x, __y, __z); }
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)
540 typedef typename __promote_3<_Tp, _Up, _Vp>::__type __type;
541 return fma(__type(__x), __type(__y), __type(__z));
545 fmax(float __x, float __y)
546 { return __builtin_fmaxf(__x, __y); }
549 fmax(long double __x, long double __y)
550 { return __builtin_fmaxl(__x, __y); }
552 template<typename _Tp, typename _Up>
553 inline typename __promote_2<_Tp, _Up>::__type
554 fmax(_Tp __x, _Up __y)
556 typedef typename __promote_2<_Tp, _Up>::__type __type;
557 return fmax(__type(__x), __type(__y));
561 fmin(float __x, float __y)
562 { return __builtin_fminf(__x, __y); }
565 fmin(long double __x, long double __y)
566 { return __builtin_fminl(__x, __y); }
568 template<typename _Tp, typename _Up>
569 inline typename __promote_2<_Tp, _Up>::__type
570 fmin(_Tp __x, _Up __y)
572 typedef typename __promote_2<_Tp, _Up>::__type __type;
573 return fmin(__type(__x), __type(__y));
580 hypot(float __x, float __y)
581 { return __builtin_hypotf(__x, __y); }
584 hypot(long double __x, long double __y)
585 { return __builtin_hypotl(__x, __y); }
587 template<typename _Tp, typename _Up>
588 inline typename __promote_2<_Tp, _Up>::__type
589 hypot(_Tp __x, _Up __y)
591 typedef typename __promote_2<_Tp, _Up>::__type __type;
592 return hypot(__type(__x), __type(__y));
597 { return __builtin_ilogbf(__x); }
600 ilogb(long double __x)
601 { return __builtin_ilogbl(__x); }
603 template<typename _Tp>
607 typedef typename __promote<_Tp>::__type __type;
608 return ilogb(__type(__x));
615 { return __builtin_lgammaf(__x); }
618 lgamma(long double __x)
619 { return __builtin_lgammal(__x); }
621 template<typename _Tp>
622 inline typename __promote<_Tp>::__type
625 typedef typename __promote<_Tp>::__type __type;
626 return lgamma(__type(__x));
631 { return __builtin_llrintf(__x); }
634 llrint(long double __x)
635 { return __builtin_llrintl(__x); }
637 template<typename _Tp>
641 typedef typename __promote<_Tp>::__type __type;
642 return llrint(__type(__x));
647 { return __builtin_llroundf(__x); }
650 llround(long double __x)
651 { return __builtin_llroundl(__x); }
653 template<typename _Tp>
657 typedef typename __promote<_Tp>::__type __type;
658 return llround(__type(__x));
666 { return __builtin_log1pf(__x); }
669 log1p(long double __x)
670 { return __builtin_log1pl(__x); }
672 template<typename _Tp>
673 inline typename __promote<_Tp>::__type
676 typedef typename __promote<_Tp>::__type __type;
677 return log1p(__type(__x));
683 { return __builtin_log2f(__x); }
686 log2(long double __x)
687 { return __builtin_log2l(__x); }
689 template<typename _Tp>
690 inline typename __promote<_Tp>::__type
693 typedef typename __promote<_Tp>::__type __type;
694 return log2(__type(__x));
699 { return __builtin_logbf(__x); }
702 logb(long double __x)
703 { return __builtin_logbl(__x); }
705 template<typename _Tp>
706 inline typename __promote<_Tp>::__type
709 typedef typename __promote<_Tp>::__type __type;
710 return logb(__type(__x));
715 { return __builtin_lrintf(__x); }
718 lrint(long double __x)
719 { return __builtin_lrintl(__x); }
721 template<typename _Tp>
725 typedef typename __promote<_Tp>::__type __type;
726 return lrint(__type(__x));
731 { return __builtin_lroundf(__x); }
734 lround(long double __x)
735 { return __builtin_lroundl(__x); }
737 template<typename _Tp>
741 typedef typename __promote<_Tp>::__type __type;
742 return lround(__type(__x));
747 { return __builtin_nearbyintf(__x); }
750 nearbyint(long double __x)
751 { return __builtin_nearbyintl(__x); }
753 template<typename _Tp>
754 inline typename __promote<_Tp>::__type
757 typedef typename __promote<_Tp>::__type __type;
758 return nearbyint(__type(__x));
762 nextafter(float __x, float __y)
763 { return __builtin_nextafterf(__x, __y); }
766 nextafter(long double __x, long double __y)
767 { return __builtin_nextafterl(__x, __y); }
769 template<typename _Tp, typename _Up>
770 inline typename __promote_2<_Tp, _Up>::__type
771 nextafter(_Tp __x, _Up __y)
773 typedef typename __promote_2<_Tp, _Up>::__type __type;
774 return nextafter(__type(__x), __type(__y));
778 nexttoward(float __x, long double __y)
779 { return __builtin_nexttowardf(__x, __y); }
782 nexttoward(long double __x, long double __y)
783 { return __builtin_nexttowardl(__x, __y); }
785 template<typename _Tp>
786 inline typename __promote<_Tp>::__type
787 nexttoward(_Tp __x, long double __y)
789 typedef typename __promote<_Tp>::__type __type;
790 return nexttoward(__type(__x), __y);
796 template<typename _Tp, typename _Up>
797 inline typename __promote_2<_Tp, _Up>::__type
798 pow(_Tp __x, _Up __y)
800 typedef typename __promote_2<_Tp, _Up>::__type __type;
801 return pow(__type(__x), __type(__y));
805 remainder(float __x, float __y)
806 { return __builtin_remainderf(__x, __y); }
809 remainder(long double __x, long double __y)
810 { return __builtin_remainderl(__x, __y); }
812 template<typename _Tp, typename _Up>
813 inline typename __promote_2<_Tp, _Up>::__type
814 remainder(_Tp __x, _Up __y)
816 typedef typename __promote_2<_Tp, _Up>::__type __type;
817 return remainder(__type(__x), __type(__y));
821 remquo(float __x, float __y, int* __pquo)
822 { return __builtin_remquof(__x, __y, __pquo); }
825 remquo(long double __x, long double __y, int* __pquo)
826 { return __builtin_remquol(__x, __y, __pquo); }
828 template<typename _Tp, typename _Up>
829 inline typename __promote_2<_Tp, _Up>::__type
830 remquo(_Tp __x, _Up __y, int* __pquo)
832 typedef typename __promote_2<_Tp, _Up>::__type __type;
833 return remquo(__type(__x), __type(__y), __pquo);
838 { return __builtin_rintf(__x); }
841 rint(long double __x)
842 { return __builtin_rintl(__x); }
844 template<typename _Tp>
845 inline typename __promote<_Tp>::__type
848 typedef typename __promote<_Tp>::__type __type;
849 return rint(__type(__x));
854 { return __builtin_roundf(__x); }
857 round(long double __x)
858 { return __builtin_roundl(__x); }
860 template<typename _Tp>
861 inline typename __promote<_Tp>::__type
864 typedef typename __promote<_Tp>::__type __type;
865 return round(__type(__x));
869 scalbln(float __x, long __ex)
870 { return __builtin_scalblnf(__x, __ex); }
873 scalbln(long double __x, long __ex)
874 { return __builtin_scalblnl(__x, __ex); }
876 template<typename _Tp>
877 inline typename __promote<_Tp>::__type
878 scalbln(_Tp __x, long __ex)
880 typedef typename __promote<_Tp>::__type __type;
881 return scalbln(__type(__x), __ex);
885 scalbn(float __x, int __ex)
886 { return __builtin_scalbnf(__x, __ex); }
889 scalbn(long double __x, int __ex)
890 { return __builtin_scalbnl(__x, __ex); }
892 template<typename _Tp>
893 inline typename __promote<_Tp>::__type
894 scalbn(_Tp __x, int __ex)
896 typedef typename __promote<_Tp>::__type __type;
897 return scalbn(__type(__x), __ex);
908 { return __builtin_tgammaf(__x); }
911 tgamma(long double __x)
912 { return __builtin_tgammal(__x); }
914 template<typename _Tp>
915 inline typename __promote<_Tp>::__type
918 typedef typename __promote<_Tp>::__type __type;
919 return tgamma(__type(__x));
924 { return __builtin_truncf(__x); }
927 trunc(long double __x)
928 { return __builtin_truncl(__x); }
930 template<typename _Tp>
931 inline typename __promote<_Tp>::__type
934 typedef typename __promote<_Tp>::__type __type;
935 return trunc(__type(__x));
940 _GLIBCXX_END_NAMESPACE