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