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