]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/c_std/cmath
Makefile.am (std_headers): Remove cXXX from list.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_std / cmath
1 // -*- C++ -*- C math library.
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 //
31 // ISO C++ 14882: 26.5 C library
32 //
33
34 #ifndef _CPP_CMATH
35 #define _CPP_CMATH 1
36
37 #include <bits/c++config.h>
38
39 #pragma GCC system_header
40 #include <math.h>
41
42 // Get rid of those macros defined in <math.h> in lieu of real functions.
43 #undef abs
44 #undef div
45 #undef acos
46 #undef asin
47 #undef atan
48 #undef atan2
49 #undef ceil
50 #undef cos
51 #undef cosh
52 #undef exp
53 #undef fabs
54 #undef floor
55 #undef fmod
56 #undef frexp
57 #undef ldexp
58 #undef log
59 #undef log10
60 #undef modf
61 #undef pow
62 #undef sin
63 #undef sinh
64 #undef sqrt
65 #undef tan
66 #undef tanh
67
68 namespace std
69 {
70 // Forward declaration of a helper function. This really should be
71 // an `exported' forward declaration.
72 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
73
74 template<typename _Tp>
75 inline _Tp
76 __cmath_abs(_Tp __x)
77 {
78 return __x < _Tp() ? -__x : __x;
79 }
80
81 inline float
82 abs(float __x)
83 { return __builtin_fabsf(__x); }
84
85 inline double
86 abs(double __x)
87 { return __builtin_fabs(__x); }
88
89 inline long double
90 abs(long double __x)
91 { return __builtin_fabsl(__x); }
92
93 #if _GLIBCPP_HAVE_ACOSF
94 inline float
95 acos(float __x) { return ::acosf(__x); }
96 #else
97 inline float
98 acos(float __x) { return ::acos(static_cast<double>(__x)); }
99 #endif
100
101 using ::acos;
102
103 #if _GLIBCPP_HAVE_ACOSL
104 inline long double
105 acos(long double __x) { return ::acosl(__x); }
106 #else
107 inline long double
108 acos(long double __x) { return ::acos(static_cast<double>(__x)); }
109 #endif
110
111 #if _GLIBCPP_HAVE_ASINF
112 inline float
113 asin(float __x) { return ::asinf(__x); }
114 #else
115 inline float
116 asin(float __x) { return ::asin(static_cast<double>(__x)); }
117 #endif
118
119 using ::asin;
120
121 #if _GLIBCPP_HAVE_ASINL
122 inline long double
123 asin(long double __x) { return ::asinl(__x); }
124 #else
125 inline long double
126 asin(long double __x) { return ::asin(static_cast<double>(__x)); }
127 #endif
128
129 #if _GLIBCPP_HAVE_ATANF
130 inline float
131 atan(float __x) { return ::atanf(__x); }
132 #else
133 inline float
134 atan(float __x) { return ::atan(static_cast<double>(__x)); }
135 #endif
136
137 using ::atan;
138
139 #if _GLIBCPP_HAVE_ATANL
140 inline long double
141 atan(long double __x) { return ::atanl(__x); }
142 #else
143 inline long double
144 atan(long double __x) { return ::atan(static_cast<double>(__x)); }
145 #endif
146
147 #if _GLIBCPP_HAVE_ATAN2F
148 inline float
149 atan2(float __y, float __x) { return ::atan2f(__y, __x); }
150 #else
151 inline float
152 atan2(float __y, float __x)
153 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
154 #endif
155
156 using ::atan2;
157
158 #if _GLIBCPP_HAVE_ATAN2L
159 inline long double
160 atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
161 #else
162 inline long double
163 atan2(long double __y, long double __x)
164 { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
165 #endif
166
167 #if _GLIBCPP_HAVE_CEILF
168 inline float
169 ceil(float __x) { return ::ceilf(__x); }
170 #else
171 inline float
172 ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
173 #endif
174
175 using ::ceil;
176
177 #if _GLIBCPP_HAVE_CEILL
178 inline long double
179 ceil(long double __x) { return ::ceill(__x); }
180 #else
181 inline long double
182 ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
183 #endif
184
185 inline float
186 cos(float __x)
187 { return __builtin_cosf(__x); }
188
189 using ::cos;
190
191 inline long double
192 cos(long double __x)
193 { return __builtin_cosl(__x); }
194
195 #if _GLIBCPP_HAVE_COSHF
196 inline float
197 cosh(float __x) { return ::coshf(__x); }
198 #else
199 inline float
200 cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
201 #endif
202
203 using ::cosh;
204
205 #if _GLIBCPP_HAVE_COSHL
206 inline long double
207 cosh(long double __x) { return ::coshl(__x); }
208 #else
209 inline long double
210 cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
211 #endif
212
213 #if _GLIBCPP_HAVE_EXPF
214 inline float
215 exp(float __x) { return ::expf(__x); }
216 #else
217 inline float
218 exp(float __x) { return ::exp(static_cast<double>(__x)); }
219 #endif
220
221 using ::exp;
222
223 #if _GLIBCPP_HAVE_EXPL
224 inline long double
225 exp(long double __x) { return ::expl(__x); }
226 #else
227 inline long double
228 exp(long double __x) { return ::exp(static_cast<double>(__x)); }
229 #endif
230
231 inline float
232 fabs(float __x)
233 { return __builtin_fabsf(__x); }
234
235 using ::fabs;
236
237 inline long double
238 fabs(long double __x)
239 { return __builtin_fabsl(__x); }
240
241 #if _GLIBCPP_HAVE_FLOORF
242 inline float
243 floor(float __x) { return ::floorf(__x); }
244 #else
245 inline float
246 floor(float __x) { return ::floor(static_cast<double>(__x)); }
247 #endif
248
249 using ::floor;
250
251 #if _GLIBCPP_HAVE_FLOORL
252 inline long double
253 floor(long double __x) { return ::floorl(__x); }
254 #else
255 inline long double
256 floor(long double __x) { return ::floor(static_cast<double>(__x)); }
257 #endif
258
259 #if _GLIBCPP_HAVE_FMODF
260 inline float
261 fmod(float __x, float __y) { return ::fmodf(__x, __y); }
262 #else
263 inline float
264 fmod(float __x, float __y)
265 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
266 #endif
267
268 using ::fmod;
269
270 #if _GLIBCPP_HAVE_FMODL
271 inline long double
272 fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
273 #else
274 inline long double
275 fmod(long double __x, long double __y)
276 { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
277 #endif
278
279 #if _GLIBCPP_HAVE_FREXPF
280 inline float
281 frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
282 #else
283 inline float
284 frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
285 #endif
286
287 using ::frexp;
288
289 #if _GLIBCPP_HAVE_FREXPL
290 inline long double
291 frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
292 #else
293 inline long double
294 frexp(long double __x, int* __exp)
295 { return ::frexp(static_cast<double>(__x), __exp); }
296 #endif
297
298 #if _GLIBCPP_HAVE_LDEXPF
299 inline float
300 ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
301 #else
302 inline float
303 ldexp(float __x, int __exp)
304 { return ::ldexp(static_cast<double>(__x), __exp); }
305 #endif
306
307 using ::ldexp;
308
309 #if _GLIBCPP_HAVE_LDEXPL
310 inline long double
311 ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
312 #else
313 inline long double
314 ldexp(long double __x, int __exp)
315 { return ::ldexp(static_cast<double>(__x), __exp); }
316 #endif
317
318 #if _GLIBCPP_HAVE_LOGF
319 inline float
320 log(float __x) { return ::logf(__x); }
321 #else
322 inline float log(float __x)
323 { return ::log(static_cast<double>(__x)); }
324 #endif
325
326 using ::log;
327
328 #if _GLIBCPP_HAVE_LOGL
329 inline long double
330 log(long double __x) { return ::logl(__x); }
331 #else
332 inline long double
333 log(long double __x) { return ::log(static_cast<double>(__x)); }
334 #endif
335
336 #if _GLIBCPP_HAVE_LOG10F
337 inline float
338 log10(float __x) { return ::log10f(__x); }
339 #else
340 inline float
341 log10(float __x) { return ::log10(static_cast<double>(__x)); }
342 #endif
343
344 using ::log10;
345
346 #if _GLIBCPP_HAVE_LOG10L
347 inline long double
348 log10(long double __x) { return ::log10l(__x); }
349 #else
350 inline long double
351 log10(long double __x) { return ::log10(static_cast<double>(__x)); }
352 #endif
353
354 #if _GLIBCPP_HAVE_MODFF
355 inline float
356 modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
357 #else
358 inline float
359 modf(float __x, float* __iptr)
360 {
361 double __tmp;
362 double __res = ::modf(static_cast<double>(__x), &__tmp);
363 *__iptr = static_cast<float>(__tmp);
364 return __res;
365 }
366 #endif
367
368 using ::modf;
369
370 #if _GLIBCPP_HAVE_MODFL
371 inline long double
372 modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
373 #else
374 inline long double
375 modf(long double __x, long double* __iptr)
376 {
377 double __tmp;
378 double __res = ::modf(static_cast<double>(__x), &__tmp);
379 * __iptr = static_cast<long double>(__tmp);
380 return __res;
381 }
382 #endif
383
384 template<typename _Tp>
385 inline _Tp
386 __pow_helper(_Tp __x, int __n)
387 {
388 return __n < 0
389 ? _Tp(1)/__cmath_power(__x, -__n)
390 : __cmath_power(__x, __n);
391 }
392
393 #if _GLIBCPP_HAVE_POWF
394 inline float
395 pow(float __x, float __y) { return ::powf(__x, __y); }
396 #else
397 inline float
398 pow(float __x, float __y)
399 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
400 #endif
401
402 using ::pow;
403
404 #if _GLIBCPP_HAVE_POWL
405 inline long double
406 pow(long double __x, long double __y) { return ::powl(__x, __y); }
407 #else
408 inline long double
409 pow(long double __x, long double __y)
410 { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
411 #endif
412
413 inline float
414 pow(float __x, int __n)
415 { return __pow_helper(__x, __n); }
416
417 inline double
418 pow(double __x, int __i)
419 { return __pow_helper(__x, __i); }
420
421 inline long double
422 pow(long double __x, int __n)
423 { return __pow_helper(__x, __n); }
424
425 inline float
426 sin(float __x)
427 { return __builtin_sinf(__x); }
428
429 using ::sin;
430
431 inline long double
432 sin(long double __x)
433 { return __builtin_sinl(__x); }
434
435 #if _GLIBCPP_HAVE_SINHF
436 inline float
437 sinh(float __x) { return ::sinhf(__x); }
438 #else
439 inline float
440 sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
441 #endif
442
443 using ::sinh;
444
445 #if _GLIBCPP_HAVE_SINHL
446 inline long double
447 sinh(long double __x) { return ::sinhl(__x); }
448 #else
449 inline long double
450 sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
451 #endif
452
453 inline float
454 sqrt(float __x)
455 { return __builtin_sqrtf(__x); }
456
457 using ::sqrt;
458
459 inline long double
460 sqrt(long double __x)
461 { return __builtin_sqrtl(__x); }
462
463 #if _GLIBCPP_HAVE_TANF
464 inline float
465 tan(float __x) { return ::tanf(__x); }
466 #else
467 inline float
468 tan(float __x) { return ::tan(static_cast<double>(__x)); }
469 #endif
470
471 using ::tan;
472
473 #if _GLIBCPP_HAVE_TANL
474 inline long double
475 tan(long double __x) { return ::tanl(__x); }
476 #else
477 inline long double
478 tan(long double __x) { return ::tan(static_cast<double>(__x)); }
479 #endif
480
481 #if _GLIBCPP_HAVE_TANHF
482 inline float
483 tanh(float __x) { return ::tanhf(__x); }
484 #else
485 inline float
486 tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
487 #endif
488
489 using ::tanh;
490
491 #if _GLIBCPP_HAVE_TANHL
492 inline long double
493 tanh(long double __x) { return ::tanhl(__x); }
494 #else
495 inline long double
496 tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
497 #endif
498 }
499
500
501 #if _GLIBCPP_USE_C99
502 // These are possible macros imported from C99-land. For strict
503 // conformance, remove possible C99-injected names from the global
504 // namespace, and sequester them in the __gnu_cxx extension namespace.
505 namespace __gnu_cxx
506 {
507 template<typename _Tp>
508 int
509 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
510
511 template<typename _Tp>
512 int
513 __capture_isfinite(_Tp __f) { return isfinite(__f); }
514
515 template<typename _Tp>
516 int
517 __capture_isinf(_Tp __f) { return isinf(__f); }
518
519 template<typename _Tp>
520 int
521 __capture_isnan(_Tp __f) { return isnan(__f); }
522
523 template<typename _Tp>
524 int
525 __capture_isnormal(_Tp __f) { return isnormal(__f); }
526
527 template<typename _Tp>
528 int
529 __capture_signbit(_Tp __f) { return signbit(__f); }
530
531 template<typename _Tp>
532 int
533 __capture_isgreater(_Tp __f1, _Tp __f2)
534 { return isgreater(__f1, __f2); }
535
536 template<typename _Tp>
537 int
538 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
539 { return isgreaterequal(__f1, __f2); }
540
541 template<typename _Tp>
542 int
543 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
544
545 template<typename _Tp>
546 int
547 __capture_islessequal(_Tp __f1, _Tp __f2)
548 { return islessequal(__f1, __f2); }
549
550 template<typename _Tp>
551 int
552 __capture_islessgreater(_Tp __f1, _Tp __f2)
553 { return islessgreater(__f1, __f2); }
554
555 template<typename _Tp>
556 int
557 __capture_isunordered(_Tp __f1, _Tp __f2)
558 { return isunordered(__f1, __f2); }
559 }
560 #endif
561
562 #undef fpclassify
563 #undef isfinite
564 #undef isinf
565 #undef isnan
566 #undef isnormal
567 #undef signbit
568 #undef isgreater
569 #undef isgreaterequal
570 #undef isless
571 #undef islessequal
572 #undef islessgreater
573 #undef isunordered
574
575 #if _GLIBCPP_USE_C99
576 namespace __gnu_cxx
577 {
578 template<typename _Tp>
579 int
580 fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
581
582 template<typename _Tp>
583 int
584 isfinite(_Tp __f) { return __capture_isfinite(__f); }
585
586 template<typename _Tp>
587 int
588 isinf(_Tp __f) { return __capture_isinf(__f); }
589
590 template<typename _Tp>
591 int
592 isnan(_Tp __f) { return __capture_isnan(__f); }
593
594 template<typename _Tp>
595 int
596 isnormal(_Tp __f) { return __capture_isnormal(__f); }
597
598 template<typename _Tp>
599 int
600 signbit(_Tp __f) { return __capture_signbit(__f); }
601
602 template<typename _Tp>
603 int
604 isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
605
606 template<typename _Tp>
607 int
608 isgreaterequal(_Tp __f1, _Tp __f2)
609 { return __capture_isgreaterequal(__f1, __f2); }
610
611 template<typename _Tp>
612 int
613 isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
614
615 template<typename _Tp>
616 int
617 islessequal(_Tp __f1, _Tp __f2)
618 { return __capture_islessequal(__f1, __f2); }
619
620 template<typename _Tp>
621 int
622 islessgreater(_Tp __f1, _Tp __f2)
623 { return __capture_islessgreater(__f1, __f2); }
624
625 template<typename _Tp>
626 int
627 isunordered(_Tp __f1, _Tp __f2)
628 { return __capture_isunordered(__f1, __f2); }
629 }
630
631 namespace std
632 {
633 using __gnu_cxx::fpclassify;
634 using __gnu_cxx::isfinite;
635 using __gnu_cxx::isinf;
636 using __gnu_cxx::isnan;
637 using __gnu_cxx::isnormal;
638 using __gnu_cxx::signbit;
639 using __gnu_cxx::isgreater;
640 using __gnu_cxx::isgreaterequal;
641 using __gnu_cxx::isless;
642 using __gnu_cxx::islessequal;
643 using __gnu_cxx::islessgreater;
644 using __gnu_cxx::isunordered;
645 }
646 #endif
647
648 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
649 # define export
650 # include <cmath.tcc>
651 #endif
652
653 #endif
654
655
656