1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009
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 "*.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 _GLIBCXX_BEGIN_NAMESPACE(std)
80 // Forward declaration of a helper function. This really should be
81 // an `exported' forward declaration.
82 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
86 { return __builtin_fabs(__x); }
90 { return __builtin_fabsf(__x); }
94 { return __builtin_fabsl(__x); }
100 { return __builtin_acosf(__x); }
103 acos(long double __x)
104 { return __builtin_acosl(__x); }
106 template<typename _Tp>
107 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
110 { return __builtin_acos(__x); }
116 { return __builtin_asinf(__x); }
119 asin(long double __x)
120 { return __builtin_asinl(__x); }
122 template<typename _Tp>
123 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
126 { return __builtin_asin(__x); }
132 { return __builtin_atanf(__x); }
135 atan(long double __x)
136 { return __builtin_atanl(__x); }
138 template<typename _Tp>
139 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
142 { return __builtin_atan(__x); }
147 atan2(float __y, float __x)
148 { return __builtin_atan2f(__y, __x); }
151 atan2(long double __y, long double __x)
152 { return __builtin_atan2l(__y, __x); }
154 template<typename _Tp, typename _Up>
155 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
156 && __is_integer<_Up>::__value,
158 atan2(_Tp __y, _Up __x)
159 { return __builtin_atan2(__y, __x); }
165 { return __builtin_ceilf(__x); }
168 ceil(long double __x)
169 { return __builtin_ceill(__x); }
171 template<typename _Tp>
172 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
175 { return __builtin_ceil(__x); }
181 { return __builtin_cosf(__x); }
185 { return __builtin_cosl(__x); }
187 template<typename _Tp>
188 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
191 { return __builtin_cos(__x); }
197 { return __builtin_coshf(__x); }
200 cosh(long double __x)
201 { return __builtin_coshl(__x); }
203 template<typename _Tp>
204 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
207 { return __builtin_cosh(__x); }
213 { return __builtin_expf(__x); }
217 { return __builtin_expl(__x); }
219 template<typename _Tp>
220 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
223 { return __builtin_exp(__x); }
229 { return __builtin_fabsf(__x); }
232 fabs(long double __x)
233 { return __builtin_fabsl(__x); }
235 template<typename _Tp>
236 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
239 { return __builtin_fabs(__x); }
245 { return __builtin_floorf(__x); }
248 floor(long double __x)
249 { return __builtin_floorl(__x); }
251 template<typename _Tp>
252 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
255 { return __builtin_floor(__x); }
260 fmod(float __x, float __y)
261 { return __builtin_fmodf(__x, __y); }
264 fmod(long double __x, long double __y)
265 { return __builtin_fmodl(__x, __y); }
270 frexp(float __x, int* __exp)
271 { return __builtin_frexpf(__x, __exp); }
274 frexp(long double __x, int* __exp)
275 { return __builtin_frexpl(__x, __exp); }
277 template<typename _Tp>
278 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
280 frexp(_Tp __x, int* __exp)
281 { return __builtin_frexp(__x, __exp); }
286 ldexp(float __x, int __exp)
287 { return __builtin_ldexpf(__x, __exp); }
290 ldexp(long double __x, int __exp)
291 { return __builtin_ldexpl(__x, __exp); }
293 template<typename _Tp>
294 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
296 ldexp(_Tp __x, int __exp)
297 { return __builtin_ldexp(__x, __exp); }
303 { return __builtin_logf(__x); }
307 { return __builtin_logl(__x); }
309 template<typename _Tp>
310 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
313 { return __builtin_log(__x); }
319 { return __builtin_log10f(__x); }
322 log10(long double __x)
323 { return __builtin_log10l(__x); }
325 template<typename _Tp>
326 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
329 { return __builtin_log10(__x); }
334 modf(float __x, float* __iptr)
335 { return __builtin_modff(__x, __iptr); }
338 modf(long double __x, long double* __iptr)
339 { return __builtin_modfl(__x, __iptr); }
341 template<typename _Tp>
343 __pow_helper(_Tp __x, int __n)
346 ? _Tp(1)/__cmath_power(__x, -__n)
347 : __cmath_power(__x, __n);
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 _GLIBCXX_END_NAMESPACE
454 #if _GLIBCXX_USE_C99_MATH
455 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
457 // These are possible macros imported from C99-land.
465 #undef isgreaterequal
471 _GLIBCXX_BEGIN_NAMESPACE(std)
473 template<typename _Tp>
474 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
478 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
479 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
480 FP_SUBNORMAL, FP_ZERO, __type(__f));
483 template<typename _Tp>
484 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
488 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
489 return __builtin_isfinite(__type(__f));
492 template<typename _Tp>
493 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
497 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
498 return __builtin_isinf(__type(__f));
501 template<typename _Tp>
502 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
506 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
507 return __builtin_isnan(__type(__f));
510 template<typename _Tp>
511 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
515 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
516 return __builtin_isnormal(__type(__f));
519 template<typename _Tp>
520 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
524 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
525 return __builtin_signbit(__type(__f));
528 template<typename _Tp>
529 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
531 isgreater(_Tp __f1, _Tp __f2)
533 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
534 return __builtin_isgreater(__type(__f1), __type(__f2));
537 template<typename _Tp>
538 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
540 isgreaterequal(_Tp __f1, _Tp __f2)
542 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
543 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
546 template<typename _Tp>
547 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
549 isless(_Tp __f1, _Tp __f2)
551 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
552 return __builtin_isless(__type(__f1), __type(__f2));
555 template<typename _Tp>
556 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
558 islessequal(_Tp __f1, _Tp __f2)
560 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
561 return __builtin_islessequal(__type(__f1), __type(__f2));
564 template<typename _Tp>
565 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
567 islessgreater(_Tp __f1, _Tp __f2)
569 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
570 return __builtin_islessgreater(__type(__f1), __type(__f2));
573 template<typename _Tp>
574 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
576 isunordered(_Tp __f1, _Tp __f2)
578 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
579 return __builtin_isunordered(__type(__f1), __type(__f2));
582 _GLIBCXX_END_NAMESPACE
584 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
587 #ifndef _GLIBCXX_EXPORT_TEMPLATE
588 # include <bits/cmath.tcc>