]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/c_std/std_cmath.h
e804e72d69ba3a62e57af8f358d007f722358d66
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_fabsf(__x
); }
98 { return __builtin_fabs(__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
)); }
122 #if _GLIBCPP_HAVE_ASINF
124 asin(float __x
) { return ::asinf(__x
); }
127 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
)); }
140 #if _GLIBCPP_HAVE_ATANF
142 atan(float __x
) { return ::atanf(__x
); }
145 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
)); }
158 #if _GLIBCPP_HAVE_ATAN2F
160 atan2(float __y
, float __x
) { return ::atan2f(__y
, __x
); }
163 atan2(float __y
, float __x
)
164 { 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
)); }
178 #if _GLIBCPP_HAVE_CEILF
180 ceil(float __x
) { return ::ceilf(__x
); }
183 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
)); }
198 { return __builtin_cosf(__x
); }
204 { return __builtin_cosl(__x
); }
206 #if _GLIBCPP_HAVE_COSHF
208 cosh(float __x
) { return ::coshf(__x
); }
211 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
)); }
224 #if _GLIBCPP_HAVE_EXPF
226 exp(float __x
) { return ::expf(__x
); }
229 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
)); }
244 { return __builtin_fabsf(__x
); }
249 fabs(long double __x
)
250 { return __builtin_fabsl(__x
); }
252 #if _GLIBCPP_HAVE_FLOORF
254 floor(float __x
) { return ::floorf(__x
); }
257 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
)); }
270 #if _GLIBCPP_HAVE_FMODF
272 fmod(float __x
, float __y
) { return ::fmodf(__x
, __y
); }
275 fmod(float __x
, float __y
)
276 { 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
)); }
290 #if _GLIBCPP_HAVE_FREXPF
292 frexp(float __x
, int* __exp
) { return ::frexpf(__x
, __exp
); }
295 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
); }
309 #if _GLIBCPP_HAVE_LDEXPF
311 ldexp(float __x
, int __exp
) { return ::ldexpf(__x
, __exp
); }
314 ldexp(float __x
, int __exp
)
315 { 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
); }
329 #if _GLIBCPP_HAVE_LOGF
331 log(float __x
) { return ::logf(__x
); }
333 inline float log(float __x
)
334 { 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
)); }
347 #if _GLIBCPP_HAVE_LOG10F
349 log10(float __x
) { return ::log10f(__x
); }
352 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
)); }
365 #if _GLIBCPP_HAVE_MODFF
367 modf(float __x
, float* __iptr
) { return ::modff(__x
, __iptr
); }
370 modf(float __x
, float* __iptr
)
373 double __res
= ::modf(static_cast<double>(__x
), &__tmp
);
374 *__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
);
404 #if _GLIBCPP_HAVE_POWF
406 pow(float __x
, float __y
) { return ::powf(__x
, __y
); }
409 pow(float __x
, float __y
)
410 { 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(float __x
, int __n
)
426 { return __pow_helper(__x
, __n
); }
429 pow(double __x
, int __i
)
430 { return __pow_helper(__x
, __i
); }
433 pow(long double __x
, int __n
)
434 { return __pow_helper(__x
, __n
); }
438 { return __builtin_sinf(__x
); }
444 { return __builtin_sinl(__x
); }
446 #if _GLIBCPP_HAVE_SINHF
448 sinh(float __x
) { return ::sinhf(__x
); }
451 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
)); }
466 { return __builtin_sqrtf(__x
); }
471 sqrt(long double __x
)
472 { return __builtin_sqrtl(__x
); }
474 #if _GLIBCPP_HAVE_TANF
476 tan(float __x
) { return ::tanf(__x
); }
479 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
)); }
492 #if _GLIBCPP_HAVE_TANHF
494 tanh(float __x
) { return ::tanhf(__x
); }
497 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>