]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/c_std/std_cmath.h
c/: Guard with _CPP_.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_std / std_cmath.h
1 // -*- C++ -*- C forwarding header.
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
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
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
44 #ifndef _CPP_CMATH
45 #define _CPP_CMATH 1
46
47 #pragma GCC system_header
48
49 #include <bits/c++config.h>
50
51 #include <math.h>
52
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
75 #undef sqrt
76 #undef tan
77 #undef tanh
78
79 namespace 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
92 inline float
93 abs(float __x)
94 { return __builtin_fabsf(__x); }
95
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
104 #if _GLIBCPP_HAVE_ACOSF
105 inline float
106 acos(float __x) { return ::acosf(__x); }
107 #else
108 inline float
109 acos(float __x) { return ::acos(static_cast<double>(__x)); }
110 #endif
111
112 using ::acos;
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
122 #if _GLIBCPP_HAVE_ASINF
123 inline float
124 asin(float __x) { return ::asinf(__x); }
125 #else
126 inline float
127 asin(float __x) { return ::asin(static_cast<double>(__x)); }
128 #endif
129
130 using ::asin;
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
140 #if _GLIBCPP_HAVE_ATANF
141 inline float
142 atan(float __x) { return ::atanf(__x); }
143 #else
144 inline float
145 atan(float __x) { return ::atan(static_cast<double>(__x)); }
146 #endif
147
148 using ::atan;
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
158 #if _GLIBCPP_HAVE_ATAN2F
159 inline float
160 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
161 #else
162 inline float
163 atan2(float __y, float __x)
164 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
165 #endif
166
167 using ::atan2;
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
178 #if _GLIBCPP_HAVE_CEILF
179 inline float
180 ceil(float __x) { return ::ceilf(__x); }
181 #else
182 inline float
183 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
184 #endif
185
186 using ::ceil;
187
188 #if _GLIBCPP_HAVE_CEILL
189 inline long double
190 ceil(long double __x) { return ::ceill(__x); }
191 #else
192 inline long double
193 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
194 #endif
195
196 inline float
197 cos(float __x)
198 { return __builtin_cosf(__x); }
199
200 using ::cos;
201
202 inline long double
203 cos(long double __x)
204 { return __builtin_cosl(__x); }
205
206 #if _GLIBCPP_HAVE_COSHF
207 inline float
208 cosh(float __x) { return ::coshf(__x); }
209 #else
210 inline float
211 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
212 #endif
213
214 using ::cosh;
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
224 #if _GLIBCPP_HAVE_EXPF
225 inline float
226 exp(float __x) { return ::expf(__x); }
227 #else
228 inline float
229 exp(float __x) { return ::exp(static_cast<double>(__x)); }
230 #endif
231
232 using ::exp;
233
234 #if _GLIBCPP_HAVE_EXPL
235 inline long double
236 exp(long double __x) { return ::expl(__x); }
237 #else
238 inline long double
239 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
240 #endif
241
242 inline float
243 fabs(float __x)
244 { return __builtin_fabsf(__x); }
245
246 using ::fabs;
247
248 inline long double
249 fabs(long double __x)
250 { return __builtin_fabsl(__x); }
251
252 #if _GLIBCPP_HAVE_FLOORF
253 inline float
254 floor(float __x) { return ::floorf(__x); }
255 #else
256 inline float
257 floor(float __x) { return ::floor(static_cast<double>(__x)); }
258 #endif
259
260 using ::floor;
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
270 #if _GLIBCPP_HAVE_FMODF
271 inline float
272 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
273 #else
274 inline float
275 fmod(float __x, float __y)
276 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
277 #endif
278
279 using ::fmod;
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
290 #if _GLIBCPP_HAVE_FREXPF
291 inline float
292 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
293 #else
294 inline float
295 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
296 #endif
297
298 using ::frexp;
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
309 #if _GLIBCPP_HAVE_LDEXPF
310 inline float
311 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
312 #else
313 inline float
314 ldexp(float __x, int __exp)
315 { return ::ldexp(static_cast<double>(__x), __exp); }
316 #endif
317
318 using ::ldexp;
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
329 #if _GLIBCPP_HAVE_LOGF
330 inline float
331 log(float __x) { return ::logf(__x); }
332 #else
333 inline float log(float __x)
334 { return ::log(static_cast<double>(__x)); }
335 #endif
336
337 using ::log;
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
347 #if _GLIBCPP_HAVE_LOG10F
348 inline float
349 log10(float __x) { return ::log10f(__x); }
350 #else
351 inline float
352 log10(float __x) { return ::log10(static_cast<double>(__x)); }
353 #endif
354
355 using ::log10;
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
365 #if _GLIBCPP_HAVE_MODFF
366 inline float
367 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
368 #else
369 inline float
370 modf(float __x, float* __iptr)
371 {
372 double __tmp;
373 double __res = ::modf(static_cast<double>(__x), &__tmp);
374 *__iptr = static_cast<float>(__tmp);
375 return __res;
376 }
377 #endif
378
379 using ::modf;
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
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 }
403
404 #if _GLIBCPP_HAVE_POWF
405 inline float
406 pow(float __x, float __y) { return ::powf(__x, __y); }
407 #else
408 inline float
409 pow(float __x, float __y)
410 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
411 #endif
412
413 using ::pow;
414
415 #if _GLIBCPP_HAVE_POWL
416 inline long double
417 pow(long double __x, long double __y) { return ::powl(__x, __y); }
418 #else
419 inline long double
420 pow(long double __x, long double __y)
421 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
422 #endif
423
424 inline float
425 pow(float __x, int __n)
426 { return __pow_helper(__x, __n); }
427
428 inline double
429 pow(double __x, int __i)
430 { return __pow_helper(__x, __i); }
431
432 inline long double
433 pow(long double __x, int __n)
434 { return __pow_helper(__x, __n); }
435
436 inline float
437 sin(float __x)
438 { return __builtin_sinf(__x); }
439
440 using ::sin;
441
442 inline long double
443 sin(long double __x)
444 { return __builtin_sinl(__x); }
445
446 #if _GLIBCPP_HAVE_SINHF
447 inline float
448 sinh(float __x) { return ::sinhf(__x); }
449 #else
450 inline float
451 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
452 #endif
453
454 using ::sinh;
455
456 #if _GLIBCPP_HAVE_SINHL
457 inline long double
458 sinh(long double __x) { return ::sinhl(__x); }
459 #else
460 inline long double
461 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
462 #endif
463
464 inline float
465 sqrt(float __x)
466 { return __builtin_sqrtf(__x); }
467
468 using ::sqrt;
469
470 inline long double
471 sqrt(long double __x)
472 { return __builtin_sqrtl(__x); }
473
474 #if _GLIBCPP_HAVE_TANF
475 inline float
476 tan(float __x) { return ::tanf(__x); }
477 #else
478 inline float
479 tan(float __x) { return ::tan(static_cast<double>(__x)); }
480 #endif
481
482 using ::tan;
483
484 #if _GLIBCPP_HAVE_TANL
485 inline long double
486 tan(long double __x) { return ::tanl(__x); }
487 #else
488 inline long double
489 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
490 #endif
491
492 #if _GLIBCPP_HAVE_TANHF
493 inline float
494 tanh(float __x) { return ::tanhf(__x); }
495 #else
496 inline float
497 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
498 #endif
499
500 using ::tanh;
501
502 #if _GLIBCPP_HAVE_TANHL
503 inline long double
504 tanh(long double __x) { return ::tanhl(__x); }
505 #else
506 inline long double
507 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
508 #endif
509 }
510
511
512 #if _GLIBCPP_USE_C99
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.
516 namespace __gnu_cxx
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
544 __capture_isgreater(_Tp __f1, _Tp __f2)
545 { return isgreater(__f1, __f2); }
546
547 template<typename _Tp>
548 int
549 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
550 { return isgreaterequal(__f1, __f2); }
551
552 template<typename _Tp>
553 int
554 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
555
556 template<typename _Tp>
557 int
558 __capture_islessequal(_Tp __f1, _Tp __f2)
559 { return islessequal(__f1, __f2); }
560
561 template<typename _Tp>
562 int
563 __capture_islessgreater(_Tp __f1, _Tp __f2)
564 { return islessgreater(__f1, __f2); }
565
566 template<typename _Tp>
567 int
568 __capture_isunordered(_Tp __f1, _Tp __f2)
569 { return isunordered(__f1, __f2); }
570 }
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
587 namespace __gnu_cxx
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
633 islessgreater(_Tp __f1, _Tp __f2)
634 { return __capture_islessgreater(__f1, __f2); }
635
636 template<typename _Tp>
637 int
638 isunordered(_Tp __f1, _Tp __f2)
639 { return __capture_isunordered(__f1, __f2); }
640 }
641
642 namespace std
643 {
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;
656 }
657 #endif
658
659 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
660 # define export
661 # include <bits/cmath.tcc>
662 #endif
663
664 #endif