1 // -*- C++ -*- C math library.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 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 2, 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 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 26.5 C library
37 #include <bits/c++config.h>
39 #pragma GCC system_header
42 // Get rid of those macros defined in <math.h> in lieu of real functions.
70 // Forward declaration of a helper function. This really should be
71 // an `exported' forward declaration.
72 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
74 template<typename _Tp>
78 return __x < _Tp() ? -__x : __x;
83 { return __builtin_fabsf(__x); }
87 { return __builtin_fabs(__x); }
91 { return __builtin_fabsl(__x); }
93 #if _GLIBCPP_HAVE_ACOSF
95 acos(float __x) { return ::acosf(__x); }
98 acos(float __x) { return ::acos(static_cast<double>(__x)); }
103 #if _GLIBCPP_HAVE_ACOSL
105 acos(long double __x) { return ::acosl(__x); }
108 acos(long double __x) { return ::acos(static_cast<double>(__x)); }
111 #if _GLIBCPP_HAVE_ASINF
113 asin(float __x) { return ::asinf(__x); }
116 asin(float __x) { return ::asin(static_cast<double>(__x)); }
121 #if _GLIBCPP_HAVE_ASINL
123 asin(long double __x) { return ::asinl(__x); }
126 asin(long double __x) { return ::asin(static_cast<double>(__x)); }
129 #if _GLIBCPP_HAVE_ATANF
131 atan(float __x) { return ::atanf(__x); }
134 atan(float __x) { return ::atan(static_cast<double>(__x)); }
139 #if _GLIBCPP_HAVE_ATANL
141 atan(long double __x) { return ::atanl(__x); }
144 atan(long double __x) { return ::atan(static_cast<double>(__x)); }
147 #if _GLIBCPP_HAVE_ATAN2F
149 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
152 atan2(float __y, float __x)
153 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
158 #if _GLIBCPP_HAVE_ATAN2L
160 atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
163 atan2(long double __y, long double __x)
164 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
167 #if _GLIBCPP_HAVE_CEILF
169 ceil(float __x) { return ::ceilf(__x); }
172 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
177 #if _GLIBCPP_HAVE_CEILL
179 ceil(long double __x) { return ::ceill(__x); }
182 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
187 { return __builtin_cosf(__x); }
193 { return __builtin_cosl(__x); }
195 #if _GLIBCPP_HAVE_COSHF
197 cosh(float __x) { return ::coshf(__x); }
200 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
205 #if _GLIBCPP_HAVE_COSHL
207 cosh(long double __x) { return ::coshl(__x); }
210 cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
213 #if _GLIBCPP_HAVE_EXPF
215 exp(float __x) { return ::expf(__x); }
218 exp(float __x) { return ::exp(static_cast<double>(__x)); }
223 #if _GLIBCPP_HAVE_EXPL
225 exp(long double __x) { return ::expl(__x); }
228 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
233 { return __builtin_fabsf(__x); }
238 fabs(long double __x)
239 { return __builtin_fabsl(__x); }
241 #if _GLIBCPP_HAVE_FLOORF
243 floor(float __x) { return ::floorf(__x); }
246 floor(float __x) { return ::floor(static_cast<double>(__x)); }
251 #if _GLIBCPP_HAVE_FLOORL
253 floor(long double __x) { return ::floorl(__x); }
256 floor(long double __x) { return ::floor(static_cast<double>(__x)); }
259 #if _GLIBCPP_HAVE_FMODF
261 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
264 fmod(float __x, float __y)
265 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
270 #if _GLIBCPP_HAVE_FMODL
272 fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
275 fmod(long double __x, long double __y)
276 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
279 #if _GLIBCPP_HAVE_FREXPF
281 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
284 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
289 #if _GLIBCPP_HAVE_FREXPL
291 frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
294 frexp(long double __x, int* __exp)
295 { return ::frexp(static_cast<double>(__x), __exp); }
298 #if _GLIBCPP_HAVE_LDEXPF
300 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
303 ldexp(float __x, int __exp)
304 { return ::ldexp(static_cast<double>(__x), __exp); }
309 #if _GLIBCPP_HAVE_LDEXPL
311 ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
314 ldexp(long double __x, int __exp)
315 { return ::ldexp(static_cast<double>(__x), __exp); }
318 #if _GLIBCPP_HAVE_LOGF
320 log(float __x) { return ::logf(__x); }
322 inline float log(float __x)
323 { return ::log(static_cast<double>(__x)); }
328 #if _GLIBCPP_HAVE_LOGL
330 log(long double __x) { return ::logl(__x); }
333 log(long double __x) { return ::log(static_cast<double>(__x)); }
336 #if _GLIBCPP_HAVE_LOG10F
338 log10(float __x) { return ::log10f(__x); }
341 log10(float __x) { return ::log10(static_cast<double>(__x)); }
346 #if _GLIBCPP_HAVE_LOG10L
348 log10(long double __x) { return ::log10l(__x); }
351 log10(long double __x) { return ::log10(static_cast<double>(__x)); }
354 #if _GLIBCPP_HAVE_MODFF
356 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
359 modf(float __x, float* __iptr)
362 double __res = ::modf(static_cast<double>(__x), &__tmp);
363 *__iptr = static_cast<float>(__tmp);
370 #if _GLIBCPP_HAVE_MODFL
372 modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
375 modf(long double __x, long double* __iptr)
378 double __res = ::modf(static_cast<double>(__x), &__tmp);
379 * __iptr = static_cast<long double>(__tmp);
384 template<typename _Tp>
386 __pow_helper(_Tp __x, int __n)
389 ? _Tp(1)/__cmath_power(__x, -__n)
390 : __cmath_power(__x, __n);
393 #if _GLIBCPP_HAVE_POWF
395 pow(float __x, float __y) { return ::powf(__x, __y); }
398 pow(float __x, float __y)
399 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
404 #if _GLIBCPP_HAVE_POWL
406 pow(long double __x, long double __y) { return ::powl(__x, __y); }
409 pow(long double __x, long double __y)
410 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
414 pow(float __x, int __n)
415 { return __pow_helper(__x, __n); }
418 pow(double __x, int __i)
419 { return __pow_helper(__x, __i); }
422 pow(long double __x, int __n)
423 { return __pow_helper(__x, __n); }
427 { return __builtin_sinf(__x); }
433 { return __builtin_sinl(__x); }
435 #if _GLIBCPP_HAVE_SINHF
437 sinh(float __x) { return ::sinhf(__x); }
440 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
445 #if _GLIBCPP_HAVE_SINHL
447 sinh(long double __x) { return ::sinhl(__x); }
450 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
455 { return __builtin_sqrtf(__x); }
460 sqrt(long double __x)
461 { return __builtin_sqrtl(__x); }
463 #if _GLIBCPP_HAVE_TANF
465 tan(float __x) { return ::tanf(__x); }
468 tan(float __x) { return ::tan(static_cast<double>(__x)); }
473 #if _GLIBCPP_HAVE_TANL
475 tan(long double __x) { return ::tanl(__x); }
478 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
481 #if _GLIBCPP_HAVE_TANHF
483 tanh(float __x) { return ::tanhf(__x); }
486 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
491 #if _GLIBCPP_HAVE_TANHL
493 tanh(long double __x) { return ::tanhl(__x); }
496 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
502 // These are possible macros imported from C99-land. For strict
503 // conformance, remove possible C99-injected names from the global
504 // namespace, and sequester them in the __gnu_cxx extension namespace.
507 template<typename _Tp>
509 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
511 template<typename _Tp>
513 __capture_isfinite(_Tp __f) { return isfinite(__f); }
515 template<typename _Tp>
517 __capture_isinf(_Tp __f) { return isinf(__f); }
519 template<typename _Tp>
521 __capture_isnan(_Tp __f) { return isnan(__f); }
523 template<typename _Tp>
525 __capture_isnormal(_Tp __f) { return isnormal(__f); }
527 template<typename _Tp>
529 __capture_signbit(_Tp __f) { return signbit(__f); }
531 template<typename _Tp>
533 __capture_isgreater(_Tp __f1, _Tp __f2)
534 { return isgreater(__f1, __f2); }
536 template<typename _Tp>
538 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
539 { return isgreaterequal(__f1, __f2); }
541 template<typename _Tp>
543 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
545 template<typename _Tp>
547 __capture_islessequal(_Tp __f1, _Tp __f2)
548 { return islessequal(__f1, __f2); }
550 template<typename _Tp>
552 __capture_islessgreater(_Tp __f1, _Tp __f2)
553 { return islessgreater(__f1, __f2); }
555 template<typename _Tp>
557 __capture_isunordered(_Tp __f1, _Tp __f2)
558 { return isunordered(__f1, __f2); }
569 #undef isgreaterequal
578 template<typename _Tp>
580 fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
582 template<typename _Tp>
584 isfinite(_Tp __f) { return __capture_isfinite(__f); }
586 template<typename _Tp>
588 isinf(_Tp __f) { return __capture_isinf(__f); }
590 template<typename _Tp>
592 isnan(_Tp __f) { return __capture_isnan(__f); }
594 template<typename _Tp>
596 isnormal(_Tp __f) { return __capture_isnormal(__f); }
598 template<typename _Tp>
600 signbit(_Tp __f) { return __capture_signbit(__f); }
602 template<typename _Tp>
604 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
606 template<typename _Tp>
608 isgreaterequal(_Tp __f1, _Tp __f2)
609 { return __capture_isgreaterequal(__f1, __f2); }
611 template<typename _Tp>
613 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
615 template<typename _Tp>
617 islessequal(_Tp __f1, _Tp __f2)
618 { return __capture_islessequal(__f1, __f2); }
620 template<typename _Tp>
622 islessgreater(_Tp __f1, _Tp __f2)
623 { return __capture_islessgreater(__f1, __f2); }
625 template<typename _Tp>
627 isunordered(_Tp __f1, _Tp __f2)
628 { return __capture_isunordered(__f1, __f2); }
633 using __gnu_cxx::fpclassify;
634 using __gnu_cxx::isfinite;
635 using __gnu_cxx::isinf;
636 using __gnu_cxx::isnan;
637 using __gnu_cxx::isnormal;
638 using __gnu_cxx::signbit;
639 using __gnu_cxx::isgreater;
640 using __gnu_cxx::isgreaterequal;
641 using __gnu_cxx::isless;
642 using __gnu_cxx::islessequal;
643 using __gnu_cxx::islessgreater;
644 using __gnu_cxx::isunordered;
648 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
650 # include <cmath.tcc>