]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/c_global/cmath
Daily bump.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_global / cmath
CommitLineData
af13a7a6
BK
1// -*- C++ -*- C forwarding header.
2
e133ace8 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
ebd15f80 4// 2006, 2007, 2008
af13a7a6
BK
5// Free Software Foundation, Inc.
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 2, or (at your option)
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this library; see the file COPYING. If not, write to
20// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21// Boston, MA 02110-1301, USA.
22
23// As a special exception, you may use this file as part of a free software
24// library without restriction. Specifically, if other files instantiate
25// templates or use macros or inline functions from this file, or you compile
26// this file and link it with other files to produce an executable, this
27// file does not by itself cause the resulting executable to be covered by
28// the GNU General Public License. This exception does not however
29// invalidate any other reasons why the executable file might be covered by
30// the GNU General Public License.
31
32/** @file include/cmath
33 * This is a Standard C++ Library file. You should @c #include this file
34 * in your programs, rather than any of the "*.h" implementation files.
35 *
36 * This is the C++ version of the Standard C Library header @c math.h,
37 * and its contents are (mostly) the same as that header, but are all
38 * contained in the namespace @c std (except for names which are defined
39 * as macros in C).
40 */
41
42//
43// ISO C++ 14882: 26.5 C library
44//
45
46#pragma GCC system_header
47
48#include <bits/c++config.h>
49#include <bits/cpp_type_traits.h>
50#include <ext/type_traits.h>
51#include_next <math.h>
52
53#ifndef _GLIBCXX_CMATH
54#define _GLIBCXX_CMATH 1
55
56// Get rid of those macros defined in <math.h> in lieu of real functions.
57#undef abs
58#undef div
59#undef acos
60#undef asin
61#undef atan
62#undef atan2
63#undef ceil
64#undef cos
65#undef cosh
66#undef exp
67#undef fabs
68#undef floor
69#undef fmod
70#undef frexp
71#undef ldexp
72#undef log
73#undef log10
74#undef modf
75#undef pow
76#undef sin
77#undef sinh
78#undef sqrt
79#undef tan
80#undef tanh
81
82_GLIBCXX_BEGIN_NAMESPACE(std)
83
84 // Forward declaration of a helper function. This really should be
85 // an `exported' forward declaration.
e133ace8
PC
86 template<typename _Tp>
87 _Tp __cmath_power(_Tp, unsigned int);
88
89 template<typename _Tp>
90 inline _Tp
91 __pow_helper(_Tp __x, int __n)
92 {
93 return __n < 0
94 ? _Tp(1)/__cmath_power(__x, -__n)
95 : __cmath_power(__x, __n);
96 }
af13a7a6
BK
97
98 inline double
99 abs(double __x)
100 { return __builtin_fabs(__x); }
101
102 inline float
103 abs(float __x)
104 { return __builtin_fabsf(__x); }
105
106 inline long double
107 abs(long double __x)
108 { return __builtin_fabsl(__x); }
109
110 using ::acos;
111
112 inline float
113 acos(float __x)
114 { return __builtin_acosf(__x); }
115
116 inline long double
117 acos(long double __x)
118 { return __builtin_acosl(__x); }
119
120 template<typename _Tp>
121 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
122 double>::__type
123 acos(_Tp __x)
124 { return __builtin_acos(__x); }
125
126 using ::asin;
127
128 inline float
129 asin(float __x)
130 { return __builtin_asinf(__x); }
131
132 inline long double
133 asin(long double __x)
134 { return __builtin_asinl(__x); }
135
136 template<typename _Tp>
e133ace8
PC
137 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
138 double>::__type
af13a7a6
BK
139 asin(_Tp __x)
140 { return __builtin_asin(__x); }
141
142 using ::atan;
143
144 inline float
145 atan(float __x)
146 { return __builtin_atanf(__x); }
147
148 inline long double
149 atan(long double __x)
150 { return __builtin_atanl(__x); }
151
152 template<typename _Tp>
e133ace8
PC
153 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
154 double>::__type
af13a7a6
BK
155 atan(_Tp __x)
156 { return __builtin_atan(__x); }
157
158 using ::atan2;
159
160 inline float
161 atan2(float __y, float __x)
162 { return __builtin_atan2f(__y, __x); }
163
164 inline long double
165 atan2(long double __y, long double __x)
166 { return __builtin_atan2l(__y, __x); }
167
168 template<typename _Tp, typename _Up>
0e7edcd5
PC
169 inline
170 typename __gnu_cxx::__promote_2<
171 typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
172 && __is_arithmetic<_Up>::__value,
173 _Tp>::__type, _Up>::__type
af13a7a6 174 atan2(_Tp __y, _Up __x)
e133ace8
PC
175 {
176 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
177 return atan2(__type(__y), __type(__x));
178 }
af13a7a6
BK
179
180 using ::ceil;
181
182 inline float
183 ceil(float __x)
184 { return __builtin_ceilf(__x); }
185
186 inline long double
187 ceil(long double __x)
188 { return __builtin_ceill(__x); }
189
190 template<typename _Tp>
191 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
192 double>::__type
193 ceil(_Tp __x)
194 { return __builtin_ceil(__x); }
195
196 using ::cos;
197
198 inline float
199 cos(float __x)
200 { return __builtin_cosf(__x); }
201
202 inline long double
203 cos(long double __x)
204 { return __builtin_cosl(__x); }
205
206 template<typename _Tp>
207 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
208 double>::__type
209 cos(_Tp __x)
210 { return __builtin_cos(__x); }
211
212 using ::cosh;
213
214 inline float
215 cosh(float __x)
216 { return __builtin_coshf(__x); }
217
218 inline long double
219 cosh(long double __x)
220 { return __builtin_coshl(__x); }
221
222 template<typename _Tp>
223 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
224 double>::__type
225 cosh(_Tp __x)
226 { return __builtin_cosh(__x); }
227
228 using ::exp;
229
230 inline float
231 exp(float __x)
232 { return __builtin_expf(__x); }
233
234 inline long double
235 exp(long double __x)
236 { return __builtin_expl(__x); }
237
238 template<typename _Tp>
239 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
240 double>::__type
241 exp(_Tp __x)
242 { return __builtin_exp(__x); }
243
244 using ::fabs;
245
246 inline float
247 fabs(float __x)
248 { return __builtin_fabsf(__x); }
249
250 inline long double
251 fabs(long double __x)
252 { return __builtin_fabsl(__x); }
253
254 template<typename _Tp>
255 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
256 double>::__type
257 fabs(_Tp __x)
258 { return __builtin_fabs(__x); }
259
260 using ::floor;
261
262 inline float
263 floor(float __x)
264 { return __builtin_floorf(__x); }
265
266 inline long double
267 floor(long double __x)
268 { return __builtin_floorl(__x); }
269
270 template<typename _Tp>
271 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
272 double>::__type
273 floor(_Tp __x)
274 { return __builtin_floor(__x); }
275
276 using ::fmod;
277
278 inline float
279 fmod(float __x, float __y)
280 { return __builtin_fmodf(__x, __y); }
281
282 inline long double
283 fmod(long double __x, long double __y)
284 { return __builtin_fmodl(__x, __y); }
285
286 using ::frexp;
287
288 inline float
289 frexp(float __x, int* __exp)
290 { return __builtin_frexpf(__x, __exp); }
291
292 inline long double
293 frexp(long double __x, int* __exp)
294 { return __builtin_frexpl(__x, __exp); }
295
296 template<typename _Tp>
297 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
298 double>::__type
299 frexp(_Tp __x, int* __exp)
300 { return __builtin_frexp(__x, __exp); }
301
302 using ::ldexp;
303
304 inline float
305 ldexp(float __x, int __exp)
306 { return __builtin_ldexpf(__x, __exp); }
307
308 inline long double
309 ldexp(long double __x, int __exp)
310 { return __builtin_ldexpl(__x, __exp); }
311
312 template<typename _Tp>
313 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
314 double>::__type
315 ldexp(_Tp __x, int __exp)
316 { return __builtin_ldexp(__x, __exp); }
317
318 using ::log;
319
320 inline float
321 log(float __x)
322 { return __builtin_logf(__x); }
323
324 inline long double
325 log(long double __x)
326 { return __builtin_logl(__x); }
327
328 template<typename _Tp>
329 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
330 double>::__type
331 log(_Tp __x)
332 { return __builtin_log(__x); }
333
334 using ::log10;
335
336 inline float
337 log10(float __x)
338 { return __builtin_log10f(__x); }
339
340 inline long double
341 log10(long double __x)
342 { return __builtin_log10l(__x); }
343
344 template<typename _Tp>
345 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
346 double>::__type
347 log10(_Tp __x)
348 { return __builtin_log10(__x); }
349
350 using ::modf;
351
352 inline float
353 modf(float __x, float* __iptr)
354 { return __builtin_modff(__x, __iptr); }
355
356 inline long double
357 modf(long double __x, long double* __iptr)
358 { return __builtin_modfl(__x, __iptr); }
359
af13a7a6
BK
360 using ::pow;
361
362 inline float
363 pow(float __x, float __y)
364 { return __builtin_powf(__x, __y); }
365
366 inline long double
367 pow(long double __x, long double __y)
368 { return __builtin_powl(__x, __y); }
369
e133ace8 370 // DR 550.
af13a7a6
BK
371 inline double
372 pow(double __x, int __i)
373 { return __builtin_powi(__x, __i); }
374
375 inline float
376 pow(float __x, int __n)
377 { return __builtin_powif(__x, __n); }
378
379 inline long double
380 pow(long double __x, int __n)
381 { return __builtin_powil(__x, __n); }
382
e133ace8 383 template<typename _Tp, typename _Up>
0e7edcd5
PC
384 inline
385 typename __gnu_cxx::__promote_2<
386 typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
387 && __is_arithmetic<_Up>::__value,
388 _Tp>::__type, _Up>::__type
e133ace8
PC
389 pow(_Tp __x, _Up __y)
390 {
391 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
392 return pow(__type(__x), __type(__y));
393 }
394
af13a7a6
BK
395 using ::sin;
396
397 inline float
398 sin(float __x)
399 { return __builtin_sinf(__x); }
400
401 inline long double
402 sin(long double __x)
403 { return __builtin_sinl(__x); }
404
405 template<typename _Tp>
406 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
407 double>::__type
408 sin(_Tp __x)
409 { return __builtin_sin(__x); }
410
411 using ::sinh;
412
413 inline float
414 sinh(float __x)
415 { return __builtin_sinhf(__x); }
416
417 inline long double
418 sinh(long double __x)
419 { return __builtin_sinhl(__x); }
420
421 template<typename _Tp>
422 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
423 double>::__type
424 sinh(_Tp __x)
425 { return __builtin_sinh(__x); }
426
427 using ::sqrt;
428
429 inline float
430 sqrt(float __x)
431 { return __builtin_sqrtf(__x); }
432
433 inline long double
434 sqrt(long double __x)
435 { return __builtin_sqrtl(__x); }
436
437 template<typename _Tp>
438 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
439 double>::__type
440 sqrt(_Tp __x)
441 { return __builtin_sqrt(__x); }
442
443 using ::tan;
444
445 inline float
446 tan(float __x)
447 { return __builtin_tanf(__x); }
448
449 inline long double
450 tan(long double __x)
451 { return __builtin_tanl(__x); }
452
453 template<typename _Tp>
454 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
455 double>::__type
456 tan(_Tp __x)
457 { return __builtin_tan(__x); }
458
459 using ::tanh;
460
461 inline float
462 tanh(float __x)
463 { return __builtin_tanhf(__x); }
464
465 inline long double
466 tanh(long double __x)
467 { return __builtin_tanhl(__x); }
468
469 template<typename _Tp>
470 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
471 double>::__type
472 tanh(_Tp __x)
473 { return __builtin_tanh(__x); }
474
475_GLIBCXX_END_NAMESPACE
476
477#if _GLIBCXX_USE_C99_MATH
478#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
479// These are possible macros imported from C99-land. For strict
480// conformance, remove possible C99-injected names from the global
481// namespace, and sequester them in the __gnu_cxx extension namespace.
482
af13a7a6
BK
483// Only undefine the C99 FP macros, if actually captured for namespace movement
484#undef fpclassify
485#undef isfinite
486#undef isinf
487#undef isnan
488#undef isnormal
489#undef signbit
490#undef isgreater
491#undef isgreaterequal
492#undef isless
493#undef islessequal
494#undef islessgreater
495#undef isunordered
496
497_GLIBCXX_BEGIN_NAMESPACE(std)
498
499 template<typename _Tp>
0e7edcd5
PC
500 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
501 int>::__type
502 fpclassify(_Tp __f)
503 {
504 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
ebd15f80
PC
505 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
506 FP_SUBNORMAL, FP_ZERO, __type(__f));
0e7edcd5 507 }
af13a7a6
BK
508
509 template<typename _Tp>
0e7edcd5
PC
510 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
511 int>::__type
512 isfinite(_Tp __f)
513 {
514 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
515 return __builtin_isfinite(__type(__f));
516 }
af13a7a6
BK
517
518 template<typename _Tp>
0e7edcd5
PC
519 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
520 int>::__type
521 isinf(_Tp __f)
522 {
523 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
524 return __builtin_isinf(__type(__f));
525 }
af13a7a6
BK
526
527 template<typename _Tp>
0e7edcd5
PC
528 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
529 int>::__type
530 isnan(_Tp __f)
531 {
532 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
533 return __builtin_isnan(__type(__f));
534 }
af13a7a6
BK
535
536 template<typename _Tp>
0e7edcd5
PC
537 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
538 int>::__type
539 isnormal(_Tp __f)
540 {
541 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
542 return __builtin_isnormal(__type(__f));
543 }
af13a7a6
BK
544
545 template<typename _Tp>
0e7edcd5
PC
546 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
547 int>::__type
548 signbit(_Tp __f)
549 {
550 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
551 return __builtin_signbit(__type(__f));
552 }
af13a7a6
BK
553
554 template<typename _Tp>
0e7edcd5
PC
555 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
556 int>::__type
af13a7a6 557 isgreater(_Tp __f1, _Tp __f2)
0e7edcd5
PC
558 {
559 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
560 return __builtin_isgreater(__type(__f1), __type(__f2));
561 }
af13a7a6
BK
562
563 template<typename _Tp>
0e7edcd5
PC
564 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
565 int>::__type
af13a7a6 566 isgreaterequal(_Tp __f1, _Tp __f2)
0e7edcd5
PC
567 {
568 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
569 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
570 }
af13a7a6
BK
571
572 template<typename _Tp>
0e7edcd5
PC
573 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
574 int>::__type
af13a7a6 575 isless(_Tp __f1, _Tp __f2)
0e7edcd5
PC
576 {
577 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
578 return __builtin_isless(__type(__f1), __type(__f2));
579 }
af13a7a6
BK
580
581 template<typename _Tp>
0e7edcd5
PC
582 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
583 int>::__type
af13a7a6 584 islessequal(_Tp __f1, _Tp __f2)
0e7edcd5
PC
585 {
586 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
587 return __builtin_islessequal(__type(__f1), __type(__f2));
588 }
af13a7a6
BK
589
590 template<typename _Tp>
0e7edcd5
PC
591 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
592 int>::__type
af13a7a6 593 islessgreater(_Tp __f1, _Tp __f2)
0e7edcd5
PC
594 {
595 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
596 return __builtin_islessgreater(__type(__f1), __type(__f2));
597 }
af13a7a6
BK
598
599 template<typename _Tp>
0e7edcd5
PC
600 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
601 int>::__type
af13a7a6 602 isunordered(_Tp __f1, _Tp __f2)
0e7edcd5
PC
603 {
604 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
605 return __builtin_isunordered(__type(__f1), __type(__f2));
606 }
af13a7a6
BK
607
608_GLIBCXX_END_NAMESPACE
609
610#endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
611#endif
612
613#ifndef _GLIBCXX_EXPORT_TEMPLATE
614# include <bits/cmath.tcc>
615#endif
616
617#ifdef __GXX_EXPERIMENTAL_CXX0X__
e133ace8
PC
618# if defined(_GLIBCXX_INCLUDE_AS_TR1)
619# error C++0x header cannot be included from TR1 header
620# endif
e133ace8
PC
621# if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
622# include <tr1_impl/cmath>
623# else
624# define _GLIBCXX_INCLUDE_AS_CXX0X
625# define _GLIBCXX_BEGIN_NAMESPACE_TR1
626# define _GLIBCXX_END_NAMESPACE_TR1
627# define _GLIBCXX_TR1
628# include <tr1_impl/cmath>
629# undef _GLIBCXX_TR1
630# undef _GLIBCXX_END_NAMESPACE_TR1
631# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
632# undef _GLIBCXX_INCLUDE_AS_CXX0X
633# endif
af13a7a6
BK
634#endif
635
636#endif