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