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 #ifdef _GLIBCXX_HAVE_OBSOLETE_ISINF_ISNAN
618 { return __builtin_isinf(__x); }
622 isinf(long double __x)
623 { return __builtin_isinf(__x); }
626 template<typename _Tp>
627 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
632 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
635 { return __builtin_isnan(__x); }
637 #ifdef _GLIBCXX_HAVE_OBSOLETE_ISINF_ISNAN
642 { return __builtin_isnan(__x); }
646 isnan(long double __x)
647 { return __builtin_isnan(__x); }
650 template<typename _Tp>
651 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
656 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
659 { return __builtin_isnormal(__x); }
663 { return __builtin_isnormal(__x); }
666 isnormal(long double __x)
667 { return __builtin_isnormal(__x); }
670 template<typename _Tp>
671 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
674 { return __x != 0 ? true : false; }
676 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
677 // Note: middle-end/36757 is fixed, __builtin_signbit is type-generic.
680 { return __builtin_signbit(__x); }
684 { return __builtin_signbit(__x); }
687 signbit(long double __x)
688 { return __builtin_signbit(__x); }
691 template<typename _Tp>
692 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
695 { return __x < 0 ? true : false; }
697 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
699 isgreater(float __x, float __y)
700 { return __builtin_isgreater(__x, __y); }
703 isgreater(double __x, double __y)
704 { return __builtin_isgreater(__x, __y); }
707 isgreater(long double __x, long double __y)
708 { return __builtin_isgreater(__x, __y); }
711 template<typename _Tp, typename _Up>
713 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
714 && __is_arithmetic<_Up>::__value), bool>::__type
715 isgreater(_Tp __x, _Up __y)
717 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
718 return __builtin_isgreater(__type(__x), __type(__y));
721 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
723 isgreaterequal(float __x, float __y)
724 { return __builtin_isgreaterequal(__x, __y); }
727 isgreaterequal(double __x, double __y)
728 { return __builtin_isgreaterequal(__x, __y); }
731 isgreaterequal(long double __x, long double __y)
732 { return __builtin_isgreaterequal(__x, __y); }
735 template<typename _Tp, typename _Up>
737 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
738 && __is_arithmetic<_Up>::__value), bool>::__type
739 isgreaterequal(_Tp __x, _Up __y)
741 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
742 return __builtin_isgreaterequal(__type(__x), __type(__y));
745 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
747 isless(float __x, float __y)
748 { return __builtin_isless(__x, __y); }
751 isless(double __x, double __y)
752 { return __builtin_isless(__x, __y); }
755 isless(long double __x, long double __y)
756 { return __builtin_isless(__x, __y); }
759 template<typename _Tp, typename _Up>
761 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
762 && __is_arithmetic<_Up>::__value), bool>::__type
763 isless(_Tp __x, _Up __y)
765 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
766 return __builtin_isless(__type(__x), __type(__y));
769 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
771 islessequal(float __x, float __y)
772 { return __builtin_islessequal(__x, __y); }
775 islessequal(double __x, double __y)
776 { return __builtin_islessequal(__x, __y); }
779 islessequal(long double __x, long double __y)
780 { return __builtin_islessequal(__x, __y); }
783 template<typename _Tp, typename _Up>
785 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
786 && __is_arithmetic<_Up>::__value), bool>::__type
787 islessequal(_Tp __x, _Up __y)
789 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
790 return __builtin_islessequal(__type(__x), __type(__y));
793 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
795 islessgreater(float __x, float __y)
796 { return __builtin_islessgreater(__x, __y); }
799 islessgreater(double __x, double __y)
800 { return __builtin_islessgreater(__x, __y); }
803 islessgreater(long double __x, long double __y)
804 { return __builtin_islessgreater(__x, __y); }
807 template<typename _Tp, typename _Up>
809 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
810 && __is_arithmetic<_Up>::__value), bool>::__type
811 islessgreater(_Tp __x, _Up __y)
813 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
814 return __builtin_islessgreater(__type(__x), __type(__y));
817 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
819 isunordered(float __x, float __y)
820 { return __builtin_isunordered(__x, __y); }
823 isunordered(double __x, double __y)
824 { return __builtin_isunordered(__x, __y); }
827 isunordered(long double __x, long double __y)
828 { return __builtin_isunordered(__x, __y); }
831 template<typename _Tp, typename _Up>
833 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
834 && __is_arithmetic<_Up>::__value), bool>::__type
835 isunordered(_Tp __x, _Up __y)
837 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
838 return __builtin_isunordered(__type(__x), __type(__y));
843 template<typename _Tp>
844 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
848 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
849 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
850 FP_SUBNORMAL, FP_ZERO, __type(__f));
853 template<typename _Tp>
854 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
858 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
859 return __builtin_isfinite(__type(__f));
862 template<typename _Tp>
863 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
867 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
868 return __builtin_isinf(__type(__f));
871 template<typename _Tp>
872 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
876 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
877 return __builtin_isnan(__type(__f));
880 template<typename _Tp>
881 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
885 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
886 return __builtin_isnormal(__type(__f));
889 template<typename _Tp>
890 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
894 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
895 return __builtin_signbit(__type(__f));
898 template<typename _Tp>
899 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
901 isgreater(_Tp __f1, _Tp __f2)
903 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
904 return __builtin_isgreater(__type(__f1), __type(__f2));
907 template<typename _Tp>
908 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
910 isgreaterequal(_Tp __f1, _Tp __f2)
912 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
913 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
916 template<typename _Tp>
917 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
919 isless(_Tp __f1, _Tp __f2)
921 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
922 return __builtin_isless(__type(__f1), __type(__f2));
925 template<typename _Tp>
926 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
928 islessequal(_Tp __f1, _Tp __f2)
930 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
931 return __builtin_islessequal(__type(__f1), __type(__f2));
934 template<typename _Tp>
935 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
937 islessgreater(_Tp __f1, _Tp __f2)
939 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
940 return __builtin_islessgreater(__type(__f1), __type(__f2));
943 template<typename _Tp>
944 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
946 isunordered(_Tp __f1, _Tp __f2)
948 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
949 return __builtin_isunordered(__type(__f1), __type(__f2));
954 _GLIBCXX_END_NAMESPACE_VERSION
957 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
960 #if __cplusplus >= 201103L
962 #ifdef _GLIBCXX_USE_C99_MATH_TR1
1070 namespace std _GLIBCXX_VISIBILITY(default)
1072 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1184 using ::nexttowardf;
1185 using ::nexttowardl;
1219 /// Additional overloads.
1220 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1223 { return __builtin_acoshf(__x); }
1225 constexpr long double
1226 acosh(long double __x)
1227 { return __builtin_acoshl(__x); }
1230 template<typename _Tp>
1231 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1234 { return __builtin_acosh(__x); }
1236 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1239 { return __builtin_asinhf(__x); }
1241 constexpr long double
1242 asinh(long double __x)
1243 { return __builtin_asinhl(__x); }
1246 template<typename _Tp>
1247 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1250 { return __builtin_asinh(__x); }
1252 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1255 { return __builtin_atanhf(__x); }
1257 constexpr long double
1258 atanh(long double __x)
1259 { return __builtin_atanhl(__x); }
1262 template<typename _Tp>
1263 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1266 { return __builtin_atanh(__x); }
1268 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1271 { return __builtin_cbrtf(__x); }
1273 constexpr long double
1274 cbrt(long double __x)
1275 { return __builtin_cbrtl(__x); }
1278 template<typename _Tp>
1279 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1282 { return __builtin_cbrt(__x); }
1284 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1286 copysign(float __x, float __y)
1287 { return __builtin_copysignf(__x, __y); }
1289 constexpr long double
1290 copysign(long double __x, long double __y)
1291 { return __builtin_copysignl(__x, __y); }
1294 template<typename _Tp, typename _Up>
1295 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1296 copysign(_Tp __x, _Up __y)
1298 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1299 return copysign(__type(__x), __type(__y));
1302 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1305 { return __builtin_erff(__x); }
1307 constexpr long double
1308 erf(long double __x)
1309 { return __builtin_erfl(__x); }
1312 template<typename _Tp>
1313 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1316 { return __builtin_erf(__x); }
1318 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1321 { return __builtin_erfcf(__x); }
1323 constexpr long double
1324 erfc(long double __x)
1325 { return __builtin_erfcl(__x); }
1328 template<typename _Tp>
1329 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1332 { return __builtin_erfc(__x); }
1334 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1337 { return __builtin_exp2f(__x); }
1339 constexpr long double
1340 exp2(long double __x)
1341 { return __builtin_exp2l(__x); }
1344 template<typename _Tp>
1345 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1348 { return __builtin_exp2(__x); }
1350 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1353 { return __builtin_expm1f(__x); }
1355 constexpr long double
1356 expm1(long double __x)
1357 { return __builtin_expm1l(__x); }
1360 template<typename _Tp>
1361 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1364 { return __builtin_expm1(__x); }
1366 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1368 fdim(float __x, float __y)
1369 { return __builtin_fdimf(__x, __y); }
1371 constexpr long double
1372 fdim(long double __x, long double __y)
1373 { return __builtin_fdiml(__x, __y); }
1376 template<typename _Tp, typename _Up>
1377 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1378 fdim(_Tp __x, _Up __y)
1380 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1381 return fdim(__type(__x), __type(__y));
1384 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1386 fma(float __x, float __y, float __z)
1387 { return __builtin_fmaf(__x, __y, __z); }
1389 constexpr long double
1390 fma(long double __x, long double __y, long double __z)
1391 { return __builtin_fmal(__x, __y, __z); }
1394 template<typename _Tp, typename _Up, typename _Vp>
1395 constexpr typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
1396 fma(_Tp __x, _Up __y, _Vp __z)
1398 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
1399 return fma(__type(__x), __type(__y), __type(__z));
1402 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1404 fmax(float __x, float __y)
1405 { return __builtin_fmaxf(__x, __y); }
1407 constexpr long double
1408 fmax(long double __x, long double __y)
1409 { return __builtin_fmaxl(__x, __y); }
1412 template<typename _Tp, typename _Up>
1413 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1414 fmax(_Tp __x, _Up __y)
1416 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1417 return fmax(__type(__x), __type(__y));
1420 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1422 fmin(float __x, float __y)
1423 { return __builtin_fminf(__x, __y); }
1425 constexpr long double
1426 fmin(long double __x, long double __y)
1427 { return __builtin_fminl(__x, __y); }
1430 template<typename _Tp, typename _Up>
1431 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1432 fmin(_Tp __x, _Up __y)
1434 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1435 return fmin(__type(__x), __type(__y));
1438 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1440 hypot(float __x, float __y)
1441 { return __builtin_hypotf(__x, __y); }
1443 constexpr long double
1444 hypot(long double __x, long double __y)
1445 { return __builtin_hypotl(__x, __y); }
1448 template<typename _Tp, typename _Up>
1449 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1450 hypot(_Tp __x, _Up __y)
1452 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1453 return hypot(__type(__x), __type(__y));
1456 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1459 { return __builtin_ilogbf(__x); }
1462 ilogb(long double __x)
1463 { return __builtin_ilogbl(__x); }
1466 template<typename _Tp>
1468 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1471 { return __builtin_ilogb(__x); }
1473 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1476 { return __builtin_lgammaf(__x); }
1478 constexpr long double
1479 lgamma(long double __x)
1480 { return __builtin_lgammal(__x); }
1483 template<typename _Tp>
1484 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1487 { return __builtin_lgamma(__x); }
1489 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1492 { return __builtin_llrintf(__x); }
1495 llrint(long double __x)
1496 { return __builtin_llrintl(__x); }
1499 template<typename _Tp>
1500 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1503 { return __builtin_llrint(__x); }
1505 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1508 { return __builtin_llroundf(__x); }
1511 llround(long double __x)
1512 { return __builtin_llroundl(__x); }
1515 template<typename _Tp>
1516 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1519 { return __builtin_llround(__x); }
1521 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1524 { return __builtin_log1pf(__x); }
1526 constexpr long double
1527 log1p(long double __x)
1528 { return __builtin_log1pl(__x); }
1531 template<typename _Tp>
1532 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1535 { return __builtin_log1p(__x); }
1537 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1541 { return __builtin_log2f(__x); }
1543 constexpr long double
1544 log2(long double __x)
1545 { return __builtin_log2l(__x); }
1548 template<typename _Tp>
1549 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1552 { return __builtin_log2(__x); }
1554 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1557 { return __builtin_logbf(__x); }
1559 constexpr long double
1560 logb(long double __x)
1561 { return __builtin_logbl(__x); }
1564 template<typename _Tp>
1565 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1568 { return __builtin_logb(__x); }
1570 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1573 { return __builtin_lrintf(__x); }
1576 lrint(long double __x)
1577 { return __builtin_lrintl(__x); }
1580 template<typename _Tp>
1581 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1584 { return __builtin_lrint(__x); }
1586 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1589 { return __builtin_lroundf(__x); }
1592 lround(long double __x)
1593 { return __builtin_lroundl(__x); }
1596 template<typename _Tp>
1597 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1600 { return __builtin_lround(__x); }
1602 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1604 nearbyint(float __x)
1605 { return __builtin_nearbyintf(__x); }
1607 constexpr long double
1608 nearbyint(long double __x)
1609 { return __builtin_nearbyintl(__x); }
1612 template<typename _Tp>
1613 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1616 { return __builtin_nearbyint(__x); }
1618 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1620 nextafter(float __x, float __y)
1621 { return __builtin_nextafterf(__x, __y); }
1623 constexpr long double
1624 nextafter(long double __x, long double __y)
1625 { return __builtin_nextafterl(__x, __y); }
1628 template<typename _Tp, typename _Up>
1629 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1630 nextafter(_Tp __x, _Up __y)
1632 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1633 return nextafter(__type(__x), __type(__y));
1636 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1638 nexttoward(float __x, long double __y)
1639 { return __builtin_nexttowardf(__x, __y); }
1641 constexpr long double
1642 nexttoward(long double __x, long double __y)
1643 { return __builtin_nexttowardl(__x, __y); }
1646 template<typename _Tp>
1647 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1649 nexttoward(_Tp __x, long double __y)
1650 { return __builtin_nexttoward(__x, __y); }
1652 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1654 remainder(float __x, float __y)
1655 { return __builtin_remainderf(__x, __y); }
1657 constexpr long double
1658 remainder(long double __x, long double __y)
1659 { return __builtin_remainderl(__x, __y); }
1662 template<typename _Tp, typename _Up>
1663 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1664 remainder(_Tp __x, _Up __y)
1666 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1667 return remainder(__type(__x), __type(__y));
1670 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1672 remquo(float __x, float __y, int* __pquo)
1673 { return __builtin_remquof(__x, __y, __pquo); }
1676 remquo(long double __x, long double __y, int* __pquo)
1677 { return __builtin_remquol(__x, __y, __pquo); }
1680 template<typename _Tp, typename _Up>
1681 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1682 remquo(_Tp __x, _Up __y, int* __pquo)
1684 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1685 return remquo(__type(__x), __type(__y), __pquo);
1688 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1691 { return __builtin_rintf(__x); }
1693 constexpr long double
1694 rint(long double __x)
1695 { return __builtin_rintl(__x); }
1698 template<typename _Tp>
1699 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1702 { return __builtin_rint(__x); }
1704 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1707 { return __builtin_roundf(__x); }
1709 constexpr long double
1710 round(long double __x)
1711 { return __builtin_roundl(__x); }
1714 template<typename _Tp>
1715 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1718 { return __builtin_round(__x); }
1720 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1722 scalbln(float __x, long __ex)
1723 { return __builtin_scalblnf(__x, __ex); }
1725 constexpr long double
1726 scalbln(long double __x, long __ex)
1727 { return __builtin_scalblnl(__x, __ex); }
1730 template<typename _Tp>
1731 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1733 scalbln(_Tp __x, long __ex)
1734 { return __builtin_scalbln(__x, __ex); }
1736 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1738 scalbn(float __x, int __ex)
1739 { return __builtin_scalbnf(__x, __ex); }
1741 constexpr long double
1742 scalbn(long double __x, int __ex)
1743 { return __builtin_scalbnl(__x, __ex); }
1746 template<typename _Tp>
1747 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1749 scalbn(_Tp __x, int __ex)
1750 { return __builtin_scalbn(__x, __ex); }
1752 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1755 { return __builtin_tgammaf(__x); }
1757 constexpr long double
1758 tgamma(long double __x)
1759 { return __builtin_tgammal(__x); }
1762 template<typename _Tp>
1763 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1766 { return __builtin_tgamma(__x); }
1768 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO
1771 { return __builtin_truncf(__x); }
1773 constexpr long double
1774 trunc(long double __x)
1775 { return __builtin_truncl(__x); }
1778 template<typename _Tp>
1779 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1782 { return __builtin_trunc(__x); }
1784 _GLIBCXX_END_NAMESPACE_VERSION
1787 #endif // _GLIBCXX_USE_C99_MATH_TR1
1791 #if __STDCPP_WANT_MATH_SPEC_FUNCS__ == 1
1792 # include <bits/specfun.h>