1 // TR1 cmath -*- C++ -*-
3 // Copyright (C) 2007 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.
30 /** @file tr1_impl/cmath
31 * This is an internal header file, included by other library headers.
32 * You should not attempt to use it directly.
35 #if _GLIBCXX_USE_C99_MATH_TR1
147 _GLIBCXX_BEGIN_NAMESPACE_TR1
149 #if _GLIBCXX_USE_C99_MATH_TR1
298 #if _GLIBCXX_USE_C99_MATH
299 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
301 /// Function template definitions [8.16.3].
304 using std::fpclassify;
311 using std::isgreater;
312 using std::isgreaterequal;
314 using std::islessequal;
315 using std::islessgreater;
316 using std::isunordered;
320 #if _GLIBCXX_USE_C99_MATH_TR1
322 /// Additional overloads [8.16.4].
327 { return __builtin_acoshf(__x); }
330 acosh(long double __x)
331 { return __builtin_acoshl(__x); }
333 template<typename _Tp>
334 inline typename __gnu_cxx::__promote<_Tp>::__type
337 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
338 return acosh(__type(__x));
345 { return __builtin_asinhf(__x); }
348 asinh(long double __x)
349 { return __builtin_asinhl(__x); }
351 template<typename _Tp>
352 inline typename __gnu_cxx::__promote<_Tp>::__type
355 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
356 return asinh(__type(__x));
364 { return __builtin_atanhf(__x); }
367 atanh(long double __x)
368 { return __builtin_atanhl(__x); }
370 template<typename _Tp>
371 inline typename __gnu_cxx::__promote<_Tp>::__type
374 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
375 return atanh(__type(__x));
380 { return __builtin_cbrtf(__x); }
383 cbrt(long double __x)
384 { return __builtin_cbrtl(__x); }
386 template<typename _Tp>
387 inline typename __gnu_cxx::__promote<_Tp>::__type
390 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
391 return cbrt(__type(__x));
397 copysign(float __x, float __y)
398 { return __builtin_copysignf(__x, __y); }
401 copysign(long double __x, long double __y)
402 { return __builtin_copysignl(__x, __y); }
404 template<typename _Tp, typename _Up>
405 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
406 copysign(_Tp __x, _Up __y)
408 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
409 return copysign(__type(__x), __type(__y));
417 { return __builtin_erff(__x); }
421 { return __builtin_erfl(__x); }
423 template<typename _Tp>
424 inline typename __gnu_cxx::__promote<_Tp>::__type
427 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
428 return erf(__type(__x));
433 { return __builtin_erfcf(__x); }
436 erfc(long double __x)
437 { return __builtin_erfcl(__x); }
439 template<typename _Tp>
440 inline typename __gnu_cxx::__promote<_Tp>::__type
443 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
444 return erfc(__type(__x));
451 { return __builtin_exp2f(__x); }
454 exp2(long double __x)
455 { return __builtin_exp2l(__x); }
457 template<typename _Tp>
458 inline typename __gnu_cxx::__promote<_Tp>::__type
461 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
462 return exp2(__type(__x));
467 { return __builtin_expm1f(__x); }
470 expm1(long double __x)
471 { return __builtin_expm1l(__x); }
473 template<typename _Tp>
474 inline typename __gnu_cxx::__promote<_Tp>::__type
477 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
478 return expm1(__type(__x));
484 fdim(float __x, float __y)
485 { return __builtin_fdimf(__x, __y); }
488 fdim(long double __x, long double __y)
489 { return __builtin_fdiml(__x, __y); }
491 template<typename _Tp, typename _Up>
492 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
493 fdim(_Tp __x, _Up __y)
495 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
496 return fdim(__type(__x), __type(__y));
502 fma(float __x, float __y, float __z)
503 { return __builtin_fmaf(__x, __y, __z); }
506 fma(long double __x, long double __y, long double __z)
507 { return __builtin_fmal(__x, __y, __z); }
509 template<typename _Tp, typename _Up, typename _Vp>
510 inline typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
511 fma(_Tp __x, _Up __y, _Vp __z)
513 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
514 return fma(__type(__x), __type(__y), __type(__z));
518 fmax(float __x, float __y)
519 { return __builtin_fmaxf(__x, __y); }
522 fmax(long double __x, long double __y)
523 { return __builtin_fmaxl(__x, __y); }
525 template<typename _Tp, typename _Up>
526 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
527 fmax(_Tp __x, _Up __y)
529 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
530 return fmax(__type(__x), __type(__y));
534 fmin(float __x, float __y)
535 { return __builtin_fminf(__x, __y); }
538 fmin(long double __x, long double __y)
539 { return __builtin_fminl(__x, __y); }
541 template<typename _Tp, typename _Up>
542 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
543 fmin(_Tp __x, _Up __y)
545 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
546 return fmin(__type(__x), __type(__y));
553 hypot(float __x, float __y)
554 { return __builtin_hypotf(__x, __y); }
557 hypot(long double __x, long double __y)
558 { return __builtin_hypotl(__x, __y); }
560 template<typename _Tp, typename _Up>
561 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
562 hypot(_Tp __x, _Up __y)
564 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
565 return hypot(__type(__x), __type(__y));
570 { return __builtin_ilogbf(__x); }
573 ilogb(long double __x)
574 { return __builtin_ilogbl(__x); }
576 template<typename _Tp>
580 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
581 return ilogb(__type(__x));
588 { return __builtin_lgammaf(__x); }
591 lgamma(long double __x)
592 { return __builtin_lgammal(__x); }
594 template<typename _Tp>
595 inline typename __gnu_cxx::__promote<_Tp>::__type
598 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
599 return lgamma(__type(__x));
604 { return __builtin_llrintf(__x); }
607 llrint(long double __x)
608 { return __builtin_llrintl(__x); }
610 template<typename _Tp>
614 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
615 return llrint(__type(__x));
620 { return __builtin_llroundf(__x); }
623 llround(long double __x)
624 { return __builtin_llroundl(__x); }
626 template<typename _Tp>
630 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
631 return llround(__type(__x));
639 { return __builtin_log1pf(__x); }
642 log1p(long double __x)
643 { return __builtin_log1pl(__x); }
645 template<typename _Tp>
646 inline typename __gnu_cxx::__promote<_Tp>::__type
649 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
650 return log1p(__type(__x));
656 { return __builtin_log2f(__x); }
659 log2(long double __x)
660 { return __builtin_log2l(__x); }
662 template<typename _Tp>
663 inline typename __gnu_cxx::__promote<_Tp>::__type
666 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
667 return log2(__type(__x));
672 { return __builtin_logbf(__x); }
675 logb(long double __x)
676 { return __builtin_logbl(__x); }
678 template<typename _Tp>
679 inline typename __gnu_cxx::__promote<_Tp>::__type
682 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
683 return logb(__type(__x));
688 { return __builtin_lrintf(__x); }
691 lrint(long double __x)
692 { return __builtin_lrintl(__x); }
694 template<typename _Tp>
698 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
699 return lrint(__type(__x));
704 { return __builtin_lroundf(__x); }
707 lround(long double __x)
708 { return __builtin_lroundl(__x); }
710 template<typename _Tp>
714 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
715 return lround(__type(__x));
720 { return __builtin_nearbyintf(__x); }
723 nearbyint(long double __x)
724 { return __builtin_nearbyintl(__x); }
726 template<typename _Tp>
727 inline typename __gnu_cxx::__promote<_Tp>::__type
730 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
731 return nearbyint(__type(__x));
735 nextafter(float __x, float __y)
736 { return __builtin_nextafterf(__x, __y); }
739 nextafter(long double __x, long double __y)
740 { return __builtin_nextafterl(__x, __y); }
742 template<typename _Tp, typename _Up>
743 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
744 nextafter(_Tp __x, _Up __y)
746 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
747 return nextafter(__type(__x), __type(__y));
751 nexttoward(float __x, long double __y)
752 { return __builtin_nexttowardf(__x, __y); }
755 nexttoward(long double __x, long double __y)
756 { return __builtin_nexttowardl(__x, __y); }
758 template<typename _Tp>
759 inline typename __gnu_cxx::__promote<_Tp>::__type
760 nexttoward(_Tp __x, long double __y)
762 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
763 return nexttoward(__type(__x), __y);
769 remainder(float __x, float __y)
770 { return __builtin_remainderf(__x, __y); }
773 remainder(long double __x, long double __y)
774 { return __builtin_remainderl(__x, __y); }
776 template<typename _Tp, typename _Up>
777 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
778 remainder(_Tp __x, _Up __y)
780 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
781 return remainder(__type(__x), __type(__y));
785 remquo(float __x, float __y, int* __pquo)
786 { return __builtin_remquof(__x, __y, __pquo); }
789 remquo(long double __x, long double __y, int* __pquo)
790 { return __builtin_remquol(__x, __y, __pquo); }
792 template<typename _Tp, typename _Up>
793 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
794 remquo(_Tp __x, _Up __y, int* __pquo)
796 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
797 return remquo(__type(__x), __type(__y), __pquo);
802 { return __builtin_rintf(__x); }
805 rint(long double __x)
806 { return __builtin_rintl(__x); }
808 template<typename _Tp>
809 inline typename __gnu_cxx::__promote<_Tp>::__type
812 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
813 return rint(__type(__x));
818 { return __builtin_roundf(__x); }
821 round(long double __x)
822 { return __builtin_roundl(__x); }
824 template<typename _Tp>
825 inline typename __gnu_cxx::__promote<_Tp>::__type
828 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
829 return round(__type(__x));
833 scalbln(float __x, long __ex)
834 { return __builtin_scalblnf(__x, __ex); }
837 scalbln(long double __x, long __ex)
838 { return __builtin_scalblnl(__x, __ex); }
840 template<typename _Tp>
841 inline typename __gnu_cxx::__promote<_Tp>::__type
842 scalbln(_Tp __x, long __ex)
844 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
845 return scalbln(__type(__x), __ex);
849 scalbn(float __x, int __ex)
850 { return __builtin_scalbnf(__x, __ex); }
853 scalbn(long double __x, int __ex)
854 { return __builtin_scalbnl(__x, __ex); }
856 template<typename _Tp>
857 inline typename __gnu_cxx::__promote<_Tp>::__type
858 scalbn(_Tp __x, int __ex)
860 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
861 return scalbn(__type(__x), __ex);
872 { return __builtin_tgammaf(__x); }
875 tgamma(long double __x)
876 { return __builtin_tgammal(__x); }
878 template<typename _Tp>
879 inline typename __gnu_cxx::__promote<_Tp>::__type
882 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
883 return tgamma(__type(__x));
888 { return __builtin_truncf(__x); }
891 trunc(long double __x)
892 { return __builtin_truncl(__x); }
894 template<typename _Tp>
895 inline typename __gnu_cxx::__promote<_Tp>::__type
898 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
899 return trunc(__type(__x));
904 _GLIBCXX_END_NAMESPACE_TR1