]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/c_std/std_cmath.h
cp-demangle.c (__cxa_demangle): Change resolution of ambiguous arguments.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_std / std_cmath.h
CommitLineData
34ff0b99 1// -*- C++ -*- C forwarding header.
22aef514 2
3a2794ab 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
34ff0b99 4// Free Software Foundation, Inc.
22aef514
BK
5//
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)
10// any later version.
11
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.
16
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,
20// USA.
21
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.
30
31//
32// ISO C++ 14882: 26.5 C library
33//
34
ffe94f83
PE
35/** @file cmath
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.
38 *
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.
42 */
43
1143680e
SE
44#ifndef _GLIBCXX_CMATH
45#define _GLIBCXX_CMATH 1
34ff0b99
BK
46
47#pragma GCC system_header
22aef514 48
98e6e789 49#include <bits/c++config.h>
cdc958d8 50#include <bits/cpp_type_traits.h>
4e588ec9 51
c0dae541 52#include <math.h>
22aef514 53
8089616e
BK
54// Get rid of those macros defined in <math.h> in lieu of real functions.
55#undef abs
56#undef div
57#undef acos
58#undef asin
59#undef atan
60#undef atan2
61#undef ceil
62#undef cos
63#undef cosh
64#undef exp
65#undef fabs
66#undef floor
67#undef fmod
68#undef frexp
69#undef ldexp
70#undef log
71#undef log10
72#undef modf
73#undef pow
74#undef sin
75#undef sinh
4200d6fe 76#undef sqrt
8089616e
BK
77#undef tan
78#undef tanh
79
b39d0359 80
7dd8177f 81namespace std
98e6e789
BK
82{
83 // Forward declaration of a helper function. This really should be
84 // an `exported' forward declaration.
85 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
86
4e588ec9
GDR
87 inline double
88 abs(double __x)
89 { return __builtin_fabs(__x); }
90
d52e4867
RS
91 inline float
92 abs(float __x)
93 { return __builtin_fabsf(__x); }
94
4e588ec9
GDR
95 inline long double
96 abs(long double __x)
97 { return __builtin_fabsl(__x); }
98
de96ac46 99 using ::acos;
c85dfef7
RS
100
101 inline float
102 acos(float __x)
103 { return __builtin_acosf(__x); }
104
105 inline long double
106 acos(long double __x)
107 { return __builtin_acosl(__x); }
4e588ec9 108
cdc958d8 109 template<typename _Tp>
4d73fac9 110 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8
GDR
111 acos(_Tp __x)
112 {
c85dfef7 113 return __builtin_acos(__x);
cdc958d8 114 }
7dd8177f 115
d52e4867
RS
116 using ::asin;
117
7dd8177f 118 inline float
c85dfef7
RS
119 asin(float __x)
120 { return __builtin_asinf(__x); }
22aef514 121
7dd8177f 122 inline long double
c85dfef7
RS
123 asin(long double __x)
124 { return __builtin_asinl(__x); }
4e588ec9 125
cdc958d8 126 template<typename _Tp>
4d73fac9 127 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 128 asin(_Tp __x)
c85dfef7 129 { return __builtin_asin(__x); }
cdc958d8 130
d52e4867
RS
131 using ::atan;
132
7dd8177f 133 inline float
c85dfef7
RS
134 atan(float __x)
135 { return __builtin_atanf(__x); }
22aef514 136
7dd8177f 137 inline long double
c85dfef7
RS
138 atan(long double __x)
139 { return __builtin_atanl(__x); }
4e588ec9 140
cdc958d8 141 template<typename _Tp>
4d73fac9 142 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 143 atan(_Tp __x)
c85dfef7 144 { return __builtin_atan(__x); }
7dd8177f 145
d52e4867
RS
146 using ::atan2;
147
7dd8177f 148 inline float
98e6e789 149 atan2(float __y, float __x)
c85dfef7 150 { return __builtin_atan2f(__y, __x); }
22aef514 151
7dd8177f 152 inline long double
c85dfef7
RS
153 atan2(long double __y, long double __x)
154 { return __builtin_atan2l(__y, __x); }
4e588ec9 155
cdc958d8 156 template<typename _Tp, typename _Up>
4d73fac9
PC
157 inline typename __enable_if<double, __is_integer<_Tp>::__value
158 && __is_integer<_Up>::__value>::__type
c85dfef7
RS
159 atan2(_Tp __y, _Up __x)
160 { return __builtin_atan2(__y, __x); }
cdc958d8 161
d52e4867
RS
162 using ::ceil;
163
7dd8177f 164 inline float
c85dfef7
RS
165 ceil(float __x)
166 { return __builtin_ceilf(__x); }
22aef514 167
7dd8177f 168 inline long double
c85dfef7
RS
169 ceil(long double __x)
170 { return __builtin_ceill(__x); }
22aef514 171
cdc958d8 172 template<typename _Tp>
4d73fac9 173 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 174 ceil(_Tp __x)
c85dfef7 175 { return __builtin_ceil(__x); }
7dd8177f 176
d52e4867
RS
177 using ::cos;
178
4e588ec9
GDR
179 inline float
180 cos(float __x)
181 { return __builtin_cosf(__x); }
182
4e588ec9
GDR
183 inline long double
184 cos(long double __x)
185 { return __builtin_cosl(__x); }
186
cdc958d8 187 template<typename _Tp>
4d73fac9 188 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8
GDR
189 cos(_Tp __x)
190 { return __builtin_cos(__x); }
191
d52e4867
RS
192 using ::cosh;
193
7dd8177f 194 inline float
c85dfef7
RS
195 cosh(float __x)
196 { return __builtin_coshf(__x); }
22aef514 197
7dd8177f 198 inline long double
c85dfef7
RS
199 cosh(long double __x)
200 { return __builtin_coshl(__x); }
4e588ec9 201
cdc958d8 202 template<typename _Tp>
4d73fac9 203 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 204 cosh(_Tp __x)
c85dfef7 205 { return __builtin_cosh(__x); }
cdc958d8 206
d52e4867
RS
207 using ::exp;
208
7dd8177f 209 inline float
c85dfef7
RS
210 exp(float __x)
211 { return __builtin_expf(__x); }
22aef514 212
7dd8177f 213 inline long double
c85dfef7
RS
214 exp(long double __x)
215 { return __builtin_expl(__x); }
22aef514 216
cdc958d8 217 template<typename _Tp>
4d73fac9 218 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 219 exp(_Tp __x)
c85dfef7 220 { return __builtin_exp(__x); }
7dd8177f 221
d52e4867
RS
222 using ::fabs;
223
4e588ec9
GDR
224 inline float
225 fabs(float __x)
226 { return __builtin_fabsf(__x); }
227
4e588ec9
GDR
228 inline long double
229 fabs(long double __x)
230 { return __builtin_fabsl(__x); }
231
cdc958d8 232 template<typename _Tp>
4d73fac9 233 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8
GDR
234 fabs(_Tp __x)
235 { return __builtin_fabs(__x); }
236
d52e4867
RS
237 using ::floor;
238
7dd8177f 239 inline float
c85dfef7
RS
240 floor(float __x)
241 { return __builtin_floorf(__x); }
22aef514 242
7dd8177f 243 inline long double
c85dfef7
RS
244 floor(long double __x)
245 { return __builtin_floorl(__x); }
4e588ec9 246
cdc958d8 247 template<typename _Tp>
4d73fac9 248 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 249 floor(_Tp __x)
c85dfef7 250 { return __builtin_floor(__x); }
7dd8177f 251
d52e4867
RS
252 using ::fmod;
253
7dd8177f 254 inline float
98e6e789 255 fmod(float __x, float __y)
c85dfef7 256 { return __builtin_fmodf(__x, __y); }
22aef514 257
7dd8177f 258 inline long double
c85dfef7
RS
259 fmod(long double __x, long double __y)
260 { return __builtin_fmodl(__x, __y); }
4e588ec9 261
d52e4867
RS
262 using ::frexp;
263
7dd8177f 264 inline float
c85dfef7
RS
265 frexp(float __x, int* __exp)
266 { return __builtin_frexpf(__x, __exp); }
22aef514 267
7dd8177f 268 inline long double
c85dfef7
RS
269 frexp(long double __x, int* __exp)
270 { return __builtin_frexpl(__x, __exp); }
4e588ec9 271
cdc958d8 272 template<typename _Tp>
4d73fac9 273 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 274 frexp(_Tp __x, int* __exp)
c85dfef7 275 { return __builtin_frexp(__x, __exp); }
7dd8177f 276
d52e4867
RS
277 using ::ldexp;
278
7dd8177f 279 inline float
98e6e789 280 ldexp(float __x, int __exp)
c85dfef7 281 { return __builtin_ldexpf(__x, __exp); }
22aef514 282
7dd8177f 283 inline long double
c85dfef7
RS
284 ldexp(long double __x, int __exp)
285 { return __builtin_ldexpl(__x, __exp); }
4e588ec9 286
cdc958d8 287 template<typename _Tp>
4d73fac9 288 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 289 ldexp(_Tp __x, int __exp)
c85dfef7 290 { return __builtin_ldexp(__x, __exp); }
cdc958d8 291
d52e4867
RS
292 using ::log;
293
7dd8177f 294 inline float
c85dfef7
RS
295 log(float __x)
296 { return __builtin_logf(__x); }
22aef514 297
7dd8177f 298 inline long double
c85dfef7
RS
299 log(long double __x)
300 { return __builtin_logl(__x); }
4e588ec9 301
cdc958d8 302 template<typename _Tp>
4d73fac9 303 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 304 log(_Tp __x)
c85dfef7 305 { return __builtin_log(__x); }
7dd8177f 306
d52e4867
RS
307 using ::log10;
308
7dd8177f 309 inline float
c85dfef7
RS
310 log10(float __x)
311 { return __builtin_log10f(__x); }
22aef514 312
7dd8177f 313 inline long double
c85dfef7
RS
314 log10(long double __x)
315 { return __builtin_log10l(__x); }
4e588ec9 316
cdc958d8 317 template<typename _Tp>
4d73fac9 318 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 319 log10(_Tp __x)
c85dfef7 320 { return __builtin_log10(__x); }
7dd8177f 321
d52e4867
RS
322 using ::modf;
323
7dd8177f 324 inline float
98e6e789 325 modf(float __x, float* __iptr)
c85dfef7
RS
326 { return __builtin_modff(__x, __iptr); }
327
7dd8177f 328 inline long double
c85dfef7
RS
329 modf(long double __x, long double* __iptr)
330 { return __builtin_modfl(__x, __iptr); }
4e588ec9 331
98e6e789
BK
332 template<typename _Tp>
333 inline _Tp
334 __pow_helper(_Tp __x, int __n)
335 {
336 return __n < 0
337 ? _Tp(1)/__cmath_power(__x, -__n)
338 : __cmath_power(__x, __n);
339 }
d52e4867
RS
340
341 using ::pow;
342
7dd8177f 343 inline float
98e6e789 344 pow(float __x, float __y)
c85dfef7 345 { return __builtin_powf(__x, __y); }
22aef514 346
7dd8177f 347 inline long double
c85dfef7
RS
348 pow(long double __x, long double __y)
349 { return __builtin_powl(__x, __y); }
22aef514 350
7dd8177f 351 inline double
98e6e789 352 pow(double __x, int __i)
de96ac46 353 { return __pow_helper(__x, __i); }
22aef514 354
7dd8177f 355 inline float
d52e4867
RS
356 pow(float __x, int __n)
357 { return __pow_helper(__x, __n); }
358
7dd8177f 359 inline long double
4e588ec9 360 pow(long double __x, int __n)
de96ac46 361 { return __pow_helper(__x, __n); }
22aef514 362
d52e4867
RS
363 using ::sin;
364
4e588ec9
GDR
365 inline float
366 sin(float __x)
367 { return __builtin_sinf(__x); }
22aef514 368
4e588ec9
GDR
369 inline long double
370 sin(long double __x)
371 { return __builtin_sinl(__x); }
22aef514 372
cdc958d8 373 template<typename _Tp>
4d73fac9 374 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8
GDR
375 sin(_Tp __x)
376 { return __builtin_sin(__x); }
377
d52e4867
RS
378 using ::sinh;
379
7dd8177f 380 inline float
c85dfef7
RS
381 sinh(float __x)
382 { return __builtin_sinhf(__x); }
22aef514 383
7dd8177f 384 inline long double
c85dfef7
RS
385 sinh(long double __x)
386 { return __builtin_sinhl(__x); }
22aef514 387
cdc958d8 388 template<typename _Tp>
4d73fac9 389 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 390 sinh(_Tp __x)
c85dfef7 391 { return __builtin_sinh(__x); }
7dd8177f 392
d52e4867
RS
393 using ::sqrt;
394
4e588ec9
GDR
395 inline float
396 sqrt(float __x)
397 { return __builtin_sqrtf(__x); }
22aef514 398
4e588ec9
GDR
399 inline long double
400 sqrt(long double __x)
401 { return __builtin_sqrtl(__x); }
22aef514 402
cdc958d8 403 template<typename _Tp>
4d73fac9 404 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8
GDR
405 sqrt(_Tp __x)
406 { return __builtin_sqrt(__x); }
7dd8177f 407
d52e4867
RS
408 using ::tan;
409
7dd8177f 410 inline float
c85dfef7
RS
411 tan(float __x)
412 { return __builtin_tanf(__x); }
22aef514 413
7dd8177f 414 inline long double
c85dfef7
RS
415 tan(long double __x)
416 { return __builtin_tanl(__x); }
22aef514 417
cdc958d8 418 template<typename _Tp>
4d73fac9 419 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 420 tan(_Tp __x)
c85dfef7 421 { return __builtin_tan(__x); }
7dd8177f 422
d52e4867
RS
423 using ::tanh;
424
7dd8177f 425 inline float
c85dfef7
RS
426 tanh(float __x)
427 { return __builtin_tanhf(__x); }
22aef514 428
7dd8177f 429 inline long double
c85dfef7
RS
430 tanh(long double __x)
431 { return __builtin_tanhl(__x); }
cdc958d8
GDR
432
433 template<typename _Tp>
4d73fac9 434 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
cdc958d8 435 tanh(_Tp __x)
c85dfef7 436 { return __builtin_tanh(__x); }
7dd8177f 437}
22aef514 438
517da0ce 439#if _GLIBCXX_USE_C99_MATH
3d7c150e 440#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
7cda84dc 441// These are possible macros imported from C99-land. For strict
3702c634 442// conformance, remove possible C99-injected names from the global
7dd8177f 443// namespace, and sequester them in the __gnu_cxx extension namespace.
3702c634 444namespace __gnu_cxx
7cda84dc
BK
445{
446 template<typename _Tp>
7dd8177f 447 int
7cda84dc
BK
448 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
449
450 template<typename _Tp>
7dd8177f 451 int
7cda84dc
BK
452 __capture_isfinite(_Tp __f) { return isfinite(__f); }
453
454 template<typename _Tp>
7dd8177f 455 int
7cda84dc
BK
456 __capture_isinf(_Tp __f) { return isinf(__f); }
457
458 template<typename _Tp>
7dd8177f 459 int
7cda84dc
BK
460 __capture_isnan(_Tp __f) { return isnan(__f); }
461
462 template<typename _Tp>
7dd8177f 463 int
7cda84dc
BK
464 __capture_isnormal(_Tp __f) { return isnormal(__f); }
465
466 template<typename _Tp>
7dd8177f 467 int
7cda84dc
BK
468 __capture_signbit(_Tp __f) { return signbit(__f); }
469
470 template<typename _Tp>
7dd8177f 471 int
3702c634
GDR
472 __capture_isgreater(_Tp __f1, _Tp __f2)
473 { return isgreater(__f1, __f2); }
7cda84dc 474
3702c634 475 template<typename _Tp>
7dd8177f
BI
476 int
477 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
3702c634 478 { return isgreaterequal(__f1, __f2); }
7cda84dc 479
3702c634 480 template<typename _Tp>
7dd8177f 481 int
3702c634 482 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
7cda84dc 483
3702c634 484 template<typename _Tp>
7dd8177f
BI
485 int
486 __capture_islessequal(_Tp __f1, _Tp __f2)
3702c634 487 { return islessequal(__f1, __f2); }
7cda84dc 488
3702c634 489 template<typename _Tp>
7dd8177f
BI
490 int
491 __capture_islessgreater(_Tp __f1, _Tp __f2)
3702c634 492 { return islessgreater(__f1, __f2); }
7cda84dc 493
3702c634 494 template<typename _Tp>
7dd8177f
BI
495 int
496 __capture_isunordered(_Tp __f1, _Tp __f2)
3702c634 497 { return isunordered(__f1, __f2); }
c04ec67e 498}
7cda84dc 499
c04ec67e 500// Only undefine the C99 FP macros, if actually captured for namespace movement
7cda84dc
BK
501#undef fpclassify
502#undef isfinite
503#undef isinf
504#undef isnan
505#undef isnormal
506#undef signbit
507#undef isgreater
508#undef isgreaterequal
509#undef isless
510#undef islessequal
511#undef islessgreater
512#undef isunordered
513
3a2794ab 514namespace std
7cda84dc
BK
515{
516 template<typename _Tp>
517 int
3a2794ab 518 fpclassify(_Tp __f) { return __gnu_cxx::__capture_fpclassify(__f); }
7cda84dc
BK
519
520 template<typename _Tp>
521 int
3a2794ab 522 isfinite(_Tp __f) { return __gnu_cxx::__capture_isfinite(__f); }
7cda84dc
BK
523
524 template<typename _Tp>
7dd8177f 525 int
3a2794ab 526 isinf(_Tp __f) { return __gnu_cxx::__capture_isinf(__f); }
7cda84dc
BK
527
528 template<typename _Tp>
7dd8177f 529 int
3a2794ab 530 isnan(_Tp __f) { return __gnu_cxx::__capture_isnan(__f); }
7cda84dc
BK
531
532 template<typename _Tp>
7dd8177f 533 int
3a2794ab 534 isnormal(_Tp __f) { return __gnu_cxx::__capture_isnormal(__f); }
7cda84dc
BK
535
536 template<typename _Tp>
7dd8177f 537 int
3a2794ab 538 signbit(_Tp __f) { return __gnu_cxx::__capture_signbit(__f); }
7cda84dc
BK
539
540 template<typename _Tp>
7dd8177f 541 int
3a2794ab
LM
542 isgreater(_Tp __f1, _Tp __f2)
543 { return __gnu_cxx::__capture_isgreater(__f1, __f2); }
7cda84dc
BK
544
545 template<typename _Tp>
7dd8177f
BI
546 int
547 isgreaterequal(_Tp __f1, _Tp __f2)
3a2794ab 548 { return __gnu_cxx::__capture_isgreaterequal(__f1, __f2); }
7cda84dc
BK
549
550 template<typename _Tp>
7dd8177f 551 int
3a2794ab
LM
552 isless(_Tp __f1, _Tp __f2)
553 { return __gnu_cxx::__capture_isless(__f1, __f2); }
7cda84dc
BK
554
555 template<typename _Tp>
7dd8177f
BI
556 int
557 islessequal(_Tp __f1, _Tp __f2)
3a2794ab 558 { return __gnu_cxx::__capture_islessequal(__f1, __f2); }
7cda84dc
BK
559
560 template<typename _Tp>
7dd8177f
BI
561 int
562 islessgreater(_Tp __f1, _Tp __f2)
3a2794ab 563 { return __gnu_cxx::__capture_islessgreater(__f1, __f2); }
7cda84dc
BK
564
565 template<typename _Tp>
7dd8177f
BI
566 int
567 isunordered(_Tp __f1, _Tp __f2)
3a2794ab 568 { return __gnu_cxx::__capture_isunordered(__f1, __f2); }
5db6f3de 569}
3d7c150e 570#endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
7cda84dc 571#endif
7dd8177f 572
5f697f7a
BK
573#ifndef _GLIBCXX_EXPORT_TEMPLATE
574# include <bits/cmath.tcc>
607642b6 575#endif
22aef514 576
98e6e789 577#endif