1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997-2016 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 include/cmath
26 * This is a Standard C++ Library file. You should @c \#include this file
27 * in your programs, rather than any of the @a *.h implementation files.
29 * This is the C++ version of the Standard C Library header @c math.h,
30 * and its contents are (mostly) the same as that header, but are all
31 * contained in the namespace @c std (except for names which are defined
36 // ISO C++ 14882: 26.5 C library
39 #pragma GCC system_header
41 #include <bits/c++config.h>
42 #include <bits/cpp_type_traits.h>
43 #include <ext/type_traits.h>
44 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
45 #include_next <math.h>
46 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
48 #ifndef _GLIBCXX_CMATH
49 #define _GLIBCXX_CMATH 1
51 // Get rid of those macros defined in <math.h> in lieu of real functions.
79 namespace std _GLIBCXX_VISIBILITY(default)
81 _GLIBCXX_BEGIN_NAMESPACE_VERSION
83 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
84 inline _GLIBCXX_CONSTEXPR double
86 { return __builtin_fabs(__x); }
89 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
90 inline _GLIBCXX_CONSTEXPR float
92 { return __builtin_fabsf(__x); }
94 inline _GLIBCXX_CONSTEXPR long double
96 { return __builtin_fabsl(__x); }
99 template<typename _Tp>
100 inline _GLIBCXX_CONSTEXPR
101 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
104 { return __builtin_fabs(__x); }
108 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
109 inline _GLIBCXX_CONSTEXPR float
111 { return __builtin_acosf(__x); }
113 inline _GLIBCXX_CONSTEXPR long double
114 acos(long double __x)
115 { return __builtin_acosl(__x); }
118 template<typename _Tp>
119 inline _GLIBCXX_CONSTEXPR
120 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
123 { return __builtin_acos(__x); }
127 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
128 inline _GLIBCXX_CONSTEXPR float
130 { return __builtin_asinf(__x); }
132 inline _GLIBCXX_CONSTEXPR long double
133 asin(long double __x)
134 { return __builtin_asinl(__x); }
137 template<typename _Tp>
138 inline _GLIBCXX_CONSTEXPR
139 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
142 { return __builtin_asin(__x); }
146 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
147 inline _GLIBCXX_CONSTEXPR float
149 { return __builtin_atanf(__x); }
151 inline _GLIBCXX_CONSTEXPR long double
152 atan(long double __x)
153 { return __builtin_atanl(__x); }
156 template<typename _Tp>
157 inline _GLIBCXX_CONSTEXPR
158 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
161 { return __builtin_atan(__x); }
165 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
166 inline _GLIBCXX_CONSTEXPR float
167 atan2(float __y, float __x)
168 { return __builtin_atan2f(__y, __x); }
170 inline _GLIBCXX_CONSTEXPR long double
171 atan2(long double __y, long double __x)
172 { return __builtin_atan2l(__y, __x); }
175 template<typename _Tp, typename _Up>
176 inline _GLIBCXX_CONSTEXPR
177 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
178 atan2(_Tp __y, _Up __x)
180 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
181 return atan2(__type(__y), __type(__x));
186 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
187 inline _GLIBCXX_CONSTEXPR float
189 { return __builtin_ceilf(__x); }
191 inline _GLIBCXX_CONSTEXPR long double
192 ceil(long double __x)
193 { return __builtin_ceill(__x); }
196 template<typename _Tp>
197 inline _GLIBCXX_CONSTEXPR
198 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
201 { return __builtin_ceil(__x); }
205 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
206 inline _GLIBCXX_CONSTEXPR float
208 { return __builtin_cosf(__x); }
210 inline _GLIBCXX_CONSTEXPR long double
212 { return __builtin_cosl(__x); }
215 template<typename _Tp>
216 inline _GLIBCXX_CONSTEXPR
217 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
220 { return __builtin_cos(__x); }
224 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
225 inline _GLIBCXX_CONSTEXPR float
227 { return __builtin_coshf(__x); }
229 inline _GLIBCXX_CONSTEXPR long double
230 cosh(long double __x)
231 { return __builtin_coshl(__x); }
234 template<typename _Tp>
235 inline _GLIBCXX_CONSTEXPR
236 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
239 { return __builtin_cosh(__x); }
243 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
244 inline _GLIBCXX_CONSTEXPR float
246 { return __builtin_expf(__x); }
248 inline _GLIBCXX_CONSTEXPR long double
250 { return __builtin_expl(__x); }
253 template<typename _Tp>
254 inline _GLIBCXX_CONSTEXPR
255 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
258 { return __builtin_exp(__x); }
262 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
263 inline _GLIBCXX_CONSTEXPR float
265 { return __builtin_fabsf(__x); }
267 inline _GLIBCXX_CONSTEXPR long double
268 fabs(long double __x)
269 { return __builtin_fabsl(__x); }
272 template<typename _Tp>
273 inline _GLIBCXX_CONSTEXPR
274 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
277 { return __builtin_fabs(__x); }
281 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
282 inline _GLIBCXX_CONSTEXPR float
284 { return __builtin_floorf(__x); }
286 inline _GLIBCXX_CONSTEXPR long double
287 floor(long double __x)
288 { return __builtin_floorl(__x); }
291 template<typename _Tp>
292 inline _GLIBCXX_CONSTEXPR
293 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
296 { return __builtin_floor(__x); }
300 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
301 inline _GLIBCXX_CONSTEXPR float
302 fmod(float __x, float __y)
303 { return __builtin_fmodf(__x, __y); }
305 inline _GLIBCXX_CONSTEXPR long double
306 fmod(long double __x, long double __y)
307 { return __builtin_fmodl(__x, __y); }
310 template<typename _Tp, typename _Up>
311 inline _GLIBCXX_CONSTEXPR
312 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
313 fmod(_Tp __x, _Up __y)
315 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
316 return fmod(__type(__x), __type(__y));
321 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
323 frexp(float __x, int* __exp)
324 { return __builtin_frexpf(__x, __exp); }
327 frexp(long double __x, int* __exp)
328 { return __builtin_frexpl(__x, __exp); }
331 template<typename _Tp>
332 inline _GLIBCXX_CONSTEXPR
333 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
335 frexp(_Tp __x, int* __exp)
336 { return __builtin_frexp(__x, __exp); }
340 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
341 inline _GLIBCXX_CONSTEXPR float
342 ldexp(float __x, int __exp)
343 { return __builtin_ldexpf(__x, __exp); }
345 inline _GLIBCXX_CONSTEXPR long double
346 ldexp(long double __x, int __exp)
347 { return __builtin_ldexpl(__x, __exp); }
350 template<typename _Tp>
351 inline _GLIBCXX_CONSTEXPR
352 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
354 ldexp(_Tp __x, int __exp)
355 { return __builtin_ldexp(__x, __exp); }
359 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
360 inline _GLIBCXX_CONSTEXPR float
362 { return __builtin_logf(__x); }
364 inline _GLIBCXX_CONSTEXPR long double
366 { return __builtin_logl(__x); }
369 template<typename _Tp>
370 inline _GLIBCXX_CONSTEXPR
371 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
374 { return __builtin_log(__x); }
378 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
379 inline _GLIBCXX_CONSTEXPR float
381 { return __builtin_log10f(__x); }
383 inline _GLIBCXX_CONSTEXPR long double
384 log10(long double __x)
385 { return __builtin_log10l(__x); }
388 template<typename _Tp>
389 inline _GLIBCXX_CONSTEXPR
390 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
393 { return __builtin_log10(__x); }
397 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
399 modf(float __x, float* __iptr)
400 { return __builtin_modff(__x, __iptr); }
403 modf(long double __x, long double* __iptr)
404 { return __builtin_modfl(__x, __iptr); }
409 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
410 inline _GLIBCXX_CONSTEXPR float
411 pow(float __x, float __y)
412 { return __builtin_powf(__x, __y); }
414 inline _GLIBCXX_CONSTEXPR long double
415 pow(long double __x, long double __y)
416 { return __builtin_powl(__x, __y); }
418 #if __cplusplus < 201103L
419 // _GLIBCXX_RESOLVE_LIB_DEFECTS
420 // DR 550. What should the return type of pow(float,int) be?
422 pow(double __x, int __i)
423 { return __builtin_powi(__x, __i); }
426 pow(float __x, int __n)
427 { return __builtin_powif(__x, __n); }
430 pow(long double __x, int __n)
431 { return __builtin_powil(__x, __n); }
435 template<typename _Tp, typename _Up>
436 inline _GLIBCXX_CONSTEXPR
437 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
438 pow(_Tp __x, _Up __y)
440 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
441 return pow(__type(__x), __type(__y));
446 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
447 inline _GLIBCXX_CONSTEXPR float
449 { return __builtin_sinf(__x); }
451 inline _GLIBCXX_CONSTEXPR long double
453 { return __builtin_sinl(__x); }
456 template<typename _Tp>
457 inline _GLIBCXX_CONSTEXPR
458 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
461 { return __builtin_sin(__x); }
465 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
466 inline _GLIBCXX_CONSTEXPR float
468 { return __builtin_sinhf(__x); }
470 inline _GLIBCXX_CONSTEXPR long double
471 sinh(long double __x)
472 { return __builtin_sinhl(__x); }
475 template<typename _Tp>
476 inline _GLIBCXX_CONSTEXPR
477 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
480 { return __builtin_sinh(__x); }
484 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
485 inline _GLIBCXX_CONSTEXPR float
487 { return __builtin_sqrtf(__x); }
489 inline _GLIBCXX_CONSTEXPR long double
490 sqrt(long double __x)
491 { return __builtin_sqrtl(__x); }
494 template<typename _Tp>
495 inline _GLIBCXX_CONSTEXPR
496 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
499 { return __builtin_sqrt(__x); }
503 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
504 inline _GLIBCXX_CONSTEXPR float
506 { return __builtin_tanf(__x); }
508 inline _GLIBCXX_CONSTEXPR long double
510 { return __builtin_tanl(__x); }
513 template<typename _Tp>
514 inline _GLIBCXX_CONSTEXPR
515 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
518 { return __builtin_tan(__x); }
522 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
523 inline _GLIBCXX_CONSTEXPR float
525 { return __builtin_tanhf(__x); }
527 inline _GLIBCXX_CONSTEXPR long double
528 tanh(long double __x)
529 { return __builtin_tanhl(__x); }
532 template<typename _Tp>
533 inline _GLIBCXX_CONSTEXPR
534 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
537 { return __builtin_tanh(__x); }
539 _GLIBCXX_END_NAMESPACE_VERSION
542 #if _GLIBCXX_USE_C99_MATH
543 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
545 // These are possible macros imported from C99-land.
553 #undef isgreaterequal
559 namespace std _GLIBCXX_VISIBILITY(default)
561 _GLIBCXX_BEGIN_NAMESPACE_VERSION
563 #if __cplusplus >= 201103L
565 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
567 fpclassify(float __x)
568 { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
569 FP_SUBNORMAL, FP_ZERO, __x); }
572 fpclassify(double __x)
573 { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
574 FP_SUBNORMAL, FP_ZERO, __x); }
577 fpclassify(long double __x)
578 { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
579 FP_SUBNORMAL, FP_ZERO, __x); }
582 template<typename _Tp>
583 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
586 { return __x != 0 ? FP_NORMAL : FP_ZERO; }
588 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
591 { return __builtin_isfinite(__x); }
595 { return __builtin_isfinite(__x); }
598 isfinite(long double __x)
599 { return __builtin_isfinite(__x); }
602 template<typename _Tp>
603 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
608 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
611 { return __builtin_isinf(__x); }
613 #if _GLIBCXX_HAVE_OBSOLETE_ISINF \
614 && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC
619 { return __builtin_isinf(__x); }
623 isinf(long double __x)
624 { return __builtin_isinf(__x); }
627 template<typename _Tp>
628 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
633 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
636 { return __builtin_isnan(__x); }
638 #if _GLIBCXX_HAVE_OBSOLETE_ISNAN \
639 && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC
644 { return __builtin_isnan(__x); }
648 isnan(long double __x)
649 { return __builtin_isnan(__x); }
652 template<typename _Tp>
653 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
658 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
661 { return __builtin_isnormal(__x); }
665 { return __builtin_isnormal(__x); }
668 isnormal(long double __x)
669 { return __builtin_isnormal(__x); }
672 template<typename _Tp>
673 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
676 { return __x != 0 ? true : false; }
678 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
679 // Note: middle-end/36757 is fixed, __builtin_signbit is type-generic.
682 { return __builtin_signbit(__x); }
686 { return __builtin_signbit(__x); }
689 signbit(long double __x)
690 { return __builtin_signbit(__x); }
693 template<typename _Tp>
694 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
697 { return __x < 0 ? true : false; }
699 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
701 isgreater(float __x, float __y)
702 { return __builtin_isgreater(__x, __y); }
705 isgreater(double __x, double __y)
706 { return __builtin_isgreater(__x, __y); }
709 isgreater(long double __x, long double __y)
710 { return __builtin_isgreater(__x, __y); }
713 template<typename _Tp, typename _Up>
715 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
716 && __is_arithmetic<_Up>::__value), bool>::__type
717 isgreater(_Tp __x, _Up __y)
719 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
720 return __builtin_isgreater(__type(__x), __type(__y));
723 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
725 isgreaterequal(float __x, float __y)
726 { return __builtin_isgreaterequal(__x, __y); }
729 isgreaterequal(double __x, double __y)
730 { return __builtin_isgreaterequal(__x, __y); }
733 isgreaterequal(long double __x, long double __y)
734 { return __builtin_isgreaterequal(__x, __y); }
737 template<typename _Tp, typename _Up>
739 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
740 && __is_arithmetic<_Up>::__value), bool>::__type
741 isgreaterequal(_Tp __x, _Up __y)
743 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
744 return __builtin_isgreaterequal(__type(__x), __type(__y));
747 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
749 isless(float __x, float __y)
750 { return __builtin_isless(__x, __y); }
753 isless(double __x, double __y)
754 { return __builtin_isless(__x, __y); }
757 isless(long double __x, long double __y)
758 { return __builtin_isless(__x, __y); }
761 template<typename _Tp, typename _Up>
763 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
764 && __is_arithmetic<_Up>::__value), bool>::__type
765 isless(_Tp __x, _Up __y)
767 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
768 return __builtin_isless(__type(__x), __type(__y));
771 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
773 islessequal(float __x, float __y)
774 { return __builtin_islessequal(__x, __y); }
777 islessequal(double __x, double __y)
778 { return __builtin_islessequal(__x, __y); }
781 islessequal(long double __x, long double __y)
782 { return __builtin_islessequal(__x, __y); }
785 template<typename _Tp, typename _Up>
787 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
788 && __is_arithmetic<_Up>::__value), bool>::__type
789 islessequal(_Tp __x, _Up __y)
791 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
792 return __builtin_islessequal(__type(__x), __type(__y));
795 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
797 islessgreater(float __x, float __y)
798 { return __builtin_islessgreater(__x, __y); }
801 islessgreater(double __x, double __y)
802 { return __builtin_islessgreater(__x, __y); }
805 islessgreater(long double __x, long double __y)
806 { return __builtin_islessgreater(__x, __y); }
809 template<typename _Tp, typename _Up>
811 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
812 && __is_arithmetic<_Up>::__value), bool>::__type
813 islessgreater(_Tp __x, _Up __y)
815 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
816 return __builtin_islessgreater(__type(__x), __type(__y));
819 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
821 isunordered(float __x, float __y)
822 { return __builtin_isunordered(__x, __y); }
825 isunordered(double __x, double __y)
826 { return __builtin_isunordered(__x, __y); }
829 isunordered(long double __x, long double __y)
830 { return __builtin_isunordered(__x, __y); }
833 template<typename _Tp, typename _Up>
835 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
836 && __is_arithmetic<_Up>::__value), bool>::__type
837 isunordered(_Tp __x, _Up __y)
839 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
840 return __builtin_isunordered(__type(__x), __type(__y));
845 template<typename _Tp>
846 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
850 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
851 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
852 FP_SUBNORMAL, FP_ZERO, __type(__f));
855 template<typename _Tp>
856 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
860 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
861 return __builtin_isfinite(__type(__f));
864 template<typename _Tp>
865 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
869 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
870 return __builtin_isinf(__type(__f));
873 template<typename _Tp>
874 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
878 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
879 return __builtin_isnan(__type(__f));
882 template<typename _Tp>
883 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
887 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
888 return __builtin_isnormal(__type(__f));
891 template<typename _Tp>
892 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
896 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
897 return __builtin_signbit(__type(__f));
900 template<typename _Tp>
901 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
903 isgreater(_Tp __f1, _Tp __f2)
905 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
906 return __builtin_isgreater(__type(__f1), __type(__f2));
909 template<typename _Tp>
910 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
912 isgreaterequal(_Tp __f1, _Tp __f2)
914 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
915 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
918 template<typename _Tp>
919 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
921 isless(_Tp __f1, _Tp __f2)
923 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
924 return __builtin_isless(__type(__f1), __type(__f2));
927 template<typename _Tp>
928 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
930 islessequal(_Tp __f1, _Tp __f2)
932 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
933 return __builtin_islessequal(__type(__f1), __type(__f2));
936 template<typename _Tp>
937 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
939 islessgreater(_Tp __f1, _Tp __f2)
941 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
942 return __builtin_islessgreater(__type(__f1), __type(__f2));
945 template<typename _Tp>
946 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
948 isunordered(_Tp __f1, _Tp __f2)
950 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
951 return __builtin_isunordered(__type(__f1), __type(__f2));
956 _GLIBCXX_END_NAMESPACE_VERSION
959 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
962 #if __cplusplus >= 201103L
964 #ifdef _GLIBCXX_USE_C99_MATH_TR1
1072 namespace std _GLIBCXX_VISIBILITY(default)
1074 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1186 using ::nexttowardf;
1187 using ::nexttowardl;
1221 /// Additional overloads.
1222 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1225 { return __builtin_acoshf(__x); }
1227 constexpr long double
1228 acosh(long double __x)
1229 { return __builtin_acoshl(__x); }
1232 template<typename _Tp>
1233 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1236 { return __builtin_acosh(__x); }
1238 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1241 { return __builtin_asinhf(__x); }
1243 constexpr long double
1244 asinh(long double __x)
1245 { return __builtin_asinhl(__x); }
1248 template<typename _Tp>
1249 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1252 { return __builtin_asinh(__x); }
1254 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1257 { return __builtin_atanhf(__x); }
1259 constexpr long double
1260 atanh(long double __x)
1261 { return __builtin_atanhl(__x); }
1264 template<typename _Tp>
1265 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1268 { return __builtin_atanh(__x); }
1270 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1273 { return __builtin_cbrtf(__x); }
1275 constexpr long double
1276 cbrt(long double __x)
1277 { return __builtin_cbrtl(__x); }
1280 template<typename _Tp>
1281 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1284 { return __builtin_cbrt(__x); }
1286 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1288 copysign(float __x, float __y)
1289 { return __builtin_copysignf(__x, __y); }
1291 constexpr long double
1292 copysign(long double __x, long double __y)
1293 { return __builtin_copysignl(__x, __y); }
1296 template<typename _Tp, typename _Up>
1297 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1298 copysign(_Tp __x, _Up __y)
1300 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1301 return copysign(__type(__x), __type(__y));
1304 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1307 { return __builtin_erff(__x); }
1309 constexpr long double
1310 erf(long double __x)
1311 { return __builtin_erfl(__x); }
1314 template<typename _Tp>
1315 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1318 { return __builtin_erf(__x); }
1320 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1323 { return __builtin_erfcf(__x); }
1325 constexpr long double
1326 erfc(long double __x)
1327 { return __builtin_erfcl(__x); }
1330 template<typename _Tp>
1331 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1334 { return __builtin_erfc(__x); }
1336 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1339 { return __builtin_exp2f(__x); }
1341 constexpr long double
1342 exp2(long double __x)
1343 { return __builtin_exp2l(__x); }
1346 template<typename _Tp>
1347 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1350 { return __builtin_exp2(__x); }
1352 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1355 { return __builtin_expm1f(__x); }
1357 constexpr long double
1358 expm1(long double __x)
1359 { return __builtin_expm1l(__x); }
1362 template<typename _Tp>
1363 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1366 { return __builtin_expm1(__x); }
1368 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1370 fdim(float __x, float __y)
1371 { return __builtin_fdimf(__x, __y); }
1373 constexpr long double
1374 fdim(long double __x, long double __y)
1375 { return __builtin_fdiml(__x, __y); }
1378 template<typename _Tp, typename _Up>
1379 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1380 fdim(_Tp __x, _Up __y)
1382 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1383 return fdim(__type(__x), __type(__y));
1386 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1388 fma(float __x, float __y, float __z)
1389 { return __builtin_fmaf(__x, __y, __z); }
1391 constexpr long double
1392 fma(long double __x, long double __y, long double __z)
1393 { return __builtin_fmal(__x, __y, __z); }
1396 template<typename _Tp, typename _Up, typename _Vp>
1397 constexpr typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
1398 fma(_Tp __x, _Up __y, _Vp __z)
1400 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
1401 return fma(__type(__x), __type(__y), __type(__z));
1404 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1406 fmax(float __x, float __y)
1407 { return __builtin_fmaxf(__x, __y); }
1409 constexpr long double
1410 fmax(long double __x, long double __y)
1411 { return __builtin_fmaxl(__x, __y); }
1414 template<typename _Tp, typename _Up>
1415 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1416 fmax(_Tp __x, _Up __y)
1418 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1419 return fmax(__type(__x), __type(__y));
1422 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1424 fmin(float __x, float __y)
1425 { return __builtin_fminf(__x, __y); }
1427 constexpr long double
1428 fmin(long double __x, long double __y)
1429 { return __builtin_fminl(__x, __y); }
1432 template<typename _Tp, typename _Up>
1433 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1434 fmin(_Tp __x, _Up __y)
1436 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1437 return fmin(__type(__x), __type(__y));
1440 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1442 hypot(float __x, float __y)
1443 { return __builtin_hypotf(__x, __y); }
1445 constexpr long double
1446 hypot(long double __x, long double __y)
1447 { return __builtin_hypotl(__x, __y); }
1450 template<typename _Tp, typename _Up>
1451 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1452 hypot(_Tp __x, _Up __y)
1454 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1455 return hypot(__type(__x), __type(__y));
1458 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1461 { return __builtin_ilogbf(__x); }
1464 ilogb(long double __x)
1465 { return __builtin_ilogbl(__x); }
1468 template<typename _Tp>
1470 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1473 { return __builtin_ilogb(__x); }
1475 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1478 { return __builtin_lgammaf(__x); }
1480 constexpr long double
1481 lgamma(long double __x)
1482 { return __builtin_lgammal(__x); }
1485 template<typename _Tp>
1486 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1489 { return __builtin_lgamma(__x); }
1491 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1494 { return __builtin_llrintf(__x); }
1497 llrint(long double __x)
1498 { return __builtin_llrintl(__x); }
1501 template<typename _Tp>
1502 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1505 { return __builtin_llrint(__x); }
1507 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1510 { return __builtin_llroundf(__x); }
1513 llround(long double __x)
1514 { return __builtin_llroundl(__x); }
1517 template<typename _Tp>
1518 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1521 { return __builtin_llround(__x); }
1523 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1526 { return __builtin_log1pf(__x); }
1528 constexpr long double
1529 log1p(long double __x)
1530 { return __builtin_log1pl(__x); }
1533 template<typename _Tp>
1534 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1537 { return __builtin_log1p(__x); }
1539 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1543 { return __builtin_log2f(__x); }
1545 constexpr long double
1546 log2(long double __x)
1547 { return __builtin_log2l(__x); }
1550 template<typename _Tp>
1551 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1554 { return __builtin_log2(__x); }
1556 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1559 { return __builtin_logbf(__x); }
1561 constexpr long double
1562 logb(long double __x)
1563 { return __builtin_logbl(__x); }
1566 template<typename _Tp>
1567 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1570 { return __builtin_logb(__x); }
1572 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1575 { return __builtin_lrintf(__x); }
1578 lrint(long double __x)
1579 { return __builtin_lrintl(__x); }
1582 template<typename _Tp>
1583 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1586 { return __builtin_lrint(__x); }
1588 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1591 { return __builtin_lroundf(__x); }
1594 lround(long double __x)
1595 { return __builtin_lroundl(__x); }
1598 template<typename _Tp>
1599 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1602 { return __builtin_lround(__x); }
1604 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1606 nearbyint(float __x)
1607 { return __builtin_nearbyintf(__x); }
1609 constexpr long double
1610 nearbyint(long double __x)
1611 { return __builtin_nearbyintl(__x); }
1614 template<typename _Tp>
1615 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1618 { return __builtin_nearbyint(__x); }
1620 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1622 nextafter(float __x, float __y)
1623 { return __builtin_nextafterf(__x, __y); }
1625 constexpr long double
1626 nextafter(long double __x, long double __y)
1627 { return __builtin_nextafterl(__x, __y); }
1630 template<typename _Tp, typename _Up>
1631 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1632 nextafter(_Tp __x, _Up __y)
1634 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1635 return nextafter(__type(__x), __type(__y));
1638 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1640 nexttoward(float __x, long double __y)
1641 { return __builtin_nexttowardf(__x, __y); }
1643 constexpr long double
1644 nexttoward(long double __x, long double __y)
1645 { return __builtin_nexttowardl(__x, __y); }
1648 template<typename _Tp>
1649 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1651 nexttoward(_Tp __x, long double __y)
1652 { return __builtin_nexttoward(__x, __y); }
1654 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1656 remainder(float __x, float __y)
1657 { return __builtin_remainderf(__x, __y); }
1659 constexpr long double
1660 remainder(long double __x, long double __y)
1661 { return __builtin_remainderl(__x, __y); }
1664 template<typename _Tp, typename _Up>
1665 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1666 remainder(_Tp __x, _Up __y)
1668 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1669 return remainder(__type(__x), __type(__y));
1672 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1674 remquo(float __x, float __y, int* __pquo)
1675 { return __builtin_remquof(__x, __y, __pquo); }
1678 remquo(long double __x, long double __y, int* __pquo)
1679 { return __builtin_remquol(__x, __y, __pquo); }
1682 template<typename _Tp, typename _Up>
1683 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1684 remquo(_Tp __x, _Up __y, int* __pquo)
1686 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1687 return remquo(__type(__x), __type(__y), __pquo);
1690 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1693 { return __builtin_rintf(__x); }
1695 constexpr long double
1696 rint(long double __x)
1697 { return __builtin_rintl(__x); }
1700 template<typename _Tp>
1701 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1704 { return __builtin_rint(__x); }
1706 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1709 { return __builtin_roundf(__x); }
1711 constexpr long double
1712 round(long double __x)
1713 { return __builtin_roundl(__x); }
1716 template<typename _Tp>
1717 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1720 { return __builtin_round(__x); }
1722 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1724 scalbln(float __x, long __ex)
1725 { return __builtin_scalblnf(__x, __ex); }
1727 constexpr long double
1728 scalbln(long double __x, long __ex)
1729 { return __builtin_scalblnl(__x, __ex); }
1732 template<typename _Tp>
1733 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1735 scalbln(_Tp __x, long __ex)
1736 { return __builtin_scalbln(__x, __ex); }
1738 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1740 scalbn(float __x, int __ex)
1741 { return __builtin_scalbnf(__x, __ex); }
1743 constexpr long double
1744 scalbn(long double __x, int __ex)
1745 { return __builtin_scalbnl(__x, __ex); }
1748 template<typename _Tp>
1749 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1751 scalbn(_Tp __x, int __ex)
1752 { return __builtin_scalbn(__x, __ex); }
1754 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1757 { return __builtin_tgammaf(__x); }
1759 constexpr long double
1760 tgamma(long double __x)
1761 { return __builtin_tgammal(__x); }
1764 template<typename _Tp>
1765 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1768 { return __builtin_tgamma(__x); }
1770 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1773 { return __builtin_truncf(__x); }
1775 constexpr long double
1776 trunc(long double __x)
1777 { return __builtin_truncl(__x); }
1780 template<typename _Tp>
1781 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1784 { return __builtin_trunc(__x); }
1786 _GLIBCXX_END_NAMESPACE_VERSION
1789 #endif // _GLIBCXX_USE_C99_MATH_TR1
1793 #if _GLIBCXX_USE_STD_SPEC_FUNCS
1794 # include <bits/specfun.h>