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