]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/c_std/std_cmath.h
c/: Guard with _CPP_.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_std / std_cmath.h
CommitLineData
34ff0b99 1// -*- C++ -*- C forwarding header.
22aef514 2
34ff0b99
BK
3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
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
3eb35fcf
BK
44#ifndef _CPP_CMATH
45#define _CPP_CMATH 1
34ff0b99
BK
46
47#pragma GCC system_header
22aef514 48
98e6e789 49#include <bits/c++config.h>
4e588ec9 50
c0dae541 51#include <math.h>
22aef514 52
8089616e
BK
53// Get rid of those macros defined in <math.h> in lieu of real functions.
54#undef abs
55#undef div
56#undef acos
57#undef asin
58#undef atan
59#undef atan2
60#undef ceil
61#undef cos
62#undef cosh
63#undef exp
64#undef fabs
65#undef floor
66#undef fmod
67#undef frexp
68#undef ldexp
69#undef log
70#undef log10
71#undef modf
72#undef pow
73#undef sin
74#undef sinh
4200d6fe 75#undef sqrt
8089616e
BK
76#undef tan
77#undef tanh
78
98e6e789
BK
79namespace std
80{
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);
84
85 template<typename _Tp>
86 inline _Tp
87 __cmath_abs(_Tp __x)
88 {
89 return __x < _Tp() ? -__x : __x;
90 }
91
4e588ec9
GDR
92 inline float
93 abs(float __x)
94 { return __builtin_fabsf(__x); }
22aef514 95
4e588ec9
GDR
96 inline double
97 abs(double __x)
98 { return __builtin_fabs(__x); }
99
100 inline long double
101 abs(long double __x)
102 { return __builtin_fabsl(__x); }
103
22aef514
BK
104#if _GLIBCPP_HAVE_ACOSF
105 inline float
98e6e789 106 acos(float __x) { return ::acosf(__x); }
22aef514
BK
107#else
108 inline float
98e6e789 109 acos(float __x) { return ::acos(static_cast<double>(__x)); }
22aef514
BK
110#endif
111
de96ac46 112 using ::acos;
4e588ec9
GDR
113
114#if _GLIBCPP_HAVE_ACOSL
115 inline long double
116 acos(long double __x) { return ::acosl(__x); }
117#else
118 inline long double
119 acos(long double __x) { return ::acos(static_cast<double>(__x)); }
120#endif
121
22aef514
BK
122#if _GLIBCPP_HAVE_ASINF
123 inline float
98e6e789 124 asin(float __x) { return ::asinf(__x); }
22aef514
BK
125#else
126 inline float
98e6e789 127 asin(float __x) { return ::asin(static_cast<double>(__x)); }
22aef514
BK
128#endif
129
de96ac46 130 using ::asin;
4e588ec9
GDR
131
132#if _GLIBCPP_HAVE_ASINL
133 inline long double
134 asin(long double __x) { return ::asinl(__x); }
135#else
136 inline long double
137 asin(long double __x) { return ::asin(static_cast<double>(__x)); }
138#endif
139
22aef514
BK
140#if _GLIBCPP_HAVE_ATANF
141 inline float
98e6e789 142 atan(float __x) { return ::atanf(__x); }
22aef514
BK
143#else
144 inline float
98e6e789 145 atan(float __x) { return ::atan(static_cast<double>(__x)); }
22aef514
BK
146#endif
147
de96ac46 148 using ::atan;
4e588ec9
GDR
149
150#if _GLIBCPP_HAVE_ATANL
151 inline long double
152 atan(long double __x) { return ::atanl(__x); }
153#else
154 inline long double
155 atan(long double __x) { return ::atan(static_cast<double>(__x)); }
156#endif
157
22aef514
BK
158#if _GLIBCPP_HAVE_ATAN2F
159 inline float
98e6e789 160 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
22aef514
BK
161#else
162 inline float
98e6e789
BK
163 atan2(float __y, float __x)
164 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
22aef514
BK
165#endif
166
de96ac46 167 using ::atan2;
4e588ec9
GDR
168
169#if _GLIBCPP_HAVE_ATAN2L
170 inline long double
171 atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
172#else
173 inline long double
174 atan2(long double __y, long double __x)
175 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
176#endif
177
22aef514
BK
178#if _GLIBCPP_HAVE_CEILF
179 inline float
98e6e789 180 ceil(float __x) { return ::ceilf(__x); }
22aef514
BK
181#else
182 inline float
98e6e789 183 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
22aef514
BK
184#endif
185
de96ac46 186 using ::ceil;
4e588ec9
GDR
187
188#if _GLIBCPP_HAVE_CEILL
189 inline long double
190 ceil(long double __x) { return ::ceill(__x); }
22aef514 191#else
4e588ec9
GDR
192 inline long double
193 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
22aef514
BK
194#endif
195
4e588ec9
GDR
196 inline float
197 cos(float __x)
198 { return __builtin_cosf(__x); }
199
de96ac46 200 using ::cos;
4e588ec9
GDR
201
202 inline long double
203 cos(long double __x)
204 { return __builtin_cosl(__x); }
205
22aef514
BK
206#if _GLIBCPP_HAVE_COSHF
207 inline float
98e6e789 208 cosh(float __x) { return ::coshf(__x); }
22aef514
BK
209#else
210 inline float
98e6e789 211 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
22aef514
BK
212#endif
213
de96ac46 214 using ::cosh;
4e588ec9
GDR
215
216#if _GLIBCPP_HAVE_COSHL
217 inline long double
218 cosh(long double __x) { return ::coshl(__x); }
219#else
220 inline long double
221 cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
222#endif
223
22aef514
BK
224#if _GLIBCPP_HAVE_EXPF
225 inline float
98e6e789 226 exp(float __x) { return ::expf(__x); }
22aef514
BK
227#else
228 inline float
98e6e789 229 exp(float __x) { return ::exp(static_cast<double>(__x)); }
22aef514
BK
230#endif
231
de96ac46 232 using ::exp;
4e588ec9
GDR
233
234#if _GLIBCPP_HAVE_EXPL
235 inline long double
236 exp(long double __x) { return ::expl(__x); }
22aef514 237#else
4e588ec9
GDR
238 inline long double
239 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
22aef514
BK
240#endif
241
4e588ec9
GDR
242 inline float
243 fabs(float __x)
244 { return __builtin_fabsf(__x); }
245
de96ac46 246 using ::fabs;
4e588ec9
GDR
247
248 inline long double
249 fabs(long double __x)
250 { return __builtin_fabsl(__x); }
251
22aef514
BK
252#if _GLIBCPP_HAVE_FLOORF
253 inline float
98e6e789 254 floor(float __x) { return ::floorf(__x); }
22aef514
BK
255#else
256 inline float
98e6e789 257 floor(float __x) { return ::floor(static_cast<double>(__x)); }
22aef514
BK
258#endif
259
de96ac46 260 using ::floor;
4e588ec9
GDR
261
262#if _GLIBCPP_HAVE_FLOORL
263 inline long double
264 floor(long double __x) { return ::floorl(__x); }
265#else
266 inline long double
267 floor(long double __x) { return ::floor(static_cast<double>(__x)); }
268#endif
269
98e6e789 270#if _GLIBCPP_HAVE_FMODF
22aef514 271 inline float
98e6e789 272 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
22aef514
BK
273#else
274 inline float
98e6e789
BK
275 fmod(float __x, float __y)
276 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
22aef514
BK
277#endif
278
de96ac46 279 using ::fmod;
4e588ec9
GDR
280
281#if _GLIBCPP_HAVE_FMODL
282 inline long double
283 fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
284#else
285 inline long double
286 fmod(long double __x, long double __y)
287 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
288#endif
289
22aef514
BK
290#if _GLIBCPP_HAVE_FREXPF
291 inline float
98e6e789 292 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
22aef514
BK
293#else
294 inline float
98e6e789 295 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
22aef514
BK
296#endif
297
de96ac46 298 using ::frexp;
4e588ec9
GDR
299
300#if _GLIBCPP_HAVE_FREXPL
301 inline long double
302 frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
303#else
304 inline long double
305 frexp(long double __x, int* __exp)
306 { return ::frexp(static_cast<double>(__x), __exp); }
307#endif
308
22aef514
BK
309#if _GLIBCPP_HAVE_LDEXPF
310 inline float
98e6e789 311 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
22aef514
BK
312#else
313 inline float
98e6e789
BK
314 ldexp(float __x, int __exp)
315 { return ::ldexp(static_cast<double>(__x), __exp); }
22aef514
BK
316#endif
317
de96ac46 318 using ::ldexp;
4e588ec9
GDR
319
320#if _GLIBCPP_HAVE_LDEXPL
321 inline long double
322 ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
323#else
324 inline long double
325 ldexp(long double __x, int __exp)
326 { return ::ldexp(static_cast<double>(__x), __exp); }
327#endif
328
22aef514
BK
329#if _GLIBCPP_HAVE_LOGF
330 inline float
98e6e789 331 log(float __x) { return ::logf(__x); }
22aef514 332#else
98e6e789
BK
333 inline float log(float __x)
334 { return ::log(static_cast<double>(__x)); }
22aef514
BK
335#endif
336
de96ac46 337 using ::log;
4e588ec9
GDR
338
339#if _GLIBCPP_HAVE_LOGL
340 inline long double
341 log(long double __x) { return ::logl(__x); }
342#else
343 inline long double
344 log(long double __x) { return ::log(static_cast<double>(__x)); }
345#endif
346
22aef514
BK
347#if _GLIBCPP_HAVE_LOG10F
348 inline float
98e6e789 349 log10(float __x) { return ::log10f(__x); }
22aef514
BK
350#else
351 inline float
98e6e789 352 log10(float __x) { return ::log10(static_cast<double>(__x)); }
22aef514
BK
353#endif
354
de96ac46 355 using ::log10;
4e588ec9
GDR
356
357#if _GLIBCPP_HAVE_LOG10L
358 inline long double
359 log10(long double __x) { return ::log10l(__x); }
360#else
361 inline long double
362 log10(long double __x) { return ::log10(static_cast<double>(__x)); }
363#endif
364
22aef514
BK
365#if _GLIBCPP_HAVE_MODFF
366 inline float
98e6e789 367 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
22aef514
BK
368#else
369 inline float
98e6e789 370 modf(float __x, float* __iptr)
22aef514
BK
371 {
372 double __tmp;
98e6e789
BK
373 double __res = ::modf(static_cast<double>(__x), &__tmp);
374 *__iptr = static_cast<float>(__tmp);
22aef514
BK
375 return __res;
376 }
377#endif
98e6e789 378
de96ac46 379 using ::modf;
4e588ec9
GDR
380
381#if _GLIBCPP_HAVE_MODFL
382 inline long double
383 modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
384#else
385 inline long double
386 modf(long double __x, long double* __iptr)
387 {
388 double __tmp;
389 double __res = ::modf(static_cast<double>(__x), &__tmp);
390 * __iptr = static_cast<long double>(__tmp);
391 return __res;
392 }
393#endif
394
98e6e789
BK
395 template<typename _Tp>
396 inline _Tp
397 __pow_helper(_Tp __x, int __n)
398 {
399 return __n < 0
400 ? _Tp(1)/__cmath_power(__x, -__n)
401 : __cmath_power(__x, __n);
402 }
22aef514
BK
403
404#if _GLIBCPP_HAVE_POWF
405 inline float
98e6e789 406 pow(float __x, float __y) { return ::powf(__x, __y); }
22aef514
BK
407#else
408 inline float
98e6e789
BK
409 pow(float __x, float __y)
410 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
22aef514
BK
411#endif
412
de96ac46 413 using ::pow;
22aef514 414
4e588ec9
GDR
415#if _GLIBCPP_HAVE_POWL
416 inline long double
417 pow(long double __x, long double __y) { return ::powl(__x, __y); }
22aef514 418#else
4e588ec9
GDR
419 inline long double
420 pow(long double __x, long double __y)
421 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
22aef514
BK
422#endif
423
22aef514 424 inline float
4e588ec9 425 pow(float __x, int __n)
de96ac46 426 { return __pow_helper(__x, __n); }
22aef514
BK
427
428 inline double
98e6e789 429 pow(double __x, int __i)
de96ac46 430 { return __pow_helper(__x, __i); }
22aef514 431
22aef514 432 inline long double
4e588ec9 433 pow(long double __x, int __n)
de96ac46 434 { return __pow_helper(__x, __n); }
22aef514 435
4e588ec9
GDR
436 inline float
437 sin(float __x)
438 { return __builtin_sinf(__x); }
22aef514 439
de96ac46 440 using ::sin;
22aef514 441
4e588ec9
GDR
442 inline long double
443 sin(long double __x)
444 { return __builtin_sinl(__x); }
22aef514 445
4e588ec9
GDR
446#if _GLIBCPP_HAVE_SINHF
447 inline float
448 sinh(float __x) { return ::sinhf(__x); }
22aef514 449#else
4e588ec9
GDR
450 inline float
451 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
22aef514
BK
452#endif
453
de96ac46 454 using ::sinh;
22aef514 455
4e588ec9 456#if _GLIBCPP_HAVE_SINHL
22aef514 457 inline long double
4e588ec9 458 sinh(long double __x) { return ::sinhl(__x); }
22aef514
BK
459#else
460 inline long double
4e588ec9 461 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
22aef514
BK
462#endif
463
4e588ec9
GDR
464 inline float
465 sqrt(float __x)
466 { return __builtin_sqrtf(__x); }
22aef514 467
de96ac46 468 using ::sqrt;
22aef514 469
4e588ec9
GDR
470 inline long double
471 sqrt(long double __x)
472 { return __builtin_sqrtl(__x); }
22aef514 473
4e588ec9
GDR
474#if _GLIBCPP_HAVE_TANF
475 inline float
476 tan(float __x) { return ::tanf(__x); }
22aef514 477#else
4e588ec9
GDR
478 inline float
479 tan(float __x) { return ::tan(static_cast<double>(__x)); }
22aef514
BK
480#endif
481
de96ac46 482 using ::tan;
98e6e789 483
4e588ec9 484#if _GLIBCPP_HAVE_TANL
22aef514 485 inline long double
4e588ec9 486 tan(long double __x) { return ::tanl(__x); }
22aef514
BK
487#else
488 inline long double
4e588ec9 489 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
22aef514
BK
490#endif
491
4e588ec9
GDR
492#if _GLIBCPP_HAVE_TANHF
493 inline float
494 tanh(float __x) { return ::tanhf(__x); }
22aef514 495#else
4e588ec9
GDR
496 inline float
497 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
22aef514
BK
498#endif
499
de96ac46 500 using ::tanh;
22aef514
BK
501
502#if _GLIBCPP_HAVE_TANHL
503 inline long double
98e6e789 504 tanh(long double __x) { return ::tanhl(__x); }
22aef514
BK
505#else
506 inline long double
98e6e789 507 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
22aef514 508#endif
61c71946 509}
22aef514 510
7cda84dc
BK
511
512#if _GLIBCPP_USE_C99
513// These are possible macros imported from C99-land. For strict
3702c634
GDR
514// conformance, remove possible C99-injected names from the global
515// namespace, and sequester them in the __gnu_cxx extension namespace.
516namespace __gnu_cxx
7cda84dc
BK
517{
518 template<typename _Tp>
519 int
520 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
521
522 template<typename _Tp>
523 int
524 __capture_isfinite(_Tp __f) { return isfinite(__f); }
525
526 template<typename _Tp>
527 int
528 __capture_isinf(_Tp __f) { return isinf(__f); }
529
530 template<typename _Tp>
531 int
532 __capture_isnan(_Tp __f) { return isnan(__f); }
533
534 template<typename _Tp>
535 int
536 __capture_isnormal(_Tp __f) { return isnormal(__f); }
537
538 template<typename _Tp>
539 int
540 __capture_signbit(_Tp __f) { return signbit(__f); }
541
542 template<typename _Tp>
543 int
3702c634
GDR
544 __capture_isgreater(_Tp __f1, _Tp __f2)
545 { return isgreater(__f1, __f2); }
7cda84dc 546
3702c634
GDR
547 template<typename _Tp>
548 int
549 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
550 { return isgreaterequal(__f1, __f2); }
7cda84dc 551
3702c634
GDR
552 template<typename _Tp>
553 int
554 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
7cda84dc 555
3702c634
GDR
556 template<typename _Tp>
557 int
558 __capture_islessequal(_Tp __f1, _Tp __f2)
559 { return islessequal(__f1, __f2); }
7cda84dc 560
3702c634
GDR
561 template<typename _Tp>
562 int
563 __capture_islessgreater(_Tp __f1, _Tp __f2)
564 { return islessgreater(__f1, __f2); }
7cda84dc 565
3702c634
GDR
566 template<typename _Tp>
567 int
568 __capture_isunordered(_Tp __f1, _Tp __f2)
569 { return isunordered(__f1, __f2); }
61c71946 570}
7cda84dc
BK
571#endif
572
573#undef fpclassify
574#undef isfinite
575#undef isinf
576#undef isnan
577#undef isnormal
578#undef signbit
579#undef isgreater
580#undef isgreaterequal
581#undef isless
582#undef islessequal
583#undef islessgreater
584#undef isunordered
585
586#if _GLIBCPP_USE_C99
3702c634 587namespace __gnu_cxx
7cda84dc
BK
588{
589 template<typename _Tp>
590 int
591 fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
592
593 template<typename _Tp>
594 int
595 isfinite(_Tp __f) { return __capture_isfinite(__f); }
596
597 template<typename _Tp>
598 int
599 isinf(_Tp __f) { return __capture_isinf(__f); }
600
601 template<typename _Tp>
602 int
603 isnan(_Tp __f) { return __capture_isnan(__f); }
604
605 template<typename _Tp>
606 int
607 isnormal(_Tp __f) { return __capture_isnormal(__f); }
608
609 template<typename _Tp>
610 int
611 signbit(_Tp __f) { return __capture_signbit(__f); }
612
613 template<typename _Tp>
614 int
615 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
616
617 template<typename _Tp>
618 int
619 isgreaterequal(_Tp __f1, _Tp __f2)
620 { return __capture_isgreaterequal(__f1, __f2); }
621
622 template<typename _Tp>
623 int
624 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
625
626 template<typename _Tp>
627 int
628 islessequal(_Tp __f1, _Tp __f2)
629 { return __capture_islessequal(__f1, __f2); }
630
631 template<typename _Tp>
632 int
5db6f3de
BK
633 islessgreater(_Tp __f1, _Tp __f2)
634 { return __capture_islessgreater(__f1, __f2); }
7cda84dc
BK
635
636 template<typename _Tp>
637 int
638 isunordered(_Tp __f1, _Tp __f2)
639 { return __capture_isunordered(__f1, __f2); }
640}
5db6f3de
BK
641
642namespace std
643{
3702c634
GDR
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;
5db6f3de 656}
7cda84dc
BK
657#endif
658
98e6e789
BK
659#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
660# define export
34ff0b99 661# include <bits/cmath.tcc>
607642b6 662#endif
22aef514 663
98e6e789 664#endif