1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
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 2, 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 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
32 /** @file include/cmath
33 * This is a Standard C++ Library file. You should @c #include this file
34 * in your programs, rather than any of the "*.h" implementation files.
36 * This is the C++ version of the Standard C Library header @c math.h,
37 * and its contents are (mostly) the same as that header, but are all
38 * contained in the namespace @c std (except for names which are defined
43 // ISO C++ 14882: 26.5 C library
46 #ifndef _GLIBCXX_CMATH
47 #define _GLIBCXX_CMATH 1
49 #pragma GCC system_header
51 #include <bits/c++config.h>
52 #include <bits/cpp_type_traits.h>
53 #include <ext/type_traits.h>
57 // Get rid of those macros defined in <math.h> in lieu of real functions.
83 _GLIBCXX_BEGIN_NAMESPACE(std)
85 // Forward declaration of a helper function. This really should be
86 // an `exported' forward declaration.
87 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
91 { return __builtin_fabs(__x); }
95 { return __builtin_fabsf(__x); }
99 { return __builtin_fabsl(__x); }
105 { return __builtin_acosf(__x); }
108 acos(long double __x)
109 { return __builtin_acosl(__x); }
111 template<typename _Tp>
112 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
115 { return __builtin_acos(__x); }
121 { return __builtin_asinf(__x); }
124 asin(long double __x)
125 { return __builtin_asinl(__x); }
127 template<typename _Tp>
128 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
131 { return __builtin_asin(__x); }
137 { return __builtin_atanf(__x); }
140 atan(long double __x)
141 { return __builtin_atanl(__x); }
143 template<typename _Tp>
144 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
147 { return __builtin_atan(__x); }
152 atan2(float __y, float __x)
153 { return __builtin_atan2f(__y, __x); }
156 atan2(long double __y, long double __x)
157 { return __builtin_atan2l(__y, __x); }
159 template<typename _Tp, typename _Up>
160 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
161 && __is_integer<_Up>::__value,
163 atan2(_Tp __y, _Up __x)
164 { return __builtin_atan2(__y, __x); }
170 { return __builtin_ceilf(__x); }
173 ceil(long double __x)
174 { return __builtin_ceill(__x); }
176 template<typename _Tp>
177 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
180 { return __builtin_ceil(__x); }
186 { return __builtin_cosf(__x); }
190 { return __builtin_cosl(__x); }
192 template<typename _Tp>
193 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
196 { return __builtin_cos(__x); }
202 { return __builtin_coshf(__x); }
205 cosh(long double __x)
206 { return __builtin_coshl(__x); }
208 template<typename _Tp>
209 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
212 { return __builtin_cosh(__x); }
218 { return __builtin_expf(__x); }
222 { return __builtin_expl(__x); }
224 template<typename _Tp>
225 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
228 { return __builtin_exp(__x); }
234 { return __builtin_fabsf(__x); }
237 fabs(long double __x)
238 { return __builtin_fabsl(__x); }
240 template<typename _Tp>
241 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
244 { return __builtin_fabs(__x); }
250 { return __builtin_floorf(__x); }
253 floor(long double __x)
254 { return __builtin_floorl(__x); }
256 template<typename _Tp>
257 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
260 { return __builtin_floor(__x); }
265 fmod(float __x, float __y)
266 { return __builtin_fmodf(__x, __y); }
269 fmod(long double __x, long double __y)
270 { return __builtin_fmodl(__x, __y); }
275 frexp(float __x, int* __exp)
276 { return __builtin_frexpf(__x, __exp); }
279 frexp(long double __x, int* __exp)
280 { return __builtin_frexpl(__x, __exp); }
282 template<typename _Tp>
283 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
285 frexp(_Tp __x, int* __exp)
286 { return __builtin_frexp(__x, __exp); }
291 ldexp(float __x, int __exp)
292 { return __builtin_ldexpf(__x, __exp); }
295 ldexp(long double __x, int __exp)
296 { return __builtin_ldexpl(__x, __exp); }
298 template<typename _Tp>
299 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
301 ldexp(_Tp __x, int __exp)
302 { return __builtin_ldexp(__x, __exp); }
308 { return __builtin_logf(__x); }
312 { return __builtin_logl(__x); }
314 template<typename _Tp>
315 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
318 { return __builtin_log(__x); }
324 { return __builtin_log10f(__x); }
327 log10(long double __x)
328 { return __builtin_log10l(__x); }
330 template<typename _Tp>
331 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
334 { return __builtin_log10(__x); }
339 modf(float __x, float* __iptr)
340 { return __builtin_modff(__x, __iptr); }
343 modf(long double __x, long double* __iptr)
344 { return __builtin_modfl(__x, __iptr); }
346 template<typename _Tp>
348 __pow_helper(_Tp __x, int __n)
351 ? _Tp(1)/__cmath_power(__x, -__n)
352 : __cmath_power(__x, __n);
358 pow(float __x, float __y)
359 { return __builtin_powf(__x, __y); }
362 pow(long double __x, long double __y)
363 { return __builtin_powl(__x, __y); }
366 pow(double __x, int __i)
367 { return __builtin_powi(__x, __i); }
370 pow(float __x, int __n)
371 { return __builtin_powif(__x, __n); }
374 pow(long double __x, int __n)
375 { return __builtin_powil(__x, __n); }
381 { return __builtin_sinf(__x); }
385 { return __builtin_sinl(__x); }
387 template<typename _Tp>
388 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
391 { return __builtin_sin(__x); }
397 { return __builtin_sinhf(__x); }
400 sinh(long double __x)
401 { return __builtin_sinhl(__x); }
403 template<typename _Tp>
404 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
407 { return __builtin_sinh(__x); }
413 { return __builtin_sqrtf(__x); }
416 sqrt(long double __x)
417 { return __builtin_sqrtl(__x); }
419 template<typename _Tp>
420 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
423 { return __builtin_sqrt(__x); }
429 { return __builtin_tanf(__x); }
433 { return __builtin_tanl(__x); }
435 template<typename _Tp>
436 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
439 { return __builtin_tan(__x); }
445 { return __builtin_tanhf(__x); }
448 tanh(long double __x)
449 { return __builtin_tanhl(__x); }
451 template<typename _Tp>
452 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
455 { return __builtin_tanh(__x); }
457 _GLIBCXX_END_NAMESPACE
459 #if _GLIBCXX_USE_C99_MATH
460 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
462 // These are possible macros imported from C99-land.
470 #undef isgreaterequal
476 _GLIBCXX_BEGIN_NAMESPACE(std)
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
589 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
592 #ifndef _GLIBCXX_EXPORT_TEMPLATE
593 # include <bits/cmath.tcc>