Merge branch 'vendor/GCC44' into gcc441
[dragonfly.git] / contrib / gcc-4.4 / gcc / ginclude / tgmath.h
1 /* Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
2    Contributed by Apple, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 <http://www.gnu.org/licenses/>.  */
24
25 /*
26  * ISO C Standard:  7.22  Type-generic math <tgmath.h>
27  */
28
29 #ifndef _TGMATH_H
30 #define _TGMATH_H
31
32 #include <math.h>
33
34 #ifndef __cplusplus
35 #include <complex.h>
36
37 /* Naming convention: generic macros are defining using
38    __TGMATH_CPLX*, __TGMATH_REAL*, and __TGMATH_CPLX_ONLY.  _CPLX
39    means the generic argument(s) may be real or complex, _REAL means
40    real only, _CPLX means complex only.  If there is no suffix, we are
41    defining a function of one generic argument.  If the suffix is _n
42    it is a function of n generic arguments.  If the suffix is _m_n it
43    is a function of n arguments, the first m of which are generic.  We
44    only define these macros for values of n and/or m that are needed. */
45
46 /* The general rules for generic macros are given in 7.22 paragraphs 1 and 2.
47    If any generic parameter is complex, we use a complex version.  Otherwise
48    we use a real version.  If the real part of any generic parameter is long
49    double, we use the long double version.  Otherwise if the real part of any
50    generic parameter is double or of integer type, we use the double version.
51    Otherwise we use the float version. */
52
53 #define __tg_cplx(expr) \
54   __builtin_classify_type(expr) == 9
55
56 #define __tg_ldbl(expr) \
57   __builtin_types_compatible_p(__typeof__(expr), long double)
58
59 #define __tg_dbl(expr)                                       \
60   (__builtin_types_compatible_p(__typeof__(expr), double)    \
61    || __builtin_classify_type(expr) == 1)
62
63 #define __tg_choose(x,f,d,l)                                  \
64   __builtin_choose_expr(__tg_ldbl(x), l,                      \
65                         __builtin_choose_expr(__tg_dbl(x), d, \
66                                               f))
67
68 #define __tg_choose_2(x,y,f,d,l)                                             \
69   __builtin_choose_expr(__tg_ldbl(x) || __tg_ldbl(y), l,                     \
70                         __builtin_choose_expr(__tg_dbl(x) || __tg_dbl(y), d, \
71                                               f))
72
73 #define __tg_choose_3(x,y,z,f,d,l)                                        \
74    __builtin_choose_expr(__tg_ldbl(x) || __tg_ldbl(y) || __tg_ldbl(z), l, \
75                         __builtin_choose_expr(__tg_dbl(x) || __tg_dbl(y)  \
76                                               || __tg_dbl(z), d,          \
77                                               f))
78
79 #define __TGMATH_CPLX(z,R,C)                                                  \
80   __builtin_choose_expr (__tg_cplx(z),                                        \
81                          __tg_choose (__real__(z), C##f(z), (C)(z), C##l(z)), \
82                          __tg_choose (z, R##f(z), (R)(z), R##l(z)))
83
84 #define __TGMATH_CPLX_2(z1,z2,R,C)                                             \
85   __builtin_choose_expr (__tg_cplx(z1) || __tg_cplx(z2),                       \
86                          __tg_choose_2 (__real__(z1), __real__(z2),            \
87                                         C##f(z1,z2), (C)(z1,z2), C##l(z1,z2)), \
88                          __tg_choose_2 (z1, z2,                                \
89                                         R##f(z1,z2), (R)(z1,z2), R##l(z1,z2)))
90
91 #define __TGMATH_REAL(x,R) \
92   __tg_choose (x, R##f(x), (R)(x), R##l(x))
93 #define __TGMATH_REAL_2(x,y,R) \
94   __tg_choose_2 (x, y, R##f(x,y), (R)(x,y), R##l(x,y))
95 #define __TGMATH_REAL_3(x,y,z,R) \
96   __tg_choose_3 (x, y, z, R##f(x,y,z), (R)(x,y,z), R##l(x,y,z))
97 #define __TGMATH_REAL_1_2(x,y,R) \
98   __tg_choose (x, R##f(x,y), (R)(x,y), R##l(x,y))
99 #define __TGMATH_REAL_2_3(x,y,z,R) \
100   __tg_choose_2 (x, y, R##f(x,y,z), (R)(x,y,z), R##l(x,y,z))
101 #define __TGMATH_CPLX_ONLY(z,C) \
102   __tg_choose (__real__(z), C##f(z), (C)(z), C##l(z))
103
104 /* Functions defined in both <math.h> and <complex.h> (7.22p4) */
105 #define acos(z)          __TGMATH_CPLX(z, acos, cacos)
106 #define asin(z)          __TGMATH_CPLX(z, asin, casin)
107 #define atan(z)          __TGMATH_CPLX(z, atan, catan)
108 #define acosh(z)         __TGMATH_CPLX(z, acosh, cacosh)
109 #define asinh(z)         __TGMATH_CPLX(z, asinh, casinh)
110 #define atanh(z)         __TGMATH_CPLX(z, atanh, catanh)
111 #define cos(z)           __TGMATH_CPLX(z, cos, ccos)
112 #define sin(z)           __TGMATH_CPLX(z, sin, csin)
113 #define tan(z)           __TGMATH_CPLX(z, tan, ctan)
114 #define cosh(z)          __TGMATH_CPLX(z, cosh, ccosh)
115 #define sinh(z)          __TGMATH_CPLX(z, sinh, csinh)
116 #define tanh(z)          __TGMATH_CPLX(z, tanh, ctanh)
117 #define exp(z)           __TGMATH_CPLX(z, exp, cexp)
118 #define log(z)           __TGMATH_CPLX(z, log, clog)
119 #define pow(z1,z2)       __TGMATH_CPLX_2(z1, z2, pow, cpow)
120 #define sqrt(z)          __TGMATH_CPLX(z, sqrt, csqrt)
121 #define fabs(z)          __TGMATH_CPLX(z, fabs, cabs)
122
123 /* Functions defined in <math.h> only (7.22p5) */
124 #define atan2(x,y)       __TGMATH_REAL_2(x, y, atan2)
125 #define cbrt(x)          __TGMATH_REAL(x, cbrt)
126 #define ceil(x)          __TGMATH_REAL(x, ceil)
127 #define copysign(x,y)    __TGMATH_REAL_2(x, y, copysign)
128 #define erf(x)           __TGMATH_REAL(x, erf)
129 #define erfc(x)          __TGMATH_REAL(x, erfc)
130 #define exp2(x)          __TGMATH_REAL(x, exp2)
131 #define expm1(x)         __TGMATH_REAL(x, expm1)
132 #define fdim(x,y)        __TGMATH_REAL_2(x, y, fdim)
133 #define floor(x)         __TGMATH_REAL(x, floor)
134 #define fma(x,y,z)       __TGMATH_REAL_3(x, y, z, fma)
135 #define fmax(x,y)        __TGMATH_REAL_2(x, y, fmax)
136 #define fmin(x,y)        __TGMATH_REAL_2(x, y, fmin)
137 #define fmod(x,y)        __TGMATH_REAL_2(x, y, fmod)
138 #define frexp(x,y)       __TGMATH_REAL_1_2(x, y, frexp)
139 #define hypot(x,y)       __TGMATH_REAL_2(x, y, hypot)
140 #define ilogb(x)         __TGMATH_REAL(x, ilogb)
141 #define ldexp(x,y)       __TGMATH_REAL_1_2(x, y, ldexp)
142 #define lgamma(x)        __TGMATH_REAL(x, lgamma)
143 #define llrint(x)        __TGMATH_REAL(x, llrint)
144 #define llround(x)       __TGMATH_REAL(x, llround)
145 #define log10(x)         __TGMATH_REAL(x, log10)
146 #define log1p(x)         __TGMATH_REAL(x, log1p)
147 #define log2(x)          __TGMATH_REAL(x, log2)
148 #define logb(x)          __TGMATH_REAL(x, logb)
149 #define lrint(x)         __TGMATH_REAL(x, lrint)
150 #define lround(x)        __TGMATH_REAL(x, lround)
151 #define nearbyint(x)     __TGMATH_REAL(x, nearbyint)
152 #define nextafter(x,y)   __TGMATH_REAL_2(x, y, nextafter)
153 #define nexttoward(x,y)  __TGMATH_REAL_1_2(x, y, nexttoward)
154 #define remainder(x,y)   __TGMATH_REAL_2(x, y, remainder)
155 #define remquo(x,y,z)    __TGMATH_REAL_2_3(x, y, z, remquo)
156 #define rint(x)          __TGMATH_REAL(x, rint)
157 #define round(x)         __TGMATH_REAL(x, round)
158 #define scalbn(x,y)      __TGMATH_REAL_1_2(x, y, scalbn)
159 #define scalbln(x,y)     __TGMATH_REAL_1_2(x, y, scalbln)
160 #define tgamma(x)        __TGMATH_REAL(x, tgamma)
161 #define trunc(x)         __TGMATH_REAL(x, trunc)
162
163 /* Functions defined in <complex.h> only (7.22p6) */
164 #define carg(z)          __TGMATH_CPLX_ONLY(z, carg)
165 #define cimag(z)         __TGMATH_CPLX_ONLY(z, cimag)
166 #define conj(z)          __TGMATH_CPLX_ONLY(z, conj)
167 #define cproj(z)         __TGMATH_CPLX_ONLY(z, cproj)
168 #define creal(z)         __TGMATH_CPLX_ONLY(z, creal)
169
170 #endif /* __cplusplus */
171 #endif /* _TGMATH_H */