]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/c_global/cmath
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / c_global / 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
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 <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.
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     }
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>
137     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
138                                            double>::__type
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>
153     inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
154                                            double>::__type
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>
169     inline
170     typename __gnu_cxx::__promote_2<
171     typename __gnu_cxx::__enable_if<__traitand<__is_arithmetic<_Tp>,
172                                                __is_arithmetic<_Up> >::__value,
173                                     _Tp>::__type, _Up>::__type
174     atan2(_Tp __y, _Up __x)
175     {
176       typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
177       return atan2(__type(__y), __type(__x));
178     }
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
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
370   // DR 550.
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
383   template<typename _Tp, typename _Up>
384     inline
385     typename __gnu_cxx::__promote_2<
386     typename __gnu_cxx::__enable_if<__traitand<__is_arithmetic<_Tp>,
387                                                __is_arithmetic<_Up> >::__value,
388                                     _Tp>::__type, _Up>::__type
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
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
483 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
484
485   template<typename _Tp>
486     inline int
487     __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
488
489 _GLIBCXX_END_NAMESPACE
490
491 // Only undefine the C99 FP macros, if actually captured for namespace movement
492 #undef fpclassify
493 #undef isfinite
494 #undef isinf
495 #undef isnan
496 #undef isnormal
497 #undef signbit
498 #undef isgreater
499 #undef isgreaterequal
500 #undef isless
501 #undef islessequal
502 #undef islessgreater
503 #undef isunordered
504
505 _GLIBCXX_BEGIN_NAMESPACE(std)
506
507   template<typename _Tp>
508     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
509                                            int>::__type
510     fpclassify(_Tp __f)
511     {
512       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
513       return ::__gnu_cxx::__capture_fpclassify(__type(__f));
514     }
515
516   template<typename _Tp>
517     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
518                                            int>::__type
519     isfinite(_Tp __f)
520     {
521       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
522       return __builtin_isfinite(__type(__f));
523     }
524
525   template<typename _Tp>
526     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
527                                            int>::__type
528     isinf(_Tp __f)
529     {
530       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
531       return __builtin_isinf(__type(__f));
532     }
533
534   template<typename _Tp>
535     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
536                                            int>::__type
537     isnan(_Tp __f)
538     {
539       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
540       return __builtin_isnan(__type(__f));
541     }
542
543   template<typename _Tp>
544     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
545                                            int>::__type
546     isnormal(_Tp __f)
547     {
548       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
549       return __builtin_isnormal(__type(__f));
550     }
551
552   template<typename _Tp>
553     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
554                                            int>::__type
555     signbit(_Tp __f)
556     {
557       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
558       return __builtin_signbit(__type(__f));
559     }
560
561   template<typename _Tp>
562     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
563                                            int>::__type
564     isgreater(_Tp __f1, _Tp __f2)
565     {
566       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
567       return __builtin_isgreater(__type(__f1), __type(__f2));
568     }
569
570   template<typename _Tp>
571     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
572                                            int>::__type
573     isgreaterequal(_Tp __f1, _Tp __f2)
574     {
575       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
576       return __builtin_isgreaterequal(__type(__f1), __type(__f2));
577     }
578
579   template<typename _Tp>
580     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
581                                            int>::__type
582     isless(_Tp __f1, _Tp __f2)
583     {
584       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
585       return __builtin_isless(__type(__f1), __type(__f2));
586     }
587
588   template<typename _Tp>
589     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
590                                            int>::__type
591     islessequal(_Tp __f1, _Tp __f2)
592     {
593       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
594       return __builtin_islessequal(__type(__f1), __type(__f2));
595     }
596
597   template<typename _Tp>
598     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
599                                            int>::__type
600     islessgreater(_Tp __f1, _Tp __f2)
601     {
602       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
603       return __builtin_islessgreater(__type(__f1), __type(__f2));
604     }
605
606   template<typename _Tp>
607     inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
608                                            int>::__type
609     isunordered(_Tp __f1, _Tp __f2)
610     {
611       typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
612       return __builtin_isunordered(__type(__f1), __type(__f2));
613     }
614
615 _GLIBCXX_END_NAMESPACE
616
617 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
618 #endif
619
620 #ifndef _GLIBCXX_EXPORT_TEMPLATE
621 # include <bits/cmath.tcc>
622 #endif
623
624 #ifdef __GXX_EXPERIMENTAL_CXX0X__
625 #  if defined(_GLIBCXX_INCLUDE_AS_TR1)
626 #    error C++0x header cannot be included from TR1 header
627 #  endif
628 #  if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
629 #    include <tr1_impl/cmath>
630 #  else
631 #    define _GLIBCXX_INCLUDE_AS_CXX0X
632 #    define _GLIBCXX_BEGIN_NAMESPACE_TR1
633 #    define _GLIBCXX_END_NAMESPACE_TR1
634 #    define _GLIBCXX_TR1
635 #    include <tr1_impl/cmath>
636 #    undef _GLIBCXX_TR1
637 #    undef _GLIBCXX_END_NAMESPACE_TR1
638 #    undef _GLIBCXX_BEGIN_NAMESPACE_TR1
639 #    undef _GLIBCXX_INCLUDE_AS_CXX0X
640 #  endif
641 #endif
642
643 #endif