1 // TR1 cmath -*- C++ -*-
3 // Copyright (C) 2007, 2009 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file tr1_impl/cmath
26 * This is an internal header file, included by other library headers.
27 * You should not attempt to use it directly.
30 #if _GLIBCXX_USE_C99_MATH_TR1
142 _GLIBCXX_BEGIN_NAMESPACE_TR1
144 #if _GLIBCXX_USE_C99_MATH_TR1
293 #if _GLIBCXX_USE_C99_MATH
294 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
296 /// Function template definitions [8.16.3].
299 using std::fpclassify;
306 using std::isgreater;
307 using std::isgreaterequal;
309 using std::islessequal;
310 using std::islessgreater;
311 using std::isunordered;
315 #if _GLIBCXX_USE_C99_MATH_TR1
317 /// Additional overloads [8.16.4].
322 { return __builtin_acoshf(__x); }
325 acosh(long double __x)
326 { return __builtin_acoshl(__x); }
328 template<typename _Tp>
329 inline typename __gnu_cxx::__promote<_Tp>::__type
332 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
333 return acosh(__type(__x));
340 { return __builtin_asinhf(__x); }
343 asinh(long double __x)
344 { return __builtin_asinhl(__x); }
346 template<typename _Tp>
347 inline typename __gnu_cxx::__promote<_Tp>::__type
350 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
351 return asinh(__type(__x));
359 { return __builtin_atanhf(__x); }
362 atanh(long double __x)
363 { return __builtin_atanhl(__x); }
365 template<typename _Tp>
366 inline typename __gnu_cxx::__promote<_Tp>::__type
369 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
370 return atanh(__type(__x));
375 { return __builtin_cbrtf(__x); }
378 cbrt(long double __x)
379 { return __builtin_cbrtl(__x); }
381 template<typename _Tp>
382 inline typename __gnu_cxx::__promote<_Tp>::__type
385 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
386 return cbrt(__type(__x));
392 copysign(float __x, float __y)
393 { return __builtin_copysignf(__x, __y); }
396 copysign(long double __x, long double __y)
397 { return __builtin_copysignl(__x, __y); }
399 template<typename _Tp, typename _Up>
400 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
401 copysign(_Tp __x, _Up __y)
403 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
404 return copysign(__type(__x), __type(__y));
412 { return __builtin_erff(__x); }
416 { return __builtin_erfl(__x); }
418 template<typename _Tp>
419 inline typename __gnu_cxx::__promote<_Tp>::__type
422 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
423 return erf(__type(__x));
428 { return __builtin_erfcf(__x); }
431 erfc(long double __x)
432 { return __builtin_erfcl(__x); }
434 template<typename _Tp>
435 inline typename __gnu_cxx::__promote<_Tp>::__type
438 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
439 return erfc(__type(__x));
446 { return __builtin_exp2f(__x); }
449 exp2(long double __x)
450 { return __builtin_exp2l(__x); }
452 template<typename _Tp>
453 inline typename __gnu_cxx::__promote<_Tp>::__type
456 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
457 return exp2(__type(__x));
462 { return __builtin_expm1f(__x); }
465 expm1(long double __x)
466 { return __builtin_expm1l(__x); }
468 template<typename _Tp>
469 inline typename __gnu_cxx::__promote<_Tp>::__type
472 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
473 return expm1(__type(__x));
479 fdim(float __x, float __y)
480 { return __builtin_fdimf(__x, __y); }
483 fdim(long double __x, long double __y)
484 { return __builtin_fdiml(__x, __y); }
486 template<typename _Tp, typename _Up>
487 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
488 fdim(_Tp __x, _Up __y)
490 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
491 return fdim(__type(__x), __type(__y));
497 fma(float __x, float __y, float __z)
498 { return __builtin_fmaf(__x, __y, __z); }
501 fma(long double __x, long double __y, long double __z)
502 { return __builtin_fmal(__x, __y, __z); }
504 template<typename _Tp, typename _Up, typename _Vp>
505 inline typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
506 fma(_Tp __x, _Up __y, _Vp __z)
508 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
509 return fma(__type(__x), __type(__y), __type(__z));
513 fmax(float __x, float __y)
514 { return __builtin_fmaxf(__x, __y); }
517 fmax(long double __x, long double __y)
518 { return __builtin_fmaxl(__x, __y); }
520 template<typename _Tp, typename _Up>
521 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
522 fmax(_Tp __x, _Up __y)
524 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
525 return fmax(__type(__x), __type(__y));
529 fmin(float __x, float __y)
530 { return __builtin_fminf(__x, __y); }
533 fmin(long double __x, long double __y)
534 { return __builtin_fminl(__x, __y); }
536 template<typename _Tp, typename _Up>
537 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
538 fmin(_Tp __x, _Up __y)
540 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
541 return fmin(__type(__x), __type(__y));
548 hypot(float __x, float __y)
549 { return __builtin_hypotf(__x, __y); }
552 hypot(long double __x, long double __y)
553 { return __builtin_hypotl(__x, __y); }
555 template<typename _Tp, typename _Up>
556 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
557 hypot(_Tp __x, _Up __y)
559 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
560 return hypot(__type(__x), __type(__y));
565 { return __builtin_ilogbf(__x); }
568 ilogb(long double __x)
569 { return __builtin_ilogbl(__x); }
571 template<typename _Tp>
575 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
576 return ilogb(__type(__x));
583 { return __builtin_lgammaf(__x); }
586 lgamma(long double __x)
587 { return __builtin_lgammal(__x); }
589 template<typename _Tp>
590 inline typename __gnu_cxx::__promote<_Tp>::__type
593 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
594 return lgamma(__type(__x));
599 { return __builtin_llrintf(__x); }
602 llrint(long double __x)
603 { return __builtin_llrintl(__x); }
605 template<typename _Tp>
609 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
610 return llrint(__type(__x));
615 { return __builtin_llroundf(__x); }
618 llround(long double __x)
619 { return __builtin_llroundl(__x); }
621 template<typename _Tp>
625 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
626 return llround(__type(__x));
634 { return __builtin_log1pf(__x); }
637 log1p(long double __x)
638 { return __builtin_log1pl(__x); }
640 template<typename _Tp>
641 inline typename __gnu_cxx::__promote<_Tp>::__type
644 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
645 return log1p(__type(__x));
651 { return __builtin_log2f(__x); }
654 log2(long double __x)
655 { return __builtin_log2l(__x); }
657 template<typename _Tp>
658 inline typename __gnu_cxx::__promote<_Tp>::__type
661 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
662 return log2(__type(__x));
667 { return __builtin_logbf(__x); }
670 logb(long double __x)
671 { return __builtin_logbl(__x); }
673 template<typename _Tp>
674 inline typename __gnu_cxx::__promote<_Tp>::__type
677 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
678 return logb(__type(__x));
683 { return __builtin_lrintf(__x); }
686 lrint(long double __x)
687 { return __builtin_lrintl(__x); }
689 template<typename _Tp>
693 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
694 return lrint(__type(__x));
699 { return __builtin_lroundf(__x); }
702 lround(long double __x)
703 { return __builtin_lroundl(__x); }
705 template<typename _Tp>
709 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
710 return lround(__type(__x));
715 { return __builtin_nearbyintf(__x); }
718 nearbyint(long double __x)
719 { return __builtin_nearbyintl(__x); }
721 template<typename _Tp>
722 inline typename __gnu_cxx::__promote<_Tp>::__type
725 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
726 return nearbyint(__type(__x));
730 nextafter(float __x, float __y)
731 { return __builtin_nextafterf(__x, __y); }
734 nextafter(long double __x, long double __y)
735 { return __builtin_nextafterl(__x, __y); }
737 template<typename _Tp, typename _Up>
738 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
739 nextafter(_Tp __x, _Up __y)
741 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
742 return nextafter(__type(__x), __type(__y));
746 nexttoward(float __x, long double __y)
747 { return __builtin_nexttowardf(__x, __y); }
750 nexttoward(long double __x, long double __y)
751 { return __builtin_nexttowardl(__x, __y); }
753 template<typename _Tp>
754 inline typename __gnu_cxx::__promote<_Tp>::__type
755 nexttoward(_Tp __x, long double __y)
757 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
758 return nexttoward(__type(__x), __y);
761 // DR 550. What should the return type of pow(float,int) be?
762 // NB: C++0x and TR1 != C++03.
766 remainder(float __x, float __y)
767 { return __builtin_remainderf(__x, __y); }
770 remainder(long double __x, long double __y)
771 { return __builtin_remainderl(__x, __y); }
773 template<typename _Tp, typename _Up>
774 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
775 remainder(_Tp __x, _Up __y)
777 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
778 return remainder(__type(__x), __type(__y));
782 remquo(float __x, float __y, int* __pquo)
783 { return __builtin_remquof(__x, __y, __pquo); }
786 remquo(long double __x, long double __y, int* __pquo)
787 { return __builtin_remquol(__x, __y, __pquo); }
789 template<typename _Tp, typename _Up>
790 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
791 remquo(_Tp __x, _Up __y, int* __pquo)
793 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
794 return remquo(__type(__x), __type(__y), __pquo);
799 { return __builtin_rintf(__x); }
802 rint(long double __x)
803 { return __builtin_rintl(__x); }
805 template<typename _Tp>
806 inline typename __gnu_cxx::__promote<_Tp>::__type
809 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
810 return rint(__type(__x));
815 { return __builtin_roundf(__x); }
818 round(long double __x)
819 { return __builtin_roundl(__x); }
821 template<typename _Tp>
822 inline typename __gnu_cxx::__promote<_Tp>::__type
825 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
826 return round(__type(__x));
830 scalbln(float __x, long __ex)
831 { return __builtin_scalblnf(__x, __ex); }
834 scalbln(long double __x, long __ex)
835 { return __builtin_scalblnl(__x, __ex); }
837 template<typename _Tp>
838 inline typename __gnu_cxx::__promote<_Tp>::__type
839 scalbln(_Tp __x, long __ex)
841 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
842 return scalbln(__type(__x), __ex);
846 scalbn(float __x, int __ex)
847 { return __builtin_scalbnf(__x, __ex); }
850 scalbn(long double __x, int __ex)
851 { return __builtin_scalbnl(__x, __ex); }
853 template<typename _Tp>
854 inline typename __gnu_cxx::__promote<_Tp>::__type
855 scalbn(_Tp __x, int __ex)
857 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
858 return scalbn(__type(__x), __ex);
869 { return __builtin_tgammaf(__x); }
872 tgamma(long double __x)
873 { return __builtin_tgammal(__x); }
875 template<typename _Tp>
876 inline typename __gnu_cxx::__promote<_Tp>::__type
879 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
880 return tgamma(__type(__x));
885 { return __builtin_truncf(__x); }
888 trunc(long double __x)
889 { return __builtin_truncl(__x); }
891 template<typename _Tp>
892 inline typename __gnu_cxx::__promote<_Tp>::__type
895 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
896 return trunc(__type(__x));
901 _GLIBCXX_END_NAMESPACE_TR1