Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / c_std / std_cmath.h
blob115fe47106419698b2ce851ff1d2aa5d16d316e4
1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
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.
32 // ISO C++ 14882: 26.5 C library
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.
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 (except for names which are defined
42 * as macros in C).
45 #ifndef _GLIBCXX_CMATH
46 #define _GLIBCXX_CMATH 1
48 #pragma GCC system_header
50 #include <bits/c++config.h>
51 #include <bits/cpp_type_traits.h>
53 #include <math.h>
55 // Get rid of those macros defined in <math.h> in lieu of real functions.
56 #undef abs
57 #undef div
58 #undef acos
59 #undef asin
60 #undef atan
61 #undef atan2
62 #undef ceil
63 #undef cos
64 #undef cosh
65 #undef exp
66 #undef fabs
67 #undef floor
68 #undef fmod
69 #undef frexp
70 #undef ldexp
71 #undef log
72 #undef log10
73 #undef modf
74 #undef pow
75 #undef sin
76 #undef sinh
77 #undef sqrt
78 #undef tan
79 #undef tanh
82 namespace std
84 // Forward declaration of a helper function. This really should be
85 // an `exported' forward declaration.
86 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
88 inline double
89 abs(double __x)
90 { return __builtin_fabs(__x); }
92 inline float
93 abs(float __x)
94 { return __builtin_fabsf(__x); }
96 inline long double
97 abs(long double __x)
98 { return __builtin_fabsl(__x); }
100 using ::acos;
102 inline float
103 acos(float __x)
104 { return __builtin_acosf(__x); }
106 inline long double
107 acos(long double __x)
108 { return __builtin_acosl(__x); }
110 template<typename _Tp>
111 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
112 acos(_Tp __x)
114 return __builtin_acos(__x);
117 using ::asin;
119 inline float
120 asin(float __x)
121 { return __builtin_asinf(__x); }
123 inline long double
124 asin(long double __x)
125 { return __builtin_asinl(__x); }
127 template<typename _Tp>
128 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
129 asin(_Tp __x)
130 { return __builtin_asin(__x); }
132 using ::atan;
134 inline float
135 atan(float __x)
136 { return __builtin_atanf(__x); }
138 inline long double
139 atan(long double __x)
140 { return __builtin_atanl(__x); }
142 template<typename _Tp>
143 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
144 atan(_Tp __x)
145 { return __builtin_atan(__x); }
147 using ::atan2;
149 inline float
150 atan2(float __y, float __x)
151 { return __builtin_atan2f(__y, __x); }
153 inline long double
154 atan2(long double __y, long double __x)
155 { return __builtin_atan2l(__y, __x); }
157 template<typename _Tp, typename _Up>
158 inline typename __enable_if<double, __is_integer<_Tp>::__value
159 && __is_integer<_Up>::__value>::__type
160 atan2(_Tp __y, _Up __x)
161 { return __builtin_atan2(__y, __x); }
163 using ::ceil;
165 inline float
166 ceil(float __x)
167 { return __builtin_ceilf(__x); }
169 inline long double
170 ceil(long double __x)
171 { return __builtin_ceill(__x); }
173 template<typename _Tp>
174 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
175 ceil(_Tp __x)
176 { return __builtin_ceil(__x); }
178 using ::cos;
180 inline float
181 cos(float __x)
182 { return __builtin_cosf(__x); }
184 inline long double
185 cos(long double __x)
186 { return __builtin_cosl(__x); }
188 template<typename _Tp>
189 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
190 cos(_Tp __x)
191 { return __builtin_cos(__x); }
193 using ::cosh;
195 inline float
196 cosh(float __x)
197 { return __builtin_coshf(__x); }
199 inline long double
200 cosh(long double __x)
201 { return __builtin_coshl(__x); }
203 template<typename _Tp>
204 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
205 cosh(_Tp __x)
206 { return __builtin_cosh(__x); }
208 using ::exp;
210 inline float
211 exp(float __x)
212 { return __builtin_expf(__x); }
214 inline long double
215 exp(long double __x)
216 { return __builtin_expl(__x); }
218 template<typename _Tp>
219 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
220 exp(_Tp __x)
221 { return __builtin_exp(__x); }
223 using ::fabs;
225 inline float
226 fabs(float __x)
227 { return __builtin_fabsf(__x); }
229 inline long double
230 fabs(long double __x)
231 { return __builtin_fabsl(__x); }
233 template<typename _Tp>
234 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
235 fabs(_Tp __x)
236 { return __builtin_fabs(__x); }
238 using ::floor;
240 inline float
241 floor(float __x)
242 { return __builtin_floorf(__x); }
244 inline long double
245 floor(long double __x)
246 { return __builtin_floorl(__x); }
248 template<typename _Tp>
249 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
250 floor(_Tp __x)
251 { return __builtin_floor(__x); }
253 using ::fmod;
255 inline float
256 fmod(float __x, float __y)
257 { return __builtin_fmodf(__x, __y); }
259 inline long double
260 fmod(long double __x, long double __y)
261 { return __builtin_fmodl(__x, __y); }
263 using ::frexp;
265 inline float
266 frexp(float __x, int* __exp)
267 { return __builtin_frexpf(__x, __exp); }
269 inline long double
270 frexp(long double __x, int* __exp)
271 { return __builtin_frexpl(__x, __exp); }
273 template<typename _Tp>
274 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
275 frexp(_Tp __x, int* __exp)
276 { return __builtin_frexp(__x, __exp); }
278 using ::ldexp;
280 inline float
281 ldexp(float __x, int __exp)
282 { return __builtin_ldexpf(__x, __exp); }
284 inline long double
285 ldexp(long double __x, int __exp)
286 { return __builtin_ldexpl(__x, __exp); }
288 template<typename _Tp>
289 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
290 ldexp(_Tp __x, int __exp)
291 { return __builtin_ldexp(__x, __exp); }
293 using ::log;
295 inline float
296 log(float __x)
297 { return __builtin_logf(__x); }
299 inline long double
300 log(long double __x)
301 { return __builtin_logl(__x); }
303 template<typename _Tp>
304 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
305 log(_Tp __x)
306 { return __builtin_log(__x); }
308 using ::log10;
310 inline float
311 log10(float __x)
312 { return __builtin_log10f(__x); }
314 inline long double
315 log10(long double __x)
316 { return __builtin_log10l(__x); }
318 template<typename _Tp>
319 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
320 log10(_Tp __x)
321 { return __builtin_log10(__x); }
323 using ::modf;
325 inline float
326 modf(float __x, float* __iptr)
327 { return __builtin_modff(__x, __iptr); }
329 inline long double
330 modf(long double __x, long double* __iptr)
331 { return __builtin_modfl(__x, __iptr); }
333 template<typename _Tp>
334 inline _Tp
335 __pow_helper(_Tp __x, int __n)
337 return __n < 0
338 ? _Tp(1)/__cmath_power(__x, -__n)
339 : __cmath_power(__x, __n);
342 using ::pow;
344 inline float
345 pow(float __x, float __y)
346 { return __builtin_powf(__x, __y); }
348 inline long double
349 pow(long double __x, long double __y)
350 { return __builtin_powl(__x, __y); }
352 inline double
353 pow(double __x, int __i)
354 { return __builtin_powi(__x, __i); }
356 inline float
357 pow(float __x, int __n)
358 { return __builtin_powif(__x, __n); }
360 inline long double
361 pow(long double __x, int __n)
362 { return __builtin_powil(__x, __n); }
364 using ::sin;
366 inline float
367 sin(float __x)
368 { return __builtin_sinf(__x); }
370 inline long double
371 sin(long double __x)
372 { return __builtin_sinl(__x); }
374 template<typename _Tp>
375 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
376 sin(_Tp __x)
377 { return __builtin_sin(__x); }
379 using ::sinh;
381 inline float
382 sinh(float __x)
383 { return __builtin_sinhf(__x); }
385 inline long double
386 sinh(long double __x)
387 { return __builtin_sinhl(__x); }
389 template<typename _Tp>
390 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
391 sinh(_Tp __x)
392 { return __builtin_sinh(__x); }
394 using ::sqrt;
396 inline float
397 sqrt(float __x)
398 { return __builtin_sqrtf(__x); }
400 inline long double
401 sqrt(long double __x)
402 { return __builtin_sqrtl(__x); }
404 template<typename _Tp>
405 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
406 sqrt(_Tp __x)
407 { return __builtin_sqrt(__x); }
409 using ::tan;
411 inline float
412 tan(float __x)
413 { return __builtin_tanf(__x); }
415 inline long double
416 tan(long double __x)
417 { return __builtin_tanl(__x); }
419 template<typename _Tp>
420 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
421 tan(_Tp __x)
422 { return __builtin_tan(__x); }
424 using ::tanh;
426 inline float
427 tanh(float __x)
428 { return __builtin_tanhf(__x); }
430 inline long double
431 tanh(long double __x)
432 { return __builtin_tanhl(__x); }
434 template<typename _Tp>
435 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
436 tanh(_Tp __x)
437 { return __builtin_tanh(__x); }
440 #if _GLIBCXX_USE_C99_MATH
441 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
442 // These are possible macros imported from C99-land. For strict
443 // conformance, remove possible C99-injected names from the global
444 // namespace, and sequester them in the __gnu_cxx extension namespace.
445 namespace __gnu_cxx
447 template<typename _Tp>
448 inline int
449 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
451 template<typename _Tp>
452 inline int
453 __capture_isfinite(_Tp __f) { return isfinite(__f); }
455 template<typename _Tp>
456 inline int
457 __capture_isinf(_Tp __f) { return isinf(__f); }
459 template<typename _Tp>
460 inline int
461 __capture_isnan(_Tp __f) { return isnan(__f); }
463 template<typename _Tp>
464 inline int
465 __capture_isnormal(_Tp __f) { return isnormal(__f); }
467 template<typename _Tp>
468 inline int
469 __capture_signbit(_Tp __f) { return signbit(__f); }
471 template<typename _Tp>
472 inline int
473 __capture_isgreater(_Tp __f1, _Tp __f2)
474 { return isgreater(__f1, __f2); }
476 template<typename _Tp>
477 inline int
478 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
479 { return isgreaterequal(__f1, __f2); }
481 template<typename _Tp>
482 inline int
483 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
485 template<typename _Tp>
486 inline int
487 __capture_islessequal(_Tp __f1, _Tp __f2)
488 { return islessequal(__f1, __f2); }
490 template<typename _Tp>
491 inline int
492 __capture_islessgreater(_Tp __f1, _Tp __f2)
493 { return islessgreater(__f1, __f2); }
495 template<typename _Tp>
496 inline int
497 __capture_isunordered(_Tp __f1, _Tp __f2)
498 { return isunordered(__f1, __f2); }
501 // Only undefine the C99 FP macros, if actually captured for namespace movement
502 #undef fpclassify
503 #undef isfinite
504 #undef isinf
505 #undef isnan
506 #undef isnormal
507 #undef signbit
508 #undef isgreater
509 #undef isgreaterequal
510 #undef isless
511 #undef islessequal
512 #undef islessgreater
513 #undef isunordered
515 namespace std
517 template<typename _Tp>
518 inline int
519 fpclassify(_Tp __f) { return __gnu_cxx::__capture_fpclassify(__f); }
521 template<typename _Tp>
522 inline int
523 isfinite(_Tp __f) { return __gnu_cxx::__capture_isfinite(__f); }
525 template<typename _Tp>
526 inline int
527 isinf(_Tp __f) { return __gnu_cxx::__capture_isinf(__f); }
529 template<typename _Tp>
530 inline int
531 isnan(_Tp __f) { return __gnu_cxx::__capture_isnan(__f); }
533 template<typename _Tp>
534 inline int
535 isnormal(_Tp __f) { return __gnu_cxx::__capture_isnormal(__f); }
537 template<typename _Tp>
538 inline int
539 signbit(_Tp __f) { return __gnu_cxx::__capture_signbit(__f); }
541 template<typename _Tp>
542 inline int
543 isgreater(_Tp __f1, _Tp __f2)
544 { return __gnu_cxx::__capture_isgreater(__f1, __f2); }
546 template<typename _Tp>
547 inline int
548 isgreaterequal(_Tp __f1, _Tp __f2)
549 { return __gnu_cxx::__capture_isgreaterequal(__f1, __f2); }
551 template<typename _Tp>
552 inline int
553 isless(_Tp __f1, _Tp __f2)
554 { return __gnu_cxx::__capture_isless(__f1, __f2); }
556 template<typename _Tp>
557 inline int
558 islessequal(_Tp __f1, _Tp __f2)
559 { return __gnu_cxx::__capture_islessequal(__f1, __f2); }
561 template<typename _Tp>
562 inline int
563 islessgreater(_Tp __f1, _Tp __f2)
564 { return __gnu_cxx::__capture_islessgreater(__f1, __f2); }
566 template<typename _Tp>
567 inline int
568 isunordered(_Tp __f1, _Tp __f2)
569 { return __gnu_cxx::__capture_isunordered(__f1, __f2); }
571 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
572 #endif
574 #ifndef _GLIBCXX_EXPORT_TEMPLATE
575 # include <bits/cmath.tcc>
576 #endif
578 #endif