1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997-2018 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
47 #include <bits/std_abs.h>
49 #ifndef _GLIBCXX_CMATH
50 #define _GLIBCXX_CMATH 1
52 // 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
85 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
86 inline _GLIBCXX_CONSTEXPR float
88 { return __builtin_acosf(__x); }
90 inline _GLIBCXX_CONSTEXPR long double
92 { return __builtin_acosl(__x); }
95 template<typename _Tp>
96 inline _GLIBCXX_CONSTEXPR
97 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
100 { return __builtin_acos(__x); }
104 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
105 inline _GLIBCXX_CONSTEXPR float
107 { return __builtin_asinf(__x); }
109 inline _GLIBCXX_CONSTEXPR long double
110 asin(long double __x)
111 { return __builtin_asinl(__x); }
114 template<typename _Tp>
115 inline _GLIBCXX_CONSTEXPR
116 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
119 { return __builtin_asin(__x); }
123 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
124 inline _GLIBCXX_CONSTEXPR float
126 { return __builtin_atanf(__x); }
128 inline _GLIBCXX_CONSTEXPR long double
129 atan(long double __x)
130 { return __builtin_atanl(__x); }
133 template<typename _Tp>
134 inline _GLIBCXX_CONSTEXPR
135 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
138 { return __builtin_atan(__x); }
142 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
143 inline _GLIBCXX_CONSTEXPR float
144 atan2(float __y, float __x)
145 { return __builtin_atan2f(__y, __x); }
147 inline _GLIBCXX_CONSTEXPR long double
148 atan2(long double __y, long double __x)
149 { return __builtin_atan2l(__y, __x); }
152 template<typename _Tp, typename _Up>
153 inline _GLIBCXX_CONSTEXPR
154 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
155 atan2(_Tp __y, _Up __x)
157 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
158 return atan2(__type(__y), __type(__x));
163 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
164 inline _GLIBCXX_CONSTEXPR float
166 { return __builtin_ceilf(__x); }
168 inline _GLIBCXX_CONSTEXPR long double
169 ceil(long double __x)
170 { return __builtin_ceill(__x); }
173 template<typename _Tp>
174 inline _GLIBCXX_CONSTEXPR
175 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
178 { return __builtin_ceil(__x); }
182 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
183 inline _GLIBCXX_CONSTEXPR float
185 { return __builtin_cosf(__x); }
187 inline _GLIBCXX_CONSTEXPR long double
189 { return __builtin_cosl(__x); }
192 template<typename _Tp>
193 inline _GLIBCXX_CONSTEXPR
194 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
197 { return __builtin_cos(__x); }
201 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
202 inline _GLIBCXX_CONSTEXPR float
204 { return __builtin_coshf(__x); }
206 inline _GLIBCXX_CONSTEXPR long double
207 cosh(long double __x)
208 { return __builtin_coshl(__x); }
211 template<typename _Tp>
212 inline _GLIBCXX_CONSTEXPR
213 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
216 { return __builtin_cosh(__x); }
220 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
221 inline _GLIBCXX_CONSTEXPR float
223 { return __builtin_expf(__x); }
225 inline _GLIBCXX_CONSTEXPR long double
227 { return __builtin_expl(__x); }
230 template<typename _Tp>
231 inline _GLIBCXX_CONSTEXPR
232 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
235 { return __builtin_exp(__x); }
239 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
240 inline _GLIBCXX_CONSTEXPR float
242 { return __builtin_fabsf(__x); }
244 inline _GLIBCXX_CONSTEXPR long double
245 fabs(long double __x)
246 { return __builtin_fabsl(__x); }
249 template<typename _Tp>
250 inline _GLIBCXX_CONSTEXPR
251 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
254 { return __builtin_fabs(__x); }
258 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
259 inline _GLIBCXX_CONSTEXPR float
261 { return __builtin_floorf(__x); }
263 inline _GLIBCXX_CONSTEXPR long double
264 floor(long double __x)
265 { return __builtin_floorl(__x); }
268 template<typename _Tp>
269 inline _GLIBCXX_CONSTEXPR
270 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
273 { return __builtin_floor(__x); }
277 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
278 inline _GLIBCXX_CONSTEXPR float
279 fmod(float __x, float __y)
280 { return __builtin_fmodf(__x, __y); }
282 inline _GLIBCXX_CONSTEXPR long double
283 fmod(long double __x, long double __y)
284 { return __builtin_fmodl(__x, __y); }
287 template<typename _Tp, typename _Up>
288 inline _GLIBCXX_CONSTEXPR
289 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
290 fmod(_Tp __x, _Up __y)
292 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
293 return fmod(__type(__x), __type(__y));
298 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
300 frexp(float __x, int* __exp)
301 { return __builtin_frexpf(__x, __exp); }
304 frexp(long double __x, int* __exp)
305 { return __builtin_frexpl(__x, __exp); }
308 template<typename _Tp>
309 inline _GLIBCXX_CONSTEXPR
310 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
312 frexp(_Tp __x, int* __exp)
313 { return __builtin_frexp(__x, __exp); }
317 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
318 inline _GLIBCXX_CONSTEXPR float
319 ldexp(float __x, int __exp)
320 { return __builtin_ldexpf(__x, __exp); }
322 inline _GLIBCXX_CONSTEXPR long double
323 ldexp(long double __x, int __exp)
324 { return __builtin_ldexpl(__x, __exp); }
327 template<typename _Tp>
328 inline _GLIBCXX_CONSTEXPR
329 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
331 ldexp(_Tp __x, int __exp)
332 { return __builtin_ldexp(__x, __exp); }
336 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
337 inline _GLIBCXX_CONSTEXPR float
339 { return __builtin_logf(__x); }
341 inline _GLIBCXX_CONSTEXPR long double
343 { return __builtin_logl(__x); }
346 template<typename _Tp>
347 inline _GLIBCXX_CONSTEXPR
348 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
351 { return __builtin_log(__x); }
355 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
356 inline _GLIBCXX_CONSTEXPR float
358 { return __builtin_log10f(__x); }
360 inline _GLIBCXX_CONSTEXPR long double
361 log10(long double __x)
362 { return __builtin_log10l(__x); }
365 template<typename _Tp>
366 inline _GLIBCXX_CONSTEXPR
367 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
370 { return __builtin_log10(__x); }
374 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
376 modf(float __x, float* __iptr)
377 { return __builtin_modff(__x, __iptr); }
380 modf(long double __x, long double* __iptr)
381 { return __builtin_modfl(__x, __iptr); }
386 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
387 inline _GLIBCXX_CONSTEXPR float
388 pow(float __x, float __y)
389 { return __builtin_powf(__x, __y); }
391 inline _GLIBCXX_CONSTEXPR long double
392 pow(long double __x, long double __y)
393 { return __builtin_powl(__x, __y); }
395 #if __cplusplus < 201103L
396 // _GLIBCXX_RESOLVE_LIB_DEFECTS
397 // DR 550. What should the return type of pow(float,int) be?
399 pow(double __x, int __i)
400 { return __builtin_powi(__x, __i); }
403 pow(float __x, int __n)
404 { return __builtin_powif(__x, __n); }
407 pow(long double __x, int __n)
408 { return __builtin_powil(__x, __n); }
412 template<typename _Tp, typename _Up>
413 inline _GLIBCXX_CONSTEXPR
414 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
415 pow(_Tp __x, _Up __y)
417 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
418 return pow(__type(__x), __type(__y));
423 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
424 inline _GLIBCXX_CONSTEXPR float
426 { return __builtin_sinf(__x); }
428 inline _GLIBCXX_CONSTEXPR long double
430 { return __builtin_sinl(__x); }
433 template<typename _Tp>
434 inline _GLIBCXX_CONSTEXPR
435 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
438 { return __builtin_sin(__x); }
442 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
443 inline _GLIBCXX_CONSTEXPR float
445 { return __builtin_sinhf(__x); }
447 inline _GLIBCXX_CONSTEXPR long double
448 sinh(long double __x)
449 { return __builtin_sinhl(__x); }
452 template<typename _Tp>
453 inline _GLIBCXX_CONSTEXPR
454 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
457 { return __builtin_sinh(__x); }
461 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
462 inline _GLIBCXX_CONSTEXPR float
464 { return __builtin_sqrtf(__x); }
466 inline _GLIBCXX_CONSTEXPR long double
467 sqrt(long double __x)
468 { return __builtin_sqrtl(__x); }
471 template<typename _Tp>
472 inline _GLIBCXX_CONSTEXPR
473 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
476 { return __builtin_sqrt(__x); }
480 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
481 inline _GLIBCXX_CONSTEXPR float
483 { return __builtin_tanf(__x); }
485 inline _GLIBCXX_CONSTEXPR long double
487 { return __builtin_tanl(__x); }
490 template<typename _Tp>
491 inline _GLIBCXX_CONSTEXPR
492 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
495 { return __builtin_tan(__x); }
499 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
500 inline _GLIBCXX_CONSTEXPR float
502 { return __builtin_tanhf(__x); }
504 inline _GLIBCXX_CONSTEXPR long double
505 tanh(long double __x)
506 { return __builtin_tanhl(__x); }
509 template<typename _Tp>
510 inline _GLIBCXX_CONSTEXPR
511 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
514 { return __builtin_tanh(__x); }
516 #if _GLIBCXX_USE_C99_MATH
517 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
519 // These are possible macros imported from C99-land.
527 #undef isgreaterequal
533 #if __cplusplus >= 201103L
535 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
537 fpclassify(float __x)
538 { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
539 FP_SUBNORMAL, FP_ZERO, __x); }
542 fpclassify(double __x)
543 { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
544 FP_SUBNORMAL, FP_ZERO, __x); }
547 fpclassify(long double __x)
548 { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
549 FP_SUBNORMAL, FP_ZERO, __x); }
552 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
553 template<typename _Tp>
554 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
557 { return __x != 0 ? FP_NORMAL : FP_ZERO; }
560 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
563 { return __builtin_isfinite(__x); }
567 { return __builtin_isfinite(__x); }
570 isfinite(long double __x)
571 { return __builtin_isfinite(__x); }
574 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
575 template<typename _Tp>
576 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
582 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
585 { return __builtin_isinf(__x); }
587 #if _GLIBCXX_HAVE_OBSOLETE_ISINF \
588 && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC
593 { return __builtin_isinf(__x); }
597 isinf(long double __x)
598 { return __builtin_isinf(__x); }
601 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
602 template<typename _Tp>
603 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
609 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
612 { return __builtin_isnan(__x); }
614 #if _GLIBCXX_HAVE_OBSOLETE_ISNAN \
615 && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC
620 { return __builtin_isnan(__x); }
624 isnan(long double __x)
625 { return __builtin_isnan(__x); }
628 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
629 template<typename _Tp>
630 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
636 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
639 { return __builtin_isnormal(__x); }
643 { return __builtin_isnormal(__x); }
646 isnormal(long double __x)
647 { return __builtin_isnormal(__x); }
650 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
651 template<typename _Tp>
652 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
655 { return __x != 0 ? true : false; }
658 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
659 // Note: middle-end/36757 is fixed, __builtin_signbit is type-generic.
662 { return __builtin_signbit(__x); }
666 { return __builtin_signbit(__x); }
669 signbit(long double __x)
670 { return __builtin_signbit(__x); }
673 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
674 template<typename _Tp>
675 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
678 { return __x < 0 ? true : false; }
681 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
683 isgreater(float __x, float __y)
684 { return __builtin_isgreater(__x, __y); }
687 isgreater(double __x, double __y)
688 { return __builtin_isgreater(__x, __y); }
691 isgreater(long double __x, long double __y)
692 { return __builtin_isgreater(__x, __y); }
695 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
696 template<typename _Tp, typename _Up>
698 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
699 && __is_arithmetic<_Up>::__value), bool>::__type
700 isgreater(_Tp __x, _Up __y)
702 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
703 return __builtin_isgreater(__type(__x), __type(__y));
707 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
709 isgreaterequal(float __x, float __y)
710 { return __builtin_isgreaterequal(__x, __y); }
713 isgreaterequal(double __x, double __y)
714 { return __builtin_isgreaterequal(__x, __y); }
717 isgreaterequal(long double __x, long double __y)
718 { return __builtin_isgreaterequal(__x, __y); }
721 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
722 template<typename _Tp, typename _Up>
724 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
725 && __is_arithmetic<_Up>::__value), bool>::__type
726 isgreaterequal(_Tp __x, _Up __y)
728 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
729 return __builtin_isgreaterequal(__type(__x), __type(__y));
733 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
735 isless(float __x, float __y)
736 { return __builtin_isless(__x, __y); }
739 isless(double __x, double __y)
740 { return __builtin_isless(__x, __y); }
743 isless(long double __x, long double __y)
744 { return __builtin_isless(__x, __y); }
747 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
748 template<typename _Tp, typename _Up>
750 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
751 && __is_arithmetic<_Up>::__value), bool>::__type
752 isless(_Tp __x, _Up __y)
754 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
755 return __builtin_isless(__type(__x), __type(__y));
759 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
761 islessequal(float __x, float __y)
762 { return __builtin_islessequal(__x, __y); }
765 islessequal(double __x, double __y)
766 { return __builtin_islessequal(__x, __y); }
769 islessequal(long double __x, long double __y)
770 { return __builtin_islessequal(__x, __y); }
773 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
774 template<typename _Tp, typename _Up>
776 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
777 && __is_arithmetic<_Up>::__value), bool>::__type
778 islessequal(_Tp __x, _Up __y)
780 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
781 return __builtin_islessequal(__type(__x), __type(__y));
785 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
787 islessgreater(float __x, float __y)
788 { return __builtin_islessgreater(__x, __y); }
791 islessgreater(double __x, double __y)
792 { return __builtin_islessgreater(__x, __y); }
795 islessgreater(long double __x, long double __y)
796 { return __builtin_islessgreater(__x, __y); }
799 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
800 template<typename _Tp, typename _Up>
802 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
803 && __is_arithmetic<_Up>::__value), bool>::__type
804 islessgreater(_Tp __x, _Up __y)
806 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
807 return __builtin_islessgreater(__type(__x), __type(__y));
811 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
813 isunordered(float __x, float __y)
814 { return __builtin_isunordered(__x, __y); }
817 isunordered(double __x, double __y)
818 { return __builtin_isunordered(__x, __y); }
821 isunordered(long double __x, long double __y)
822 { return __builtin_isunordered(__x, __y); }
825 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
826 template<typename _Tp, typename _Up>
828 __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value
829 && __is_arithmetic<_Up>::__value), bool>::__type
830 isunordered(_Tp __x, _Up __y)
832 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
833 return __builtin_isunordered(__type(__x), __type(__y));
839 template<typename _Tp>
840 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
844 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
845 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
846 FP_SUBNORMAL, FP_ZERO, __type(__f));
849 template<typename _Tp>
850 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
854 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
855 return __builtin_isfinite(__type(__f));
858 template<typename _Tp>
859 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
863 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
864 return __builtin_isinf(__type(__f));
867 template<typename _Tp>
868 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
872 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
873 return __builtin_isnan(__type(__f));
876 template<typename _Tp>
877 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
881 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
882 return __builtin_isnormal(__type(__f));
885 template<typename _Tp>
886 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
890 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
891 return __builtin_signbit(__type(__f));
894 template<typename _Tp>
895 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
897 isgreater(_Tp __f1, _Tp __f2)
899 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
900 return __builtin_isgreater(__type(__f1), __type(__f2));
903 template<typename _Tp>
904 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
906 isgreaterequal(_Tp __f1, _Tp __f2)
908 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
909 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
912 template<typename _Tp>
913 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
915 isless(_Tp __f1, _Tp __f2)
917 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
918 return __builtin_isless(__type(__f1), __type(__f2));
921 template<typename _Tp>
922 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
924 islessequal(_Tp __f1, _Tp __f2)
926 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
927 return __builtin_islessequal(__type(__f1), __type(__f2));
930 template<typename _Tp>
931 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
933 islessgreater(_Tp __f1, _Tp __f2)
935 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
936 return __builtin_islessgreater(__type(__f1), __type(__f2));
939 template<typename _Tp>
940 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
942 isunordered(_Tp __f1, _Tp __f2)
944 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
945 return __builtin_isunordered(__type(__f1), __type(__f2));
949 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
950 #endif /* _GLIBCXX_USE_C99_MATH */
952 #if __cplusplus >= 201103L
954 #ifdef _GLIBCXX_USE_C99_MATH_TR1
1004 #ifndef _GLIBCXX_NO_C99_ROUNDING_FUNCS
1133 #ifndef _GLIBCXX_NO_C99_ROUNDING_FUNCS
1176 using ::nexttowardf;
1177 using ::nexttowardl;
1211 /// Additional overloads.
1212 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1215 { return __builtin_acoshf(__x); }
1217 constexpr long double
1218 acosh(long double __x)
1219 { return __builtin_acoshl(__x); }
1222 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1223 template<typename _Tp>
1224 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1227 { return __builtin_acosh(__x); }
1230 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1233 { return __builtin_asinhf(__x); }
1235 constexpr long double
1236 asinh(long double __x)
1237 { return __builtin_asinhl(__x); }
1240 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1241 template<typename _Tp>
1242 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1245 { return __builtin_asinh(__x); }
1248 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1251 { return __builtin_atanhf(__x); }
1253 constexpr long double
1254 atanh(long double __x)
1255 { return __builtin_atanhl(__x); }
1258 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1259 template<typename _Tp>
1260 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1263 { return __builtin_atanh(__x); }
1266 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1269 { return __builtin_cbrtf(__x); }
1271 constexpr long double
1272 cbrt(long double __x)
1273 { return __builtin_cbrtl(__x); }
1276 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1277 template<typename _Tp>
1278 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1281 { return __builtin_cbrt(__x); }
1284 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
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 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1295 template<typename _Tp, typename _Up>
1296 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1297 copysign(_Tp __x, _Up __y)
1299 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1300 return copysign(__type(__x), __type(__y));
1304 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1307 { return __builtin_erff(__x); }
1309 constexpr long double
1310 erf(long double __x)
1311 { return __builtin_erfl(__x); }
1314 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1315 template<typename _Tp>
1316 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1319 { return __builtin_erf(__x); }
1322 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1325 { return __builtin_erfcf(__x); }
1327 constexpr long double
1328 erfc(long double __x)
1329 { return __builtin_erfcl(__x); }
1332 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1333 template<typename _Tp>
1334 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1337 { return __builtin_erfc(__x); }
1340 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1343 { return __builtin_exp2f(__x); }
1345 constexpr long double
1346 exp2(long double __x)
1347 { return __builtin_exp2l(__x); }
1350 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1351 template<typename _Tp>
1352 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1355 { return __builtin_exp2(__x); }
1358 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1361 { return __builtin_expm1f(__x); }
1363 constexpr long double
1364 expm1(long double __x)
1365 { return __builtin_expm1l(__x); }
1368 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1369 template<typename _Tp>
1370 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1373 { return __builtin_expm1(__x); }
1376 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1378 fdim(float __x, float __y)
1379 { return __builtin_fdimf(__x, __y); }
1381 constexpr long double
1382 fdim(long double __x, long double __y)
1383 { return __builtin_fdiml(__x, __y); }
1386 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1387 template<typename _Tp, typename _Up>
1388 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1389 fdim(_Tp __x, _Up __y)
1391 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1392 return fdim(__type(__x), __type(__y));
1396 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1398 fma(float __x, float __y, float __z)
1399 { return __builtin_fmaf(__x, __y, __z); }
1401 constexpr long double
1402 fma(long double __x, long double __y, long double __z)
1403 { return __builtin_fmal(__x, __y, __z); }
1406 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1407 template<typename _Tp, typename _Up, typename _Vp>
1408 constexpr typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
1409 fma(_Tp __x, _Up __y, _Vp __z)
1411 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
1412 return fma(__type(__x), __type(__y), __type(__z));
1416 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1418 fmax(float __x, float __y)
1419 { return __builtin_fmaxf(__x, __y); }
1421 constexpr long double
1422 fmax(long double __x, long double __y)
1423 { return __builtin_fmaxl(__x, __y); }
1426 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1427 template<typename _Tp, typename _Up>
1428 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1429 fmax(_Tp __x, _Up __y)
1431 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1432 return fmax(__type(__x), __type(__y));
1436 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1438 fmin(float __x, float __y)
1439 { return __builtin_fminf(__x, __y); }
1441 constexpr long double
1442 fmin(long double __x, long double __y)
1443 { return __builtin_fminl(__x, __y); }
1446 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1447 template<typename _Tp, typename _Up>
1448 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1449 fmin(_Tp __x, _Up __y)
1451 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1452 return fmin(__type(__x), __type(__y));
1456 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1458 hypot(float __x, float __y)
1459 { return __builtin_hypotf(__x, __y); }
1461 constexpr long double
1462 hypot(long double __x, long double __y)
1463 { return __builtin_hypotl(__x, __y); }
1466 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1467 template<typename _Tp, typename _Up>
1468 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1469 hypot(_Tp __x, _Up __y)
1471 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1472 return hypot(__type(__x), __type(__y));
1476 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1479 { return __builtin_ilogbf(__x); }
1482 ilogb(long double __x)
1483 { return __builtin_ilogbl(__x); }
1486 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1487 template<typename _Tp>
1489 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1492 { return __builtin_ilogb(__x); }
1495 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1498 { return __builtin_lgammaf(__x); }
1500 constexpr long double
1501 lgamma(long double __x)
1502 { return __builtin_lgammal(__x); }
1505 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1506 template<typename _Tp>
1507 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1510 { return __builtin_lgamma(__x); }
1513 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1516 { return __builtin_llrintf(__x); }
1519 llrint(long double __x)
1520 { return __builtin_llrintl(__x); }
1523 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1524 template<typename _Tp>
1525 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1528 { return __builtin_llrint(__x); }
1531 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1534 { return __builtin_llroundf(__x); }
1537 llround(long double __x)
1538 { return __builtin_llroundl(__x); }
1541 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1542 template<typename _Tp>
1543 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1546 { return __builtin_llround(__x); }
1549 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1552 { return __builtin_log1pf(__x); }
1554 constexpr long double
1555 log1p(long double __x)
1556 { return __builtin_log1pl(__x); }
1559 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1560 template<typename _Tp>
1561 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1564 { return __builtin_log1p(__x); }
1567 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1571 { return __builtin_log2f(__x); }
1573 constexpr long double
1574 log2(long double __x)
1575 { return __builtin_log2l(__x); }
1578 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1579 template<typename _Tp>
1580 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1583 { return __builtin_log2(__x); }
1586 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1589 { return __builtin_logbf(__x); }
1591 constexpr long double
1592 logb(long double __x)
1593 { return __builtin_logbl(__x); }
1596 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1597 template<typename _Tp>
1598 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1601 { return __builtin_logb(__x); }
1604 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1607 { return __builtin_lrintf(__x); }
1610 lrint(long double __x)
1611 { return __builtin_lrintl(__x); }
1614 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1615 template<typename _Tp>
1616 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1619 { return __builtin_lrint(__x); }
1622 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1625 { return __builtin_lroundf(__x); }
1628 lround(long double __x)
1629 { return __builtin_lroundl(__x); }
1632 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1633 template<typename _Tp>
1634 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1637 { return __builtin_lround(__x); }
1640 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1642 nearbyint(float __x)
1643 { return __builtin_nearbyintf(__x); }
1645 constexpr long double
1646 nearbyint(long double __x)
1647 { return __builtin_nearbyintl(__x); }
1650 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1651 template<typename _Tp>
1652 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1655 { return __builtin_nearbyint(__x); }
1658 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1660 nextafter(float __x, float __y)
1661 { return __builtin_nextafterf(__x, __y); }
1663 constexpr long double
1664 nextafter(long double __x, long double __y)
1665 { return __builtin_nextafterl(__x, __y); }
1668 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1669 template<typename _Tp, typename _Up>
1670 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1671 nextafter(_Tp __x, _Up __y)
1673 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1674 return nextafter(__type(__x), __type(__y));
1678 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1680 nexttoward(float __x, long double __y)
1681 { return __builtin_nexttowardf(__x, __y); }
1683 constexpr long double
1684 nexttoward(long double __x, long double __y)
1685 { return __builtin_nexttowardl(__x, __y); }
1688 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1689 template<typename _Tp>
1690 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1692 nexttoward(_Tp __x, long double __y)
1693 { return __builtin_nexttoward(__x, __y); }
1696 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1698 remainder(float __x, float __y)
1699 { return __builtin_remainderf(__x, __y); }
1701 constexpr long double
1702 remainder(long double __x, long double __y)
1703 { return __builtin_remainderl(__x, __y); }
1706 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1707 template<typename _Tp, typename _Up>
1708 constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1709 remainder(_Tp __x, _Up __y)
1711 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1712 return remainder(__type(__x), __type(__y));
1716 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1718 remquo(float __x, float __y, int* __pquo)
1719 { return __builtin_remquof(__x, __y, __pquo); }
1722 remquo(long double __x, long double __y, int* __pquo)
1723 { return __builtin_remquol(__x, __y, __pquo); }
1726 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1727 template<typename _Tp, typename _Up>
1728 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1729 remquo(_Tp __x, _Up __y, int* __pquo)
1731 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1732 return remquo(__type(__x), __type(__y), __pquo);
1736 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1739 { return __builtin_rintf(__x); }
1741 constexpr long double
1742 rint(long double __x)
1743 { return __builtin_rintl(__x); }
1746 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1747 template<typename _Tp>
1748 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1751 { return __builtin_rint(__x); }
1754 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1757 { return __builtin_roundf(__x); }
1759 constexpr long double
1760 round(long double __x)
1761 { return __builtin_roundl(__x); }
1764 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1765 template<typename _Tp>
1766 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1769 { return __builtin_round(__x); }
1772 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1774 scalbln(float __x, long __ex)
1775 { return __builtin_scalblnf(__x, __ex); }
1777 constexpr long double
1778 scalbln(long double __x, long __ex)
1779 { return __builtin_scalblnl(__x, __ex); }
1782 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1783 template<typename _Tp>
1784 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1786 scalbln(_Tp __x, long __ex)
1787 { return __builtin_scalbln(__x, __ex); }
1790 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1792 scalbn(float __x, int __ex)
1793 { return __builtin_scalbnf(__x, __ex); }
1795 constexpr long double
1796 scalbn(long double __x, int __ex)
1797 { return __builtin_scalbnl(__x, __ex); }
1800 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1801 template<typename _Tp>
1802 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1804 scalbn(_Tp __x, int __ex)
1805 { return __builtin_scalbn(__x, __ex); }
1808 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1811 { return __builtin_tgammaf(__x); }
1813 constexpr long double
1814 tgamma(long double __x)
1815 { return __builtin_tgammal(__x); }
1818 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1819 template<typename _Tp>
1820 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1823 { return __builtin_tgamma(__x); }
1826 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP
1829 { return __builtin_truncf(__x); }
1831 constexpr long double
1832 trunc(long double __x)
1833 { return __builtin_truncl(__x); }
1836 #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT
1837 template<typename _Tp>
1838 constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
1841 { return __builtin_trunc(__x); }
1844 #endif // _GLIBCXX_USE_C99_MATH_TR1
1847 #if __cplusplus > 201402L
1849 // [c.math.hypot3], three-dimensional hypotenuse
1850 #define __cpp_lib_hypot 201603
1852 template<typename _Tp>
1854 __hypot3(_Tp __x, _Tp __y, _Tp __z)
1856 __x = std::abs(__x);
1857 __y = std::abs(__y);
1858 __z = std::abs(__z);
1859 if (_Tp __a = __x < __y ? __y < __z ? __z : __y : __x < __z ? __z : __x)
1860 return __a * std::sqrt((__x / __a) * (__x / __a)
1861 + (__y / __a) * (__y / __a)
1862 + (__z / __a) * (__z / __a));
1868 hypot(float __x, float __y, float __z)
1869 { return std::__hypot3<float>(__x, __y, __z); }
1872 hypot(double __x, double __y, double __z)
1873 { return std::__hypot3<double>(__x, __y, __z); }
1876 hypot(long double __x, long double __y, long double __z)
1877 { return std::__hypot3<long double>(__x, __y, __z); }
1879 template<typename _Tp, typename _Up, typename _Vp>
1880 typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
1881 hypot(_Tp __x, _Up __y, _Vp __z)
1883 using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type;
1884 return std::__hypot3<__type>(__x, __y, __z);
1888 _GLIBCXX_END_NAMESPACE_VERSION
1891 #if _GLIBCXX_USE_STD_SPEC_FUNCS
1892 # include <bits/specfun.h>