Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / include / c++ / 3.4.2 / cmath
blob66866b2cc3a06c9daeab4fd6f30bba5923956ea8
1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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.
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  */
44 #ifndef _GLIBCXX_CMATH
45 #define _GLIBCXX_CMATH 1
47 #pragma GCC system_header
49 #include <bits/c++config.h>
50 #include <bits/cpp_type_traits.h>
52 #include <math.h>
54 // Get rid of those macros defined in <math.h> in lieu of real functions.
55 #undef abs
56 #undef div
57 #undef acos
58 #undef asin
59 #undef atan
60 #undef atan2
61 #undef ceil
62 #undef cos
63 #undef cosh
64 #undef exp
65 #undef fabs
66 #undef floor
67 #undef fmod
68 #undef frexp
69 #undef ldexp
70 #undef log
71 #undef log10
72 #undef modf
73 #undef pow
74 #undef sin
75 #undef sinh
76 #undef sqrt
77 #undef tan
78 #undef tanh
81 namespace std
83   // Forward declaration of a helper function.  This really should be
84   // an `exported' forward declaration.
85   template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
87   inline double
88   abs(double __x)
89   { return __builtin_fabs(__x); }
91   inline float
92   abs(float __x)
93   { return __builtin_fabsf(__x); }
95   inline long double
96   abs(long double __x)
97   { return __builtin_fabsl(__x); }
99   using ::acos;
101   inline float
102   acos(float __x)
103   { return __builtin_acosf(__x); }
105   inline long double
106   acos(long double __x)
107   { return __builtin_acosl(__x); }
109   template<typename _Tp>
110     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
111     acos(_Tp __x)
112     {
113       return __builtin_acos(__x);
114     }
116   using ::asin;
118   inline float
119   asin(float __x)
120   { return __builtin_asinf(__x); }
122   inline long double
123   asin(long double __x)
124   { return __builtin_asinl(__x); }
126   template<typename _Tp>
127     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
128     asin(_Tp __x)
129     { return __builtin_asin(__x); }
131   using ::atan;
133   inline float
134   atan(float __x)
135   { return __builtin_atanf(__x); }
137   inline long double
138   atan(long double __x)
139   { return __builtin_atanl(__x); }
141   template<typename _Tp>
142     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
143     atan(_Tp __x)
144     { return __builtin_atan(__x); }
146   using ::atan2;
148   inline float
149   atan2(float __y, float __x)
150   { return __builtin_atan2f(__y, __x); }
152   inline long double
153   atan2(long double __y, long double __x)
154   { return __builtin_atan2l(__y, __x); }
156   template<typename _Tp, typename _Up>
157     inline typename __enable_if<double, __is_integer<_Tp>::_M_type
158                                         && __is_integer<_Up>::_M_type>::_M_type
159     atan2(_Tp __y, _Up __x)
160     { return __builtin_atan2(__y, __x); }
162   using ::ceil;
164   inline float
165   ceil(float __x)
166   { return __builtin_ceilf(__x); }
168   inline long double
169   ceil(long double __x)
170   { return __builtin_ceill(__x); }
172   template<typename _Tp>
173     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
174     ceil(_Tp __x)
175     { return __builtin_ceil(__x); }
177   using ::cos;
179   inline float
180   cos(float __x)
181   { return __builtin_cosf(__x); }
183   inline long double
184   cos(long double __x)
185   { return __builtin_cosl(__x); }
187   template<typename _Tp>
188     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
189     cos(_Tp __x)
190     { return __builtin_cos(__x); }
192   using ::cosh;
194   inline float
195   cosh(float __x)
196   { return __builtin_coshf(__x); }
198   inline long double
199   cosh(long double __x)
200   { return __builtin_coshl(__x); }
202   template<typename _Tp>
203     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
204     cosh(_Tp __x)
205     { return __builtin_cosh(__x); }
207   using ::exp;
209   inline float
210   exp(float __x)
211   { return __builtin_expf(__x); }
213   inline long double
214   exp(long double __x)
215   { return __builtin_expl(__x); }
217   template<typename _Tp>
218     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
219     exp(_Tp __x)
220     { return __builtin_exp(__x); }
222   using ::fabs;
224   inline float
225   fabs(float __x)
226   { return __builtin_fabsf(__x); }
228   inline long double
229   fabs(long double __x)
230   { return __builtin_fabsl(__x); }
232   template<typename _Tp>
233     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
234     fabs(_Tp __x)
235     { return __builtin_fabs(__x); }
237   using ::floor;
239   inline float
240   floor(float __x)
241   { return __builtin_floorf(__x); }
243   inline long double
244   floor(long double __x)
245   { return __builtin_floorl(__x); }
247   template<typename _Tp>
248     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
249     floor(_Tp __x)
250     { return __builtin_floor(__x); }
252   using ::fmod;
254   inline float
255   fmod(float __x, float __y)
256   { return __builtin_fmodf(__x, __y); }
258   inline long double
259   fmod(long double __x, long double __y)
260   { return __builtin_fmodl(__x, __y); }
262   using ::frexp;
264   inline float
265   frexp(float __x, int* __exp)
266   { return __builtin_frexpf(__x, __exp); }
268   inline long double
269   frexp(long double __x, int* __exp)
270   { return __builtin_frexpl(__x, __exp); }
272   template<typename _Tp>
273     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
274     frexp(_Tp __x, int* __exp)
275     { return __builtin_frexp(__x, __exp); }
277   using ::ldexp;
279   inline float
280   ldexp(float __x, int __exp)
281   { return __builtin_ldexpf(__x, __exp); }
283   inline long double
284   ldexp(long double __x, int __exp)
285   { return __builtin_ldexpl(__x, __exp); }
287   template<typename _Tp>
288   inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
289   ldexp(_Tp __x, int __exp)
290   { return __builtin_ldexp(__x, __exp); }
292   using ::log;
294   inline float
295   log(float __x)
296   { return __builtin_logf(__x); }
298   inline long double
299   log(long double __x)
300   { return __builtin_logl(__x); }
302   template<typename _Tp>
303     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
304     log(_Tp __x)
305     { return __builtin_log(__x); }
307   using ::log10;
309   inline float
310   log10(float __x)
311   { return __builtin_log10f(__x); }
313   inline long double
314   log10(long double __x)
315   { return __builtin_log10l(__x); }
317   template<typename _Tp>
318     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
319     log10(_Tp __x)
320     { return __builtin_log10(__x); }
322   using ::modf;
324   inline float
325   modf(float __x, float* __iptr)
326   { return __builtin_modff(__x, __iptr); }
328   inline long double
329   modf(long double __x, long double* __iptr)
330   { return __builtin_modfl(__x, __iptr); }
332   template<typename _Tp>
333     inline _Tp
334     __pow_helper(_Tp __x, int __n)
335     {
336       return __n < 0
337         ? _Tp(1)/__cmath_power(__x, -__n)
338         : __cmath_power(__x, __n);
339     }
341   using ::pow;
343   inline float
344   pow(float __x, float __y)
345   { return __builtin_powf(__x, __y); }
347   inline long double
348   pow(long double __x, long double __y)
349   { return __builtin_powl(__x, __y); }
351   inline double
352   pow(double __x, int __i)
353   { return __pow_helper(__x, __i); }
355   inline float
356   pow(float __x, int __n)
357   { return __pow_helper(__x, __n); }
359   inline long double
360   pow(long double __x, int __n)
361   { return __pow_helper(__x, __n); }
363   using ::sin;
365   inline float
366   sin(float __x)
367   { return __builtin_sinf(__x); }
369   inline long double
370   sin(long double __x)
371   { return __builtin_sinl(__x); }
373   template<typename _Tp>
374     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
375     sin(_Tp __x)
376     { return __builtin_sin(__x); }
378   using ::sinh;
380   inline float
381   sinh(float __x)
382   { return __builtin_sinhf(__x); }
384   inline long double
385   sinh(long double __x)
386   { return __builtin_sinhl(__x); }
388   template<typename _Tp>
389     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
390     sinh(_Tp __x)
391     { return __builtin_sinh(__x); }
393   using ::sqrt;
395   inline float
396   sqrt(float __x)
397   { return __builtin_sqrtf(__x); }
399   inline long double
400   sqrt(long double __x)
401   { return __builtin_sqrtl(__x); }
403   template<typename _Tp>
404     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
405     sqrt(_Tp __x)
406     { return __builtin_sqrt(__x); }
408   using ::tan;
410   inline float
411   tan(float __x)
412   { return __builtin_tanf(__x); }
414   inline long double
415   tan(long double __x)
416   { return __builtin_tanl(__x); }
418   template<typename _Tp>
419     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
420     tan(_Tp __x)
421     { return __builtin_tan(__x); }
423   using ::tanh;
425   inline float
426   tanh(float __x)
427   { return __builtin_tanhf(__x); }
429   inline long double
430   tanh(long double __x)
431   { return __builtin_tanhl(__x); }
433   template<typename _Tp>
434     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
435     tanh(_Tp __x)
436     { return __builtin_tanh(__x); }
439 #if _GLIBCXX_USE_C99_MATH
440 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
441 // These are possible macros imported from C99-land. For strict
442 // conformance, remove possible C99-injected names from the global
443 // namespace, and sequester them in the __gnu_cxx extension namespace.
444 namespace __gnu_cxx
446   template<typename _Tp>
447     int
448     __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
450   template<typename _Tp>
451     int
452     __capture_isfinite(_Tp __f) { return isfinite(__f); }
454   template<typename _Tp>
455     int
456     __capture_isinf(_Tp __f) { return isinf(__f); }
458   template<typename _Tp>
459     int
460     __capture_isnan(_Tp __f) { return isnan(__f); }
462   template<typename _Tp>
463     int
464     __capture_isnormal(_Tp __f) { return isnormal(__f); }
466   template<typename _Tp>
467     int
468     __capture_signbit(_Tp __f) { return signbit(__f); }
470   template<typename _Tp>
471     int
472     __capture_isgreater(_Tp __f1, _Tp __f2)
473     { return isgreater(__f1, __f2); }
475   template<typename _Tp>
476      int
477      __capture_isgreaterequal(_Tp __f1, _Tp __f2)
478      { return isgreaterequal(__f1, __f2); }
480   template<typename _Tp>
481      int
482      __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
484   template<typename _Tp>
485      int
486      __capture_islessequal(_Tp __f1, _Tp __f2)
487      { return islessequal(__f1, __f2); }
489   template<typename _Tp>
490      int
491      __capture_islessgreater(_Tp __f1, _Tp __f2)
492      { return islessgreater(__f1, __f2); }
494   template<typename _Tp>
495      int
496      __capture_isunordered(_Tp __f1, _Tp __f2)
497      { return isunordered(__f1, __f2); }
500 // Only undefine the C99 FP macros, if actually captured for namespace movement
501 #undef fpclassify
502 #undef isfinite
503 #undef isinf
504 #undef isnan
505 #undef isnormal
506 #undef signbit
507 #undef isgreater
508 #undef isgreaterequal
509 #undef isless
510 #undef islessequal
511 #undef islessgreater
512 #undef isunordered
513 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
514 #endif
516 #if _GLIBCXX_USE_C99_MATH
517 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
518 namespace __gnu_cxx
520   template<typename _Tp>
521     int
522     fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
524   template<typename _Tp>
525     int
526     isfinite(_Tp __f) { return __capture_isfinite(__f); }
528   template<typename _Tp>
529     int
530     isinf(_Tp __f) { return __capture_isinf(__f); }
532   template<typename _Tp>
533     int
534     isnan(_Tp __f) { return __capture_isnan(__f); }
536   template<typename _Tp>
537     int
538     isnormal(_Tp __f) { return __capture_isnormal(__f); }
540   template<typename _Tp>
541     int
542     signbit(_Tp __f) { return __capture_signbit(__f); }
544   template<typename _Tp>
545     int
546     isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
548   template<typename _Tp>
549     int
550     isgreaterequal(_Tp __f1, _Tp __f2)
551     { return __capture_isgreaterequal(__f1, __f2); }
553   template<typename _Tp>
554     int
555     isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
557   template<typename _Tp>
558     int
559     islessequal(_Tp __f1, _Tp __f2)
560     { return __capture_islessequal(__f1, __f2); }
562   template<typename _Tp>
563     int
564     islessgreater(_Tp __f1, _Tp __f2)
565     { return __capture_islessgreater(__f1, __f2); }
567   template<typename _Tp>
568     int
569     isunordered(_Tp __f1, _Tp __f2)
570     { return __capture_isunordered(__f1, __f2); }
573 namespace std
575   using __gnu_cxx::fpclassify;
576   using __gnu_cxx::isfinite;
577   using __gnu_cxx::isinf;
578   using __gnu_cxx::isnan;
579   using __gnu_cxx::isnormal;
580   using __gnu_cxx::signbit;
581   using __gnu_cxx::isgreater;
582   using __gnu_cxx::isgreaterequal;
583   using __gnu_cxx::isless;
584   using __gnu_cxx::islessequal;
585   using __gnu_cxx::islessgreater;
586   using __gnu_cxx::isunordered;
588 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
589 #endif
591 #ifndef _GLIBCXX_EXPORT_TEMPLATE
592 # include <bits/cmath.tcc>
593 #endif
595 #endif