1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 26.5 C library
36 * This is a Standard C++ Library file. You should @c #include this file
37 * in your programs, rather than any of the "*.h" implementation files.
39 * This is the C++ version of the Standard C Library header @c math.h,
40 * and its contents are (mostly) the same as that header, but are all
41 * contained in the namespace @c std.
47 #pragma GCC system_header
49 #include <bits/c++config.h>
53 // Get rid of those macros defined in <math.h> in lieu of real functions.
81 // Forward declaration of a helper function. This really should be
82 // an `exported' forward declaration.
83 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
85 template<typename _Tp>
89 return __x < _Tp() ? -__x : __x;
94 { return __builtin_fabs(__x); }
98 { return __builtin_fabsf(__x); }
102 { return __builtin_fabsl(__x); }
104 #if _GLIBCPP_HAVE_ACOSF
106 acos(float __x) { return ::acosf(__x); }
109 acos(float __x) { return ::acos(static_cast<double>(__x)); }
114 #if _GLIBCPP_HAVE_ACOSL
116 acos(long double __x) { return ::acosl(__x); }
119 acos(long double __x) { return ::acos(static_cast<double>(__x)); }
124 #if _GLIBCPP_HAVE_ASINF
126 asin(float __x) { return ::asinf(__x); }
129 asin(float __x) { return ::asin(static_cast<double>(__x)); }
132 #if _GLIBCPP_HAVE_ASINL
134 asin(long double __x) { return ::asinl(__x); }
137 asin(long double __x) { return ::asin(static_cast<double>(__x)); }
142 #if _GLIBCPP_HAVE_ATANF
144 atan(float __x) { return ::atanf(__x); }
147 atan(float __x) { return ::atan(static_cast<double>(__x)); }
150 #if _GLIBCPP_HAVE_ATANL
152 atan(long double __x) { return ::atanl(__x); }
155 atan(long double __x) { return ::atan(static_cast<double>(__x)); }
160 #if _GLIBCPP_HAVE_ATAN2F
162 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
165 atan2(float __y, float __x)
166 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
169 #if _GLIBCPP_HAVE_ATAN2L
171 atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
174 atan2(long double __y, long double __x)
175 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
180 #if _GLIBCPP_HAVE_CEILF
182 ceil(float __x) { return ::ceilf(__x); }
185 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
188 #if _GLIBCPP_HAVE_CEILL
190 ceil(long double __x) { return ::ceill(__x); }
193 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
200 { return __builtin_cosf(__x); }
204 { return __builtin_cosl(__x); }
208 #if _GLIBCPP_HAVE_COSHF
210 cosh(float __x) { return ::coshf(__x); }
213 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
216 #if _GLIBCPP_HAVE_COSHL
218 cosh(long double __x) { return ::coshl(__x); }
221 cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
226 #if _GLIBCPP_HAVE_EXPF
228 exp(float __x) { return ::expf(__x); }
231 exp(float __x) { return ::exp(static_cast<double>(__x)); }
234 #if _GLIBCPP_HAVE_EXPL
236 exp(long double __x) { return ::expl(__x); }
239 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
246 { return __builtin_fabsf(__x); }
249 fabs(long double __x)
250 { return __builtin_fabsl(__x); }
254 #if _GLIBCPP_HAVE_FLOORF
256 floor(float __x) { return ::floorf(__x); }
259 floor(float __x) { return ::floor(static_cast<double>(__x)); }
262 #if _GLIBCPP_HAVE_FLOORL
264 floor(long double __x) { return ::floorl(__x); }
267 floor(long double __x) { return ::floor(static_cast<double>(__x)); }
272 #if _GLIBCPP_HAVE_FMODF
274 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
277 fmod(float __x, float __y)
278 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
281 #if _GLIBCPP_HAVE_FMODL
283 fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
286 fmod(long double __x, long double __y)
287 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
292 #if _GLIBCPP_HAVE_FREXPF
294 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
297 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
300 #if _GLIBCPP_HAVE_FREXPL
302 frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
305 frexp(long double __x, int* __exp)
306 { return ::frexp(static_cast<double>(__x), __exp); }
311 #if _GLIBCPP_HAVE_LDEXPF
313 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
316 ldexp(float __x, int __exp)
317 { return ::ldexp(static_cast<double>(__x), __exp); }
320 #if _GLIBCPP_HAVE_LDEXPL
322 ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
325 ldexp(long double __x, int __exp)
326 { return ::ldexp(static_cast<double>(__x), __exp); }
331 #if _GLIBCPP_HAVE_LOGF
333 log(float __x) { return ::logf(__x); }
335 inline float log(float __x)
336 { return ::log(static_cast<double>(__x)); }
339 #if _GLIBCPP_HAVE_LOGL
341 log(long double __x) { return ::logl(__x); }
344 log(long double __x) { return ::log(static_cast<double>(__x)); }
349 #if _GLIBCPP_HAVE_LOG10F
351 log10(float __x) { return ::log10f(__x); }
354 log10(float __x) { return ::log10(static_cast<double>(__x)); }
357 #if _GLIBCPP_HAVE_LOG10L
359 log10(long double __x) { return ::log10l(__x); }
362 log10(long double __x) { return ::log10(static_cast<double>(__x)); }
367 #if _GLIBCPP_HAVE_MODFF
369 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
372 modf(float __x, float* __iptr)
375 double __res = ::modf(static_cast<double>(__x), &__tmp);
376 *__iptr = static_cast<float>(__tmp);
381 #if _GLIBCPP_HAVE_MODFL
383 modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
386 modf(long double __x, long double* __iptr)
389 double __res = ::modf(static_cast<double>(__x), &__tmp);
390 * __iptr = static_cast<long double>(__tmp);
395 template<typename _Tp>
397 __pow_helper(_Tp __x, int __n)
400 ? _Tp(1)/__cmath_power(__x, -__n)
401 : __cmath_power(__x, __n);
406 #if _GLIBCPP_HAVE_POWF
408 pow(float __x, float __y) { return ::powf(__x, __y); }
411 pow(float __x, float __y)
412 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
415 #if _GLIBCPP_HAVE_POWL
417 pow(long double __x, long double __y) { return ::powl(__x, __y); }
420 pow(long double __x, long double __y)
421 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
425 pow(double __x, int __i)
426 { return __pow_helper(__x, __i); }
429 pow(float __x, int __n)
430 { return __pow_helper(__x, __n); }
433 pow(long double __x, int __n)
434 { return __pow_helper(__x, __n); }
440 { return __builtin_sinf(__x); }
444 { return __builtin_sinl(__x); }
448 #if _GLIBCPP_HAVE_SINHF
450 sinh(float __x) { return ::sinhf(__x); }
453 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
456 #if _GLIBCPP_HAVE_SINHL
458 sinh(long double __x) { return ::sinhl(__x); }
461 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
468 { return __builtin_sqrtf(__x); }
471 sqrt(long double __x)
472 { return __builtin_sqrtl(__x); }
476 #if _GLIBCPP_HAVE_TANF
478 tan(float __x) { return ::tanf(__x); }
481 tan(float __x) { return ::tan(static_cast<double>(__x)); }
484 #if _GLIBCPP_HAVE_TANL
486 tan(long double __x) { return ::tanl(__x); }
489 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
494 #if _GLIBCPP_HAVE_TANHF
496 tanh(float __x) { return ::tanhf(__x); }
499 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
502 #if _GLIBCPP_HAVE_TANHL
504 tanh(long double __x) { return ::tanhl(__x); }
507 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
513 // These are possible macros imported from C99-land. For strict
514 // conformance, remove possible C99-injected names from the global
515 // namespace, and sequester them in the __gnu_cxx extension namespace.
518 template<typename _Tp>
520 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
522 template<typename _Tp>
524 __capture_isfinite(_Tp __f) { return isfinite(__f); }
526 template<typename _Tp>
528 __capture_isinf(_Tp __f) { return isinf(__f); }
530 template<typename _Tp>
532 __capture_isnan(_Tp __f) { return isnan(__f); }
534 template<typename _Tp>
536 __capture_isnormal(_Tp __f) { return isnormal(__f); }
538 template<typename _Tp>
540 __capture_signbit(_Tp __f) { return signbit(__f); }
542 template<typename _Tp>
544 __capture_isgreater(_Tp __f1, _Tp __f2)
545 { return isgreater(__f1, __f2); }
547 template<typename _Tp>
549 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
550 { return isgreaterequal(__f1, __f2); }
552 template<typename _Tp>
554 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
556 template<typename _Tp>
558 __capture_islessequal(_Tp __f1, _Tp __f2)
559 { return islessequal(__f1, __f2); }
561 template<typename _Tp>
563 __capture_islessgreater(_Tp __f1, _Tp __f2)
564 { return islessgreater(__f1, __f2); }
566 template<typename _Tp>
568 __capture_isunordered(_Tp __f1, _Tp __f2)
569 { return isunordered(__f1, __f2); }
580 #undef isgreaterequal
589 template<typename _Tp>
591 fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
593 template<typename _Tp>
595 isfinite(_Tp __f) { return __capture_isfinite(__f); }
597 template<typename _Tp>
599 isinf(_Tp __f) { return __capture_isinf(__f); }
601 template<typename _Tp>
603 isnan(_Tp __f) { return __capture_isnan(__f); }
605 template<typename _Tp>
607 isnormal(_Tp __f) { return __capture_isnormal(__f); }
609 template<typename _Tp>
611 signbit(_Tp __f) { return __capture_signbit(__f); }
613 template<typename _Tp>
615 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
617 template<typename _Tp>
619 isgreaterequal(_Tp __f1, _Tp __f2)
620 { return __capture_isgreaterequal(__f1, __f2); }
622 template<typename _Tp>
624 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
626 template<typename _Tp>
628 islessequal(_Tp __f1, _Tp __f2)
629 { return __capture_islessequal(__f1, __f2); }
631 template<typename _Tp>
633 islessgreater(_Tp __f1, _Tp __f2)
634 { return __capture_islessgreater(__f1, __f2); }
636 template<typename _Tp>
638 isunordered(_Tp __f1, _Tp __f2)
639 { return __capture_isunordered(__f1, __f2); }
644 using __gnu_cxx::fpclassify;
645 using __gnu_cxx::isfinite;
646 using __gnu_cxx::isinf;
647 using __gnu_cxx::isnan;
648 using __gnu_cxx::isnormal;
649 using __gnu_cxx::signbit;
650 using __gnu_cxx::isgreater;
651 using __gnu_cxx::isgreaterequal;
652 using __gnu_cxx::isless;
653 using __gnu_cxx::islessequal;
654 using __gnu_cxx::islessgreater;
655 using __gnu_cxx::isunordered;
659 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
661 # include <bits/cmath.tcc>