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 #ifndef _GLIBCXX_CMATH
40 #define _GLIBCXX_CMATH 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
45 #include <bits/cpp_type_traits.h>
46 #include <ext/type_traits.h>
50 // Get rid of those macros defined in <math.h> in lieu of real functions.
76 namespace std _GLIBCXX_VISIBILITY(default)
78 _GLIBCXX_BEGIN_NAMESPACE_VERSION
82 { return __builtin_fabs(__x); }
86 { return __builtin_fabsf(__x); }
90 { return __builtin_fabsl(__x); }
92 template<typename _Tp>
93 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
96 { return __builtin_fabs(__x); }
102 { return __builtin_acosf(__x); }
105 acos(long double __x)
106 { return __builtin_acosl(__x); }
108 template<typename _Tp>
109 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
112 { return __builtin_acos(__x); }
118 { return __builtin_asinf(__x); }
121 asin(long double __x)
122 { return __builtin_asinl(__x); }
124 template<typename _Tp>
125 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
128 { return __builtin_asin(__x); }
134 { return __builtin_atanf(__x); }
137 atan(long double __x)
138 { return __builtin_atanl(__x); }
140 template<typename _Tp>
141 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
144 { return __builtin_atan(__x); }
149 atan2(float __y, float __x)
150 { return __builtin_atan2f(__y, __x); }
153 atan2(long double __y, long double __x)
154 { return __builtin_atan2l(__y, __x); }
156 template<typename _Tp, typename _Up>
157 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
158 && __is_integer<_Up>::__value,
160 atan2(_Tp __y, _Up __x)
161 { return __builtin_atan2(__y, __x); }
167 { return __builtin_ceilf(__x); }
170 ceil(long double __x)
171 { return __builtin_ceill(__x); }
173 template<typename _Tp>
174 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
177 { return __builtin_ceil(__x); }
183 { return __builtin_cosf(__x); }
187 { return __builtin_cosl(__x); }
189 template<typename _Tp>
190 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
193 { return __builtin_cos(__x); }
199 { return __builtin_coshf(__x); }
202 cosh(long double __x)
203 { return __builtin_coshl(__x); }
205 template<typename _Tp>
206 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
209 { return __builtin_cosh(__x); }
215 { return __builtin_expf(__x); }
219 { return __builtin_expl(__x); }
221 template<typename _Tp>
222 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
225 { return __builtin_exp(__x); }
231 { return __builtin_fabsf(__x); }
234 fabs(long double __x)
235 { return __builtin_fabsl(__x); }
237 template<typename _Tp>
238 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
241 { return __builtin_fabs(__x); }
247 { return __builtin_floorf(__x); }
250 floor(long double __x)
251 { return __builtin_floorl(__x); }
253 template<typename _Tp>
254 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
257 { return __builtin_floor(__x); }
262 fmod(float __x, float __y)
263 { return __builtin_fmodf(__x, __y); }
266 fmod(long double __x, long double __y)
267 { return __builtin_fmodl(__x, __y); }
269 template<typename _Tp, typename _Up>
270 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
271 && __is_integer<_Up>::__value,
273 fmod(_Tp __x, _Up __y)
274 { return __builtin_fmod(__x, __y); }
279 frexp(float __x, int* __exp)
280 { return __builtin_frexpf(__x, __exp); }
283 frexp(long double __x, int* __exp)
284 { return __builtin_frexpl(__x, __exp); }
286 template<typename _Tp>
287 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
289 frexp(_Tp __x, int* __exp)
290 { return __builtin_frexp(__x, __exp); }
295 ldexp(float __x, int __exp)
296 { return __builtin_ldexpf(__x, __exp); }
299 ldexp(long double __x, int __exp)
300 { return __builtin_ldexpl(__x, __exp); }
302 template<typename _Tp>
303 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
305 ldexp(_Tp __x, int __exp)
306 { return __builtin_ldexp(__x, __exp); }
312 { return __builtin_logf(__x); }
316 { return __builtin_logl(__x); }
318 template<typename _Tp>
319 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
322 { return __builtin_log(__x); }
328 { return __builtin_log10f(__x); }
331 log10(long double __x)
332 { return __builtin_log10l(__x); }
334 template<typename _Tp>
335 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
338 { return __builtin_log10(__x); }
343 modf(float __x, float* __iptr)
344 { return __builtin_modff(__x, __iptr); }
347 modf(long double __x, long double* __iptr)
348 { return __builtin_modfl(__x, __iptr); }
353 pow(float __x, float __y)
354 { return __builtin_powf(__x, __y); }
357 pow(long double __x, long double __y)
358 { return __builtin_powl(__x, __y); }
361 pow(double __x, int __i)
362 { return __builtin_powi(__x, __i); }
365 pow(float __x, int __n)
366 { return __builtin_powif(__x, __n); }
369 pow(long double __x, int __n)
370 { return __builtin_powil(__x, __n); }
376 { return __builtin_sinf(__x); }
380 { return __builtin_sinl(__x); }
382 template<typename _Tp>
383 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
386 { return __builtin_sin(__x); }
392 { return __builtin_sinhf(__x); }
395 sinh(long double __x)
396 { return __builtin_sinhl(__x); }
398 template<typename _Tp>
399 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
402 { return __builtin_sinh(__x); }
408 { return __builtin_sqrtf(__x); }
411 sqrt(long double __x)
412 { return __builtin_sqrtl(__x); }
414 template<typename _Tp>
415 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
418 { return __builtin_sqrt(__x); }
424 { return __builtin_tanf(__x); }
428 { return __builtin_tanl(__x); }
430 template<typename _Tp>
431 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
434 { return __builtin_tan(__x); }
440 { return __builtin_tanhf(__x); }
443 tanh(long double __x)
444 { return __builtin_tanhl(__x); }
446 template<typename _Tp>
447 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
450 { return __builtin_tanh(__x); }
452 #if _GLIBCXX_USE_C99_MATH
453 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
455 // These are possible macros imported from C99-land.
463 #undef isgreaterequal
469 template<typename _Tp>
470 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
474 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
475 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
476 FP_SUBNORMAL, FP_ZERO, __type(__f));
479 template<typename _Tp>
480 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
484 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
485 return __builtin_isfinite(__type(__f));
488 template<typename _Tp>
489 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
493 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
494 return __builtin_isinf(__type(__f));
497 template<typename _Tp>
498 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
502 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
503 return __builtin_isnan(__type(__f));
506 template<typename _Tp>
507 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
511 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
512 return __builtin_isnormal(__type(__f));
515 template<typename _Tp>
516 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
520 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
521 return __builtin_signbit(__type(__f));
524 template<typename _Tp>
525 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
527 isgreater(_Tp __f1, _Tp __f2)
529 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
530 return __builtin_isgreater(__type(__f1), __type(__f2));
533 template<typename _Tp>
534 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
536 isgreaterequal(_Tp __f1, _Tp __f2)
538 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
539 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
542 template<typename _Tp>
543 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
545 isless(_Tp __f1, _Tp __f2)
547 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
548 return __builtin_isless(__type(__f1), __type(__f2));
551 template<typename _Tp>
552 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
554 islessequal(_Tp __f1, _Tp __f2)
556 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
557 return __builtin_islessequal(__type(__f1), __type(__f2));
560 template<typename _Tp>
561 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
563 islessgreater(_Tp __f1, _Tp __f2)
565 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
566 return __builtin_islessgreater(__type(__f1), __type(__f2));
569 template<typename _Tp>
570 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
572 isunordered(_Tp __f1, _Tp __f2)
574 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
575 return __builtin_isunordered(__type(__f1), __type(__f2));
578 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
579 #endif /* _GLIBCXX_USE_C99_MATH */
581 _GLIBCXX_END_NAMESPACE_VERSION