1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
27 /** @file include/cmath
28 * This is a Standard C++ Library file. You should @c #include this file
29 * in your programs, rather than any of the @a *.h implementation files.
31 * This is the C++ version of the Standard C Library header @c math.h,
32 * and its contents are (mostly) the same as that header, but are all
33 * contained in the namespace @c std (except for names which are defined
38 // ISO C++ 14882: 26.5 C library
41 #ifndef _GLIBCXX_CMATH
42 #define _GLIBCXX_CMATH 1
44 #pragma GCC system_header
46 #include <bits/c++config.h>
47 #include <bits/cpp_type_traits.h>
48 #include <ext/type_traits.h>
52 // Get rid of those macros defined in <math.h> in lieu of real functions.
78 namespace std _GLIBCXX_VISIBILITY(default)
80 _GLIBCXX_BEGIN_NAMESPACE_VERSION
84 { return __builtin_fabs(__x); }
88 { return __builtin_fabsf(__x); }
92 { return __builtin_fabsl(__x); }
94 template<typename _Tp>
95 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
98 { return __builtin_fabs(__x); }
104 { return __builtin_acosf(__x); }
107 acos(long double __x)
108 { return __builtin_acosl(__x); }
110 template<typename _Tp>
111 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
114 { return __builtin_acos(__x); }
120 { return __builtin_asinf(__x); }
123 asin(long double __x)
124 { return __builtin_asinl(__x); }
126 template<typename _Tp>
127 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
130 { return __builtin_asin(__x); }
136 { return __builtin_atanf(__x); }
139 atan(long double __x)
140 { return __builtin_atanl(__x); }
142 template<typename _Tp>
143 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
146 { return __builtin_atan(__x); }
151 atan2(float __y, float __x)
152 { return __builtin_atan2f(__y, __x); }
155 atan2(long double __y, long double __x)
156 { return __builtin_atan2l(__y, __x); }
158 template<typename _Tp, typename _Up>
159 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
160 && __is_integer<_Up>::__value,
162 atan2(_Tp __y, _Up __x)
163 { return __builtin_atan2(__y, __x); }
169 { return __builtin_ceilf(__x); }
172 ceil(long double __x)
173 { return __builtin_ceill(__x); }
175 template<typename _Tp>
176 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
179 { return __builtin_ceil(__x); }
185 { return __builtin_cosf(__x); }
189 { return __builtin_cosl(__x); }
191 template<typename _Tp>
192 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
195 { return __builtin_cos(__x); }
201 { return __builtin_coshf(__x); }
204 cosh(long double __x)
205 { return __builtin_coshl(__x); }
207 template<typename _Tp>
208 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
211 { return __builtin_cosh(__x); }
217 { return __builtin_expf(__x); }
221 { return __builtin_expl(__x); }
223 template<typename _Tp>
224 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
227 { return __builtin_exp(__x); }
233 { return __builtin_fabsf(__x); }
236 fabs(long double __x)
237 { return __builtin_fabsl(__x); }
239 template<typename _Tp>
240 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
243 { return __builtin_fabs(__x); }
249 { return __builtin_floorf(__x); }
252 floor(long double __x)
253 { return __builtin_floorl(__x); }
255 template<typename _Tp>
256 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
259 { return __builtin_floor(__x); }
264 fmod(float __x, float __y)
265 { return __builtin_fmodf(__x, __y); }
268 fmod(long double __x, long double __y)
269 { return __builtin_fmodl(__x, __y); }
271 template<typename _Tp, typename _Up>
272 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
273 && __is_integer<_Up>::__value,
275 fmod(_Tp __x, _Up __y)
276 { return __builtin_fmod(__x, __y); }
281 frexp(float __x, int* __exp)
282 { return __builtin_frexpf(__x, __exp); }
285 frexp(long double __x, int* __exp)
286 { return __builtin_frexpl(__x, __exp); }
288 template<typename _Tp>
289 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
291 frexp(_Tp __x, int* __exp)
292 { return __builtin_frexp(__x, __exp); }
297 ldexp(float __x, int __exp)
298 { return __builtin_ldexpf(__x, __exp); }
301 ldexp(long double __x, int __exp)
302 { return __builtin_ldexpl(__x, __exp); }
304 template<typename _Tp>
305 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
307 ldexp(_Tp __x, int __exp)
308 { return __builtin_ldexp(__x, __exp); }
314 { return __builtin_logf(__x); }
318 { return __builtin_logl(__x); }
320 template<typename _Tp>
321 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
324 { return __builtin_log(__x); }
330 { return __builtin_log10f(__x); }
333 log10(long double __x)
334 { return __builtin_log10l(__x); }
336 template<typename _Tp>
337 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
340 { return __builtin_log10(__x); }
345 modf(float __x, float* __iptr)
346 { return __builtin_modff(__x, __iptr); }
349 modf(long double __x, long double* __iptr)
350 { return __builtin_modfl(__x, __iptr); }
355 pow(float __x, float __y)
356 { return __builtin_powf(__x, __y); }
359 pow(long double __x, long double __y)
360 { return __builtin_powl(__x, __y); }
363 pow(double __x, int __i)
364 { return __builtin_powi(__x, __i); }
367 pow(float __x, int __n)
368 { return __builtin_powif(__x, __n); }
371 pow(long double __x, int __n)
372 { return __builtin_powil(__x, __n); }
378 { return __builtin_sinf(__x); }
382 { return __builtin_sinl(__x); }
384 template<typename _Tp>
385 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
388 { return __builtin_sin(__x); }
394 { return __builtin_sinhf(__x); }
397 sinh(long double __x)
398 { return __builtin_sinhl(__x); }
400 template<typename _Tp>
401 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
404 { return __builtin_sinh(__x); }
410 { return __builtin_sqrtf(__x); }
413 sqrt(long double __x)
414 { return __builtin_sqrtl(__x); }
416 template<typename _Tp>
417 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
420 { return __builtin_sqrt(__x); }
426 { return __builtin_tanf(__x); }
430 { return __builtin_tanl(__x); }
432 template<typename _Tp>
433 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
436 { return __builtin_tan(__x); }
442 { return __builtin_tanhf(__x); }
445 tanh(long double __x)
446 { return __builtin_tanhl(__x); }
448 template<typename _Tp>
449 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
452 { return __builtin_tanh(__x); }
454 _GLIBCXX_END_NAMESPACE_VERSION
457 #if _GLIBCXX_USE_C99_MATH
458 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
460 // These are possible macros imported from C99-land.
468 #undef isgreaterequal
474 namespace std _GLIBCXX_VISIBILITY(default)
476 _GLIBCXX_BEGIN_NAMESPACE_VERSION
478 template<typename _Tp>
479 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
483 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
484 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
485 FP_SUBNORMAL, FP_ZERO, __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_isfinite(__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_isinf(__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_isnan(__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_isnormal(__type(__f));
524 template<typename _Tp>
525 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
529 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
530 return __builtin_signbit(__type(__f));
533 template<typename _Tp>
534 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
536 isgreater(_Tp __f1, _Tp __f2)
538 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
539 return __builtin_isgreater(__type(__f1), __type(__f2));
542 template<typename _Tp>
543 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
545 isgreaterequal(_Tp __f1, _Tp __f2)
547 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
548 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
551 template<typename _Tp>
552 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
554 isless(_Tp __f1, _Tp __f2)
556 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
557 return __builtin_isless(__type(__f1), __type(__f2));
560 template<typename _Tp>
561 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
563 islessequal(_Tp __f1, _Tp __f2)
565 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
566 return __builtin_islessequal(__type(__f1), __type(__f2));
569 template<typename _Tp>
570 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
572 islessgreater(_Tp __f1, _Tp __f2)
574 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
575 return __builtin_islessgreater(__type(__f1), __type(__f2));
578 template<typename _Tp>
579 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
581 isunordered(_Tp __f1, _Tp __f2)
583 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
584 return __builtin_isunordered(__type(__f1), __type(__f2));
587 _GLIBCXX_END_NAMESPACE_VERSION
590 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */