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_FP
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 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
583 template<typename _Tp>
584 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
587 { return __x != 0 ? FP_NORMAL : FP_ZERO; }
590 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
593 { return __builtin_isfinite(__x); }
597 { return __builtin_isfinite(__x); }
600 isfinite(long double __x)
601 { return __builtin_isfinite(__x); }
604 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
605 template<typename _Tp>
606 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
612 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
615 { return __builtin_isinf(__x); }
617 #if _GLIBCXX_HAVE_OBSOLETE_ISINF \
618 && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC
623 { return __builtin_isinf(__x); }
627 isinf(long double __x)
628 { return __builtin_isinf(__x); }
631 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
632 template<typename _Tp>
633 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
639 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
642 { return __builtin_isnan(__x); }
644 #if _GLIBCXX_HAVE_OBSOLETE_ISNAN \
645 && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC
650 { return __builtin_isnan(__x); }
654 isnan(long double __x)
655 { return __builtin_isnan(__x); }
658 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
659 template<typename _Tp>
660 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
666 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
669 { return __builtin_isnormal(__x); }
673 { return __builtin_isnormal(__x); }
676 isnormal(long double __x)
677 { return __builtin_isnormal(__x); }
680 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
681 template<typename _Tp>
682 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
685 { return __x != 0 ? true : false; }
688 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
689 // Note: middle-end/36757 is fixed, __builtin_signbit is type-generic.
692 { return __builtin_signbit(__x); }
696 { return __builtin_signbit(__x); }
699 signbit(long double __x)
700 { return __builtin_signbit(__x); }
703 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
704 template<typename _Tp>
705 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
708 { return __x < 0 ? true : false; }
711 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
713 isgreater(float __x, float __y)
714 { return __builtin_isgreater(__x, __y); }
717 isgreater(double __x, double __y)
718 { return __builtin_isgreater(__x, __y); }
721 isgreater(long double __x, long double __y)
722 { return __builtin_isgreater(__x, __y); }
725 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
726 template<typename _Tp, typename _Up>
728 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
729 && __is_arithmetic<_Up>::__value), bool>::__type
730 isgreater(_Tp __x, _Up __y)
732 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
733 return __builtin_isgreater(__type(__x), __type(__y));
737 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
739 isgreaterequal(float __x, float __y)
740 { return __builtin_isgreaterequal(__x, __y); }
743 isgreaterequal(double __x, double __y)
744 { return __builtin_isgreaterequal(__x, __y); }
747 isgreaterequal(long double __x, long double __y)
748 { return __builtin_isgreaterequal(__x, __y); }
751 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
752 template<typename _Tp, typename _Up>
754 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
755 && __is_arithmetic<_Up>::__value), bool>::__type
756 isgreaterequal(_Tp __x, _Up __y)
758 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
759 return __builtin_isgreaterequal(__type(__x), __type(__y));
763 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
765 isless(float __x, float __y)
766 { return __builtin_isless(__x, __y); }
769 isless(double __x, double __y)
770 { return __builtin_isless(__x, __y); }
773 isless(long double __x, long double __y)
774 { return __builtin_isless(__x, __y); }
777 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
778 template<typename _Tp, typename _Up>
780 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
781 && __is_arithmetic<_Up>::__value), bool>::__type
782 isless(_Tp __x, _Up __y)
784 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
785 return __builtin_isless(__type(__x), __type(__y));
789 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
791 islessequal(float __x, float __y)
792 { return __builtin_islessequal(__x, __y); }
795 islessequal(double __x, double __y)
796 { return __builtin_islessequal(__x, __y); }
799 islessequal(long double __x, long double __y)
800 { return __builtin_islessequal(__x, __y); }
803 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
804 template<typename _Tp, typename _Up>
806 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
807 && __is_arithmetic<_Up>::__value), bool>::__type
808 islessequal(_Tp __x, _Up __y)
810 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
811 return __builtin_islessequal(__type(__x), __type(__y));
815 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
817 islessgreater(float __x, float __y)
818 { return __builtin_islessgreater(__x, __y); }
821 islessgreater(double __x, double __y)
822 { return __builtin_islessgreater(__x, __y); }
825 islessgreater(long double __x, long double __y)
826 { return __builtin_islessgreater(__x, __y); }
829 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
830 template<typename _Tp, typename _Up>
832 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
833 && __is_arithmetic<_Up>::__value), bool>::__type
834 islessgreater(_Tp __x, _Up __y)
836 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
837 return __builtin_islessgreater(__type(__x), __type(__y));
841 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
843 isunordered(float __x, float __y)
844 { return __builtin_isunordered(__x, __y); }
847 isunordered(double __x, double __y)
848 { return __builtin_isunordered(__x, __y); }
851 isunordered(long double __x, long double __y)
852 { return __builtin_isunordered(__x, __y); }
855 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
856 template<typename _Tp, typename _Up>
858 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
859 && __is_arithmetic<_Up>::__value), bool>::__type
860 isunordered(_Tp __x, _Up __y)
862 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
863 return __builtin_isunordered(__type(__x), __type(__y));
869 template<typename _Tp>
870 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
874 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
875 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
876 FP_SUBNORMAL, FP_ZERO, __type(__f));
879 template<typename _Tp>
880 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
884 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
885 return __builtin_isfinite(__type(__f));
888 template<typename _Tp>
889 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
893 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
894 return __builtin_isinf(__type(__f));
897 template<typename _Tp>
898 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
902 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
903 return __builtin_isnan(__type(__f));
906 template<typename _Tp>
907 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
911 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
912 return __builtin_isnormal(__type(__f));
915 template<typename _Tp>
916 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
920 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
921 return __builtin_signbit(__type(__f));
924 template<typename _Tp>
925 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
927 isgreater(_Tp __f1, _Tp __f2)
929 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
930 return __builtin_isgreater(__type(__f1), __type(__f2));
933 template<typename _Tp>
934 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
936 isgreaterequal(_Tp __f1, _Tp __f2)
938 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
939 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
942 template<typename _Tp>
943 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
945 isless(_Tp __f1, _Tp __f2)
947 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
948 return __builtin_isless(__type(__f1), __type(__f2));
951 template<typename _Tp>
952 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
954 islessequal(_Tp __f1, _Tp __f2)
956 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
957 return __builtin_islessequal(__type(__f1), __type(__f2));
960 template<typename _Tp>
961 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
963 islessgreater(_Tp __f1, _Tp __f2)
965 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
966 return __builtin_islessgreater(__type(__f1), __type(__f2));
969 template<typename _Tp>
970 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
972 isunordered(_Tp __f1, _Tp __f2)
974 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
975 return __builtin_isunordered(__type(__f1), __type(__f2));
980 _GLIBCXX_END_NAMESPACE_VERSION
983 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
986 #if __cplusplus >= 201103L
988 #ifdef _GLIBCXX_USE_C99_MATH_TR1
1096 namespace std _GLIBCXX_VISIBILITY(default)
1098 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1210 using ::nexttowardf;
1211 using ::nexttowardl;
1245 /// Additional overloads.
1246 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1249 { return __builtin_acoshf(__x); }
1251 constexpr long double
1252 acosh(long double __x)
1253 { return __builtin_acoshl(__x); }
1256 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1257 template<typename _Tp>
1258 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1261 { return __builtin_acosh(__x); }
1264 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1267 { return __builtin_asinhf(__x); }
1269 constexpr long double
1270 asinh(long double __x)
1271 { return __builtin_asinhl(__x); }
1274 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1275 template<typename _Tp>
1276 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1279 { return __builtin_asinh(__x); }
1282 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1285 { return __builtin_atanhf(__x); }
1287 constexpr long double
1288 atanh(long double __x)
1289 { return __builtin_atanhl(__x); }
1292 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1293 template<typename _Tp>
1294 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1297 { return __builtin_atanh(__x); }
1300 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1303 { return __builtin_cbrtf(__x); }
1305 constexpr long double
1306 cbrt(long double __x)
1307 { return __builtin_cbrtl(__x); }
1310 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1311 template<typename _Tp>
1312 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1315 { return __builtin_cbrt(__x); }
1318 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1320 copysign(float __x, float __y)
1321 { return __builtin_copysignf(__x, __y); }
1323 constexpr long double
1324 copysign(long double __x, long double __y)
1325 { return __builtin_copysignl(__x, __y); }
1328 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1329 template<typename _Tp, typename _Up>
1330 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1331 copysign(_Tp __x, _Up __y)
1333 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1334 return copysign(__type(__x), __type(__y));
1338 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1341 { return __builtin_erff(__x); }
1343 constexpr long double
1344 erf(long double __x)
1345 { return __builtin_erfl(__x); }
1348 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1349 template<typename _Tp>
1350 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1353 { return __builtin_erf(__x); }
1356 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1359 { return __builtin_erfcf(__x); }
1361 constexpr long double
1362 erfc(long double __x)
1363 { return __builtin_erfcl(__x); }
1366 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1367 template<typename _Tp>
1368 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1371 { return __builtin_erfc(__x); }
1374 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1377 { return __builtin_exp2f(__x); }
1379 constexpr long double
1380 exp2(long double __x)
1381 { return __builtin_exp2l(__x); }
1384 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1385 template<typename _Tp>
1386 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1389 { return __builtin_exp2(__x); }
1392 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1395 { return __builtin_expm1f(__x); }
1397 constexpr long double
1398 expm1(long double __x)
1399 { return __builtin_expm1l(__x); }
1402 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1403 template<typename _Tp>
1404 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1407 { return __builtin_expm1(__x); }
1410 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1412 fdim(float __x, float __y)
1413 { return __builtin_fdimf(__x, __y); }
1415 constexpr long double
1416 fdim(long double __x, long double __y)
1417 { return __builtin_fdiml(__x, __y); }
1420 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1421 template<typename _Tp, typename _Up>
1422 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1423 fdim(_Tp __x, _Up __y)
1425 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1426 return fdim(__type(__x), __type(__y));
1430 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1432 fma(float __x, float __y, float __z)
1433 { return __builtin_fmaf(__x, __y, __z); }
1435 constexpr long double
1436 fma(long double __x, long double __y, long double __z)
1437 { return __builtin_fmal(__x, __y, __z); }
1440 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1441 template<typename _Tp, typename _Up, typename _Vp>
1442 constexpr typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
1443 fma(_Tp __x, _Up __y, _Vp __z)
1445 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
1446 return fma(__type(__x), __type(__y), __type(__z));
1450 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1452 fmax(float __x, float __y)
1453 { return __builtin_fmaxf(__x, __y); }
1455 constexpr long double
1456 fmax(long double __x, long double __y)
1457 { return __builtin_fmaxl(__x, __y); }
1460 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1461 template<typename _Tp, typename _Up>
1462 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1463 fmax(_Tp __x, _Up __y)
1465 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1466 return fmax(__type(__x), __type(__y));
1470 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1472 fmin(float __x, float __y)
1473 { return __builtin_fminf(__x, __y); }
1475 constexpr long double
1476 fmin(long double __x, long double __y)
1477 { return __builtin_fminl(__x, __y); }
1480 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1481 template<typename _Tp, typename _Up>
1482 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1483 fmin(_Tp __x, _Up __y)
1485 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1486 return fmin(__type(__x), __type(__y));
1490 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1492 hypot(float __x, float __y)
1493 { return __builtin_hypotf(__x, __y); }
1495 constexpr long double
1496 hypot(long double __x, long double __y)
1497 { return __builtin_hypotl(__x, __y); }
1500 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1501 template<typename _Tp, typename _Up>
1502 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1503 hypot(_Tp __x, _Up __y)
1505 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1506 return hypot(__type(__x), __type(__y));
1510 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1513 { return __builtin_ilogbf(__x); }
1516 ilogb(long double __x)
1517 { return __builtin_ilogbl(__x); }
1520 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1521 template<typename _Tp>
1523 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1526 { return __builtin_ilogb(__x); }
1529 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1532 { return __builtin_lgammaf(__x); }
1534 constexpr long double
1535 lgamma(long double __x)
1536 { return __builtin_lgammal(__x); }
1539 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1540 template<typename _Tp>
1541 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1544 { return __builtin_lgamma(__x); }
1547 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1550 { return __builtin_llrintf(__x); }
1553 llrint(long double __x)
1554 { return __builtin_llrintl(__x); }
1557 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1558 template<typename _Tp>
1559 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1562 { return __builtin_llrint(__x); }
1565 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1568 { return __builtin_llroundf(__x); }
1571 llround(long double __x)
1572 { return __builtin_llroundl(__x); }
1575 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1576 template<typename _Tp>
1577 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1580 { return __builtin_llround(__x); }
1583 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1586 { return __builtin_log1pf(__x); }
1588 constexpr long double
1589 log1p(long double __x)
1590 { return __builtin_log1pl(__x); }
1593 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1594 template<typename _Tp>
1595 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1598 { return __builtin_log1p(__x); }
1601 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1605 { return __builtin_log2f(__x); }
1607 constexpr long double
1608 log2(long double __x)
1609 { return __builtin_log2l(__x); }
1612 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1613 template<typename _Tp>
1614 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1617 { return __builtin_log2(__x); }
1620 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1623 { return __builtin_logbf(__x); }
1625 constexpr long double
1626 logb(long double __x)
1627 { return __builtin_logbl(__x); }
1630 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1631 template<typename _Tp>
1632 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1635 { return __builtin_logb(__x); }
1638 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1641 { return __builtin_lrintf(__x); }
1644 lrint(long double __x)
1645 { return __builtin_lrintl(__x); }
1648 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1649 template<typename _Tp>
1650 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1653 { return __builtin_lrint(__x); }
1656 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1659 { return __builtin_lroundf(__x); }
1662 lround(long double __x)
1663 { return __builtin_lroundl(__x); }
1666 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1667 template<typename _Tp>
1668 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1671 { return __builtin_lround(__x); }
1674 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1676 nearbyint(float __x)
1677 { return __builtin_nearbyintf(__x); }
1679 constexpr long double
1680 nearbyint(long double __x)
1681 { return __builtin_nearbyintl(__x); }
1684 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1685 template<typename _Tp>
1686 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1689 { return __builtin_nearbyint(__x); }
1692 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1694 nextafter(float __x, float __y)
1695 { return __builtin_nextafterf(__x, __y); }
1697 constexpr long double
1698 nextafter(long double __x, long double __y)
1699 { return __builtin_nextafterl(__x, __y); }
1702 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1703 template<typename _Tp, typename _Up>
1704 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1705 nextafter(_Tp __x, _Up __y)
1707 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1708 return nextafter(__type(__x), __type(__y));
1712 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1714 nexttoward(float __x, long double __y)
1715 { return __builtin_nexttowardf(__x, __y); }
1717 constexpr long double
1718 nexttoward(long double __x, long double __y)
1719 { return __builtin_nexttowardl(__x, __y); }
1722 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1723 template<typename _Tp>
1724 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1726 nexttoward(_Tp __x, long double __y)
1727 { return __builtin_nexttoward(__x, __y); }
1730 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1732 remainder(float __x, float __y)
1733 { return __builtin_remainderf(__x, __y); }
1735 constexpr long double
1736 remainder(long double __x, long double __y)
1737 { return __builtin_remainderl(__x, __y); }
1740 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1741 template<typename _Tp, typename _Up>
1742 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1743 remainder(_Tp __x, _Up __y)
1745 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1746 return remainder(__type(__x), __type(__y));
1750 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1752 remquo(float __x, float __y, int* __pquo)
1753 { return __builtin_remquof(__x, __y, __pquo); }
1756 remquo(long double __x, long double __y, int* __pquo)
1757 { return __builtin_remquol(__x, __y, __pquo); }
1760 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1761 template<typename _Tp, typename _Up>
1762 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1763 remquo(_Tp __x, _Up __y, int* __pquo)
1765 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1766 return remquo(__type(__x), __type(__y), __pquo);
1770 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1773 { return __builtin_rintf(__x); }
1775 constexpr long double
1776 rint(long double __x)
1777 { return __builtin_rintl(__x); }
1780 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1781 template<typename _Tp>
1782 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1785 { return __builtin_rint(__x); }
1788 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1791 { return __builtin_roundf(__x); }
1793 constexpr long double
1794 round(long double __x)
1795 { return __builtin_roundl(__x); }
1798 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1799 template<typename _Tp>
1800 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1803 { return __builtin_round(__x); }
1806 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1808 scalbln(float __x, long __ex)
1809 { return __builtin_scalblnf(__x, __ex); }
1811 constexpr long double
1812 scalbln(long double __x, long __ex)
1813 { return __builtin_scalblnl(__x, __ex); }
1816 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1817 template<typename _Tp>
1818 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1820 scalbln(_Tp __x, long __ex)
1821 { return __builtin_scalbln(__x, __ex); }
1824 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1826 scalbn(float __x, int __ex)
1827 { return __builtin_scalbnf(__x, __ex); }
1829 constexpr long double
1830 scalbn(long double __x, int __ex)
1831 { return __builtin_scalbnl(__x, __ex); }
1834 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1835 template<typename _Tp>
1836 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1838 scalbn(_Tp __x, int __ex)
1839 { return __builtin_scalbn(__x, __ex); }
1842 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1845 { return __builtin_tgammaf(__x); }
1847 constexpr long double
1848 tgamma(long double __x)
1849 { return __builtin_tgammal(__x); }
1852 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1853 template<typename _Tp>
1854 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1857 { return __builtin_tgamma(__x); }
1860 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1863 { return __builtin_truncf(__x); }
1865 constexpr long double
1866 trunc(long double __x)
1867 { return __builtin_truncl(__x); }
1870 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1871 template<typename _Tp>
1872 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1875 { return __builtin_trunc(__x); }
1878 _GLIBCXX_END_NAMESPACE_VERSION
1881 #endif // _GLIBCXX_USE_C99_MATH_TR1
1885 #if __STDCPP_WANT_MATH_SPEC_FUNCS__ == 1
1886 # include <bits/specfun.h>