]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1997-2019 Free Software Foundation, Inc. |
dfd2257a UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
dfd2257a UD |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
dfd2257a | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
dfd2257a UD |
17 | |
18 | /* | |
63ae7b63 | 19 | * ISO C99 Standard: 7.22 Type-generic math <tgmath.h> |
dfd2257a UD |
20 | */ |
21 | ||
22 | #ifndef _TGMATH_H | |
23 | #define _TGMATH_H 1 | |
24 | ||
614d15f9 JM |
25 | #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION |
26 | #include <bits/libc-header-start.h> | |
27 | ||
dfd2257a | 28 | /* Include the needed headers. */ |
614d15f9 | 29 | #include <bits/floatn.h> |
dfd2257a UD |
30 | #include <math.h> |
31 | #include <complex.h> | |
32 | ||
33 | ||
be3a79a3 JM |
34 | /* There are two variant implementations of type-generic macros in |
35 | this file: one for GCC 8 and later, using __builtin_tgmath and | |
36 | where each macro expands each of its arguments only once, and one | |
37 | for older GCC, using other compiler extensions but with macros | |
38 | expanding their arguments many times (so resulting in exponential | |
39 | blowup of the size of expansions when calls to such macros are | |
40 | nested inside arguments to such macros). */ | |
41 | ||
42 | #define __HAVE_BUILTIN_TGMATH __GNUC_PREREQ (8, 0) | |
dfd2257a | 43 | |
4360eafd | 44 | #if __GNUC_PREREQ (2, 7) |
dfd2257a | 45 | |
be3a79a3 | 46 | # if __HAVE_BUILTIN_TGMATH |
0d3fee40 | 47 | |
be3a79a3 JM |
48 | # if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
49 | # define __TG_F16_ARG(X) X ## f16, | |
50 | # else | |
51 | # define __TG_F16_ARG(X) | |
52 | # endif | |
53 | # if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
54 | # define __TG_F32_ARG(X) X ## f32, | |
55 | # else | |
56 | # define __TG_F32_ARG(X) | |
57 | # endif | |
58 | # if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
59 | # define __TG_F64_ARG(X) X ## f64, | |
60 | # else | |
61 | # define __TG_F64_ARG(X) | |
62 | # endif | |
63 | # if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
64 | # define __TG_F128_ARG(X) X ## f128, | |
65 | # else | |
66 | # define __TG_F128_ARG(X) | |
67 | # endif | |
68 | # if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
69 | # define __TG_F32X_ARG(X) X ## f32x, | |
70 | # else | |
71 | # define __TG_F32X_ARG(X) | |
72 | # endif | |
73 | # if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
74 | # define __TG_F64X_ARG(X) X ## f64x, | |
75 | # else | |
76 | # define __TG_F64X_ARG(X) | |
77 | # endif | |
78 | # if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
79 | # define __TG_F128X_ARG(X) X ## f128x, | |
80 | # else | |
81 | # define __TG_F128X_ARG(X) | |
82 | # endif | |
83 | ||
84 | # define __TGMATH_FUNCS(X) X ## f, X, X ## l, \ | |
85 | __TG_F16_ARG (X) __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \ | |
86 | __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X) | |
87 | # define __TGMATH_RCFUNCS(F, C) __TGMATH_FUNCS (F) __TGMATH_FUNCS (C) | |
88 | # define __TGMATH_1(F, X) __builtin_tgmath (__TGMATH_FUNCS (F) (X)) | |
89 | # define __TGMATH_2(F, X, Y) __builtin_tgmath (__TGMATH_FUNCS (F) (X), (Y)) | |
90 | # define __TGMATH_2STD(F, X, Y) __builtin_tgmath (F ## f, F, F ## l, (X), (Y)) | |
91 | # define __TGMATH_3(F, X, Y, Z) __builtin_tgmath (__TGMATH_FUNCS (F) \ | |
92 | (X), (Y), (Z)) | |
93 | # define __TGMATH_1C(F, C, X) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) (X)) | |
94 | # define __TGMATH_2C(F, C, X, Y) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) \ | |
95 | (X), (Y)) | |
96 | ||
97 | # else /* !__HAVE_BUILTIN_TGMATH. */ | |
98 | ||
99 | # ifdef __NO_LONG_DOUBLE_MATH | |
100 | # define __tgml(fct) fct | |
101 | # else | |
102 | # define __tgml(fct) fct ## l | |
103 | # endif | |
925e31d9 | 104 | |
d9bef9c0 JM |
105 | /* __floating_type expands to 1 if TYPE is a floating type (including |
106 | complex floating types), 0 if TYPE is an integer type (including | |
107 | complex integer types). __real_integer_type expands to 1 if TYPE | |
108 | is a real integer type. __complex_integer_type expands to 1 if | |
109 | TYPE is a complex integer type. All these macros expand to integer | |
110 | constant expressions. All these macros can assume their argument | |
111 | has an arithmetic type (not vector, decimal floating-point or | |
112 | fixed-point), valid to pass to tgmath.h macros. */ | |
be3a79a3 | 113 | # if __GNUC_PREREQ (3, 1) |
d9bef9c0 JM |
114 | /* __builtin_classify_type expands to an integer constant expression |
115 | in GCC 3.1 and later. Default conversions applied to the argument | |
116 | of __builtin_classify_type mean it always returns 1 for real | |
117 | integer types rather than ever returning different values for | |
118 | character, boolean or enumerated types. */ | |
be3a79a3 | 119 | # define __floating_type(type) \ |
d9bef9c0 | 120 | (__builtin_classify_type (__real__ ((type) 0)) == 8) |
be3a79a3 | 121 | # define __real_integer_type(type) \ |
d9bef9c0 | 122 | (__builtin_classify_type ((type) 0) == 1) |
be3a79a3 | 123 | # define __complex_integer_type(type) \ |
d9bef9c0 JM |
124 | (__builtin_classify_type ((type) 0) == 9 \ |
125 | && __builtin_classify_type (__real__ ((type) 0)) == 1) | |
be3a79a3 | 126 | # else |
d9bef9c0 JM |
127 | /* GCC versions predating __builtin_classify_type are also looser on |
128 | what counts as an integer constant expression. */ | |
be3a79a3 JM |
129 | # define __floating_type(type) (((type) 1.25) != 1) |
130 | # define __real_integer_type(type) (((type) (1.25 + _Complex_I)) == 1) | |
131 | # define __complex_integer_type(type) \ | |
d9bef9c0 | 132 | (((type) (1.25 + _Complex_I)) == (1 + _Complex_I)) |
be3a79a3 | 133 | # endif |
925e31d9 | 134 | |
d9bef9c0 | 135 | /* Whether an expression (of arithmetic type) has a real type. */ |
be3a79a3 | 136 | # define __expr_is_real(E) (__builtin_classify_type (E) != 9) |
d9bef9c0 JM |
137 | |
138 | /* The tgmath real type for T, where E is 0 if T is an integer type | |
139 | and 1 for a floating type. If T has a complex type, it is | |
140 | unspecified whether the return type is real or complex (but it has | |
141 | the correct corresponding real type). */ | |
be3a79a3 | 142 | # define __tgmath_real_type_sub(T, E) \ |
1c298d08 UD |
143 | __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \ |
144 | : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0)) | |
925e31d9 UD |
145 | |
146 | /* The tgmath real type of EXPR. */ | |
be3a79a3 | 147 | # define __tgmath_real_type(expr) \ |
2fee621d JM |
148 | __tgmath_real_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \ |
149 | __floating_type (__typeof__ (+(expr)))) | |
925e31d9 | 150 | |
d9bef9c0 JM |
151 | /* The tgmath complex type for T, where E1 is 1 if T has a floating |
152 | type and 0 otherwise, E2 is 1 if T has a real integer type and 0 | |
153 | otherwise, and E3 is 1 if T has a complex type and 0 otherwise. */ | |
be3a79a3 | 154 | # define __tgmath_complex_type_sub(T, E1, E2, E3) \ |
d9bef9c0 JM |
155 | __typeof__ (*(0 \ |
156 | ? (__typeof__ (0 ? (T *) 0 : (void *) (!(E1)))) 0 \ | |
157 | : (__typeof__ (0 \ | |
158 | ? (__typeof__ (0 \ | |
159 | ? (double *) 0 \ | |
160 | : (void *) (!(E2)))) 0 \ | |
161 | : (__typeof__ (0 \ | |
162 | ? (_Complex double *) 0 \ | |
163 | : (void *) (!(E3)))) 0)) 0)) | |
164 | ||
165 | /* The tgmath complex type of EXPR. */ | |
be3a79a3 | 166 | # define __tgmath_complex_type(expr) \ |
d9bef9c0 JM |
167 | __tgmath_complex_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \ |
168 | __floating_type (__typeof__ (+(expr))), \ | |
169 | __real_integer_type (__typeof__ (+(expr))), \ | |
170 | __complex_integer_type (__typeof__ (+(expr)))) | |
171 | ||
be3a79a3 | 172 | # if (__HAVE_DISTINCT_FLOAT16 \ |
86ec4865 JM |
173 | || __HAVE_DISTINCT_FLOAT32 \ |
174 | || __HAVE_DISTINCT_FLOAT64 \ | |
175 | || __HAVE_DISTINCT_FLOAT32X \ | |
176 | || __HAVE_DISTINCT_FLOAT64X \ | |
177 | || __HAVE_DISTINCT_FLOAT128X) | |
be3a79a3 JM |
178 | # error "Unsupported _FloatN or _FloatNx types for <tgmath.h>." |
179 | # endif | |
86ec4865 | 180 | |
614d15f9 JM |
181 | /* Expand to text that checks if ARG_COMB has type _Float128, and if |
182 | so calls the appropriately suffixed FCT (which may include a cast), | |
183 | or FCT and CFCT for complex functions, with arguments ARG_CALL. */ | |
be3a79a3 JM |
184 | # if __HAVE_DISTINCT_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
185 | # if (!__HAVE_FLOAT64X \ | |
86ec4865 JM |
186 | || __HAVE_FLOAT64X_LONG_DOUBLE \ |
187 | || !__HAVE_FLOATN_NOT_TYPEDEF) | |
be3a79a3 | 188 | # define __TGMATH_F128(arg_comb, fct, arg_call) \ |
2fee621d | 189 | __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \ |
614d15f9 | 190 | ? fct ## f128 arg_call : |
be3a79a3 | 191 | # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \ |
2fee621d | 192 | __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \ |
d9bef9c0 | 193 | ? (__expr_is_real (arg_comb) \ |
614d15f9 JM |
194 | ? fct ## f128 arg_call \ |
195 | : cfct ## f128 arg_call) : | |
be3a79a3 | 196 | # else |
86ec4865 JM |
197 | /* _Float64x is a distinct type at the C language level, which must be |
198 | handled like _Float128. */ | |
be3a79a3 | 199 | # define __TGMATH_F128(arg_comb, fct, arg_call) \ |
86ec4865 JM |
200 | (__builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \ |
201 | || __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float64x)) \ | |
202 | ? fct ## f128 arg_call : | |
be3a79a3 | 203 | # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \ |
86ec4865 JM |
204 | (__builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \ |
205 | || __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), \ | |
206 | _Float64x)) \ | |
207 | ? (__expr_is_real (arg_comb) \ | |
208 | ? fct ## f128 arg_call \ | |
209 | : cfct ## f128 arg_call) : | |
be3a79a3 JM |
210 | # endif |
211 | # else | |
212 | # define __TGMATH_F128(arg_comb, fct, arg_call) /* Nothing. */ | |
213 | # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) /* Nothing. */ | |
86ec4865 | 214 | # endif |
614d15f9 | 215 | |
be3a79a3 | 216 | # endif /* !__HAVE_BUILTIN_TGMATH. */ |
925e31d9 | 217 | |
dfd2257a UD |
218 | /* We have two kinds of generic macros: to support functions which are |
219 | only defined on real valued parameters and those which are defined | |
220 | for complex functions as well. */ | |
be3a79a3 JM |
221 | # if __HAVE_BUILTIN_TGMATH |
222 | ||
223 | # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val)) | |
224 | # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val)) | |
225 | # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \ | |
226 | __TGMATH_2 (Fct, (Val1), (Val2)) | |
227 | # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \ | |
228 | __TGMATH_2STD (Fct, (Val1), (Val2)) | |
229 | # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \ | |
230 | __TGMATH_2 (Fct, (Val1), (Val2)) | |
231 | # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \ | |
232 | __TGMATH_2STD (Fct, (Val1), (Val2)) | |
233 | # define __TGMATH_BINARY_REAL_RET_ONLY(Val1, Val2, Fct) \ | |
234 | __TGMATH_2 (Fct, (Val1), (Val2)) | |
235 | # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \ | |
236 | __TGMATH_3 (Fct, (Val1), (Val2), (Val3)) | |
237 | # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \ | |
238 | __TGMATH_3 (Fct, (Val1), (Val2), (Val3)) | |
239 | # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \ | |
240 | __TGMATH_3 (Fct, (Val1), (Val2), (Val3)) | |
241 | # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \ | |
242 | __TGMATH_1C (Fct, Cfct, (Val)) | |
243 | # define __TGMATH_UNARY_IMAG(Val, Cfct) __TGMATH_1 (Cfct, (Val)) | |
244 | # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \ | |
245 | __TGMATH_1C (Fct, Cfct, (Val)) | |
246 | # define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \ | |
247 | __TGMATH_1 (Cfct, (Val)) | |
248 | # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \ | |
249 | __TGMATH_2C (Fct, Cfct, (Val1), (Val2)) | |
250 | ||
251 | # else /* !__HAVE_BUILTIN_TGMATH. */ | |
252 | ||
253 | # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \ | |
2fee621d | 254 | (__extension__ ((sizeof (+(Val)) == sizeof (double) \ |
1c298d08 UD |
255 | || __builtin_classify_type (Val) != 8) \ |
256 | ? (__tgmath_real_type (Val)) Fct (Val) \ | |
2fee621d | 257 | : (sizeof (+(Val)) == sizeof (float)) \ |
1c298d08 | 258 | ? (__tgmath_real_type (Val)) Fct##f (Val) \ |
614d15f9 JM |
259 | : __TGMATH_F128 ((Val), (__tgmath_real_type (Val)) Fct, \ |
260 | (Val)) \ | |
261 | (__tgmath_real_type (Val)) __tgml(Fct) (Val))) | |
71502ebe | 262 | |
be3a79a3 | 263 | # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \ |
2fee621d | 264 | (__extension__ ((sizeof (+(Val)) == sizeof (double) \ |
1c298d08 | 265 | || __builtin_classify_type (Val) != 8) \ |
cfa44345 | 266 | ? Fct (Val) \ |
2fee621d | 267 | : (sizeof (+(Val)) == sizeof (float)) \ |
cfa44345 | 268 | ? Fct##f (Val) \ |
614d15f9 JM |
269 | : __TGMATH_F128 ((Val), Fct, (Val)) \ |
270 | __tgml(Fct) (Val))) | |
dfd2257a | 271 | |
be3a79a3 | 272 | # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \ |
2fee621d | 273 | (__extension__ ((sizeof (+(Val1)) == sizeof (double) \ |
614d15f9 JM |
274 | || __builtin_classify_type (Val1) != 8) \ |
275 | ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \ | |
2fee621d | 276 | : (sizeof (+(Val1)) == sizeof (float)) \ |
614d15f9 JM |
277 | ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \ |
278 | : __TGMATH_F128 ((Val1), (__tgmath_real_type (Val1)) Fct, \ | |
279 | (Val1, Val2)) \ | |
280 | (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2))) | |
281 | ||
be3a79a3 | 282 | # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \ |
2fee621d | 283 | (__extension__ ((sizeof (+(Val1)) == sizeof (double) \ |
1c298d08 UD |
284 | || __builtin_classify_type (Val1) != 8) \ |
285 | ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \ | |
2fee621d | 286 | : (sizeof (+(Val1)) == sizeof (float)) \ |
1c298d08 UD |
287 | ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \ |
288 | : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2))) | |
dfd2257a | 289 | |
be3a79a3 | 290 | # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \ |
42df8d59 | 291 | (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \ |
1c298d08 | 292 | && __builtin_classify_type ((Val1) + (Val2)) == 8) \ |
614d15f9 JM |
293 | ? __TGMATH_F128 ((Val1) + (Val2), \ |
294 | (__typeof \ | |
295 | ((__tgmath_real_type (Val1)) 0 \ | |
296 | + (__tgmath_real_type (Val2)) 0)) Fct, \ | |
297 | (Val1, Val2)) \ | |
298 | (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
299 | + (__tgmath_real_type (Val2)) 0)) \ | |
300 | __tgml(Fct) (Val1, Val2) \ | |
2fee621d JM |
301 | : (sizeof (+(Val1)) == sizeof (double) \ |
302 | || sizeof (+(Val2)) == sizeof (double) \ | |
614d15f9 JM |
303 | || __builtin_classify_type (Val1) != 8 \ |
304 | || __builtin_classify_type (Val2) != 8) \ | |
1c298d08 UD |
305 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ |
306 | + (__tgmath_real_type (Val2)) 0)) \ | |
614d15f9 JM |
307 | Fct (Val1, Val2) \ |
308 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
309 | + (__tgmath_real_type (Val2)) 0)) \ | |
310 | Fct##f (Val1, Val2))) | |
311 | ||
be3a79a3 | 312 | # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \ |
42df8d59 | 313 | (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \ |
614d15f9 JM |
314 | && __builtin_classify_type ((Val1) + (Val2)) == 8) \ |
315 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
316 | + (__tgmath_real_type (Val2)) 0)) \ | |
1c298d08 | 317 | __tgml(Fct) (Val1, Val2) \ |
2fee621d JM |
318 | : (sizeof (+(Val1)) == sizeof (double) \ |
319 | || sizeof (+(Val2)) == sizeof (double) \ | |
1c298d08 UD |
320 | || __builtin_classify_type (Val1) != 8 \ |
321 | || __builtin_classify_type (Val2) != 8) \ | |
322 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
323 | + (__tgmath_real_type (Val2)) 0)) \ | |
324 | Fct (Val1, Val2) \ | |
325 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
326 | + (__tgmath_real_type (Val2)) 0)) \ | |
327 | Fct##f (Val1, Val2))) | |
dfd2257a | 328 | |
be3a79a3 | 329 | # define __TGMATH_BINARY_REAL_RET_ONLY(Val1, Val2, Fct) \ |
42df8d59 | 330 | (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \ |
d12a22c5 | 331 | && __builtin_classify_type ((Val1) + (Val2)) == 8) \ |
614d15f9 JM |
332 | ? __TGMATH_F128 ((Val1) + (Val2), Fct, (Val1, Val2)) \ |
333 | __tgml(Fct) (Val1, Val2) \ | |
2fee621d JM |
334 | : (sizeof (+(Val1)) == sizeof (double) \ |
335 | || sizeof (+(Val2)) == sizeof (double) \ | |
d12a22c5 JM |
336 | || __builtin_classify_type (Val1) != 8 \ |
337 | || __builtin_classify_type (Val2) != 8) \ | |
338 | ? Fct (Val1, Val2) \ | |
339 | : Fct##f (Val1, Val2))) | |
340 | ||
be3a79a3 | 341 | # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \ |
42df8d59 | 342 | (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \ |
1c298d08 | 343 | && __builtin_classify_type ((Val1) + (Val2)) == 8) \ |
614d15f9 JM |
344 | ? __TGMATH_F128 ((Val1) + (Val2), \ |
345 | (__typeof \ | |
346 | ((__tgmath_real_type (Val1)) 0 \ | |
347 | + (__tgmath_real_type (Val2)) 0)) Fct, \ | |
348 | (Val1, Val2, Val3)) \ | |
349 | (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
350 | + (__tgmath_real_type (Val2)) 0)) \ | |
351 | __tgml(Fct) (Val1, Val2, Val3) \ | |
2fee621d JM |
352 | : (sizeof (+(Val1)) == sizeof (double) \ |
353 | || sizeof (+(Val2)) == sizeof (double) \ | |
1c298d08 UD |
354 | || __builtin_classify_type (Val1) != 8 \ |
355 | || __builtin_classify_type (Val2) != 8) \ | |
356 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
357 | + (__tgmath_real_type (Val2)) 0)) \ | |
358 | Fct (Val1, Val2, Val3) \ | |
359 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
360 | + (__tgmath_real_type (Val2)) 0)) \ | |
361 | Fct##f (Val1, Val2, Val3))) | |
bfce746a | 362 | |
be3a79a3 | 363 | # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \ |
42df8d59 | 364 | (__extension__ ((sizeof ((Val1) + (Val2) + (Val3)) > sizeof (double) \ |
1c298d08 UD |
365 | && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \ |
366 | == 8) \ | |
614d15f9 JM |
367 | ? __TGMATH_F128 ((Val1) + (Val2) + (Val3), \ |
368 | (__typeof \ | |
369 | ((__tgmath_real_type (Val1)) 0 \ | |
370 | + (__tgmath_real_type (Val2)) 0 \ | |
371 | + (__tgmath_real_type (Val3)) 0)) Fct, \ | |
372 | (Val1, Val2, Val3)) \ | |
373 | (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
374 | + (__tgmath_real_type (Val2)) 0 \ | |
375 | + (__tgmath_real_type (Val3)) 0)) \ | |
1c298d08 | 376 | __tgml(Fct) (Val1, Val2, Val3) \ |
2fee621d JM |
377 | : (sizeof (+(Val1)) == sizeof (double) \ |
378 | || sizeof (+(Val2)) == sizeof (double) \ | |
379 | || sizeof (+(Val3)) == sizeof (double) \ | |
1c298d08 UD |
380 | || __builtin_classify_type (Val1) != 8 \ |
381 | || __builtin_classify_type (Val2) != 8 \ | |
382 | || __builtin_classify_type (Val3) != 8) \ | |
383 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
384 | + (__tgmath_real_type (Val2)) 0 \ | |
385 | + (__tgmath_real_type (Val3)) 0)) \ | |
386 | Fct (Val1, Val2, Val3) \ | |
387 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
388 | + (__tgmath_real_type (Val2)) 0 \ | |
389 | + (__tgmath_real_type (Val3)) 0)) \ | |
390 | Fct##f (Val1, Val2, Val3))) | |
dfd2257a | 391 | |
be3a79a3 | 392 | # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \ |
2fee621d | 393 | (__extension__ ((sizeof (+(Val1)) == sizeof (double) \ |
423c2b9d | 394 | || __builtin_classify_type (Val1) != 8) \ |
cfa44345 | 395 | ? Fct (Val1, Val2, Val3) \ |
2fee621d | 396 | : (sizeof (+(Val1)) == sizeof (float)) \ |
cfa44345 | 397 | ? Fct##f (Val1, Val2, Val3) \ |
614d15f9 JM |
398 | : __TGMATH_F128 ((Val1), Fct, (Val1, Val2, Val3)) \ |
399 | __tgml(Fct) (Val1, Val2, Val3))) | |
423c2b9d | 400 | |
48244d09 UD |
401 | /* XXX This definition has to be changed as soon as the compiler understands |
402 | the imaginary keyword. */ | |
be3a79a3 | 403 | # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \ |
2fee621d | 404 | (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \ |
1c298d08 | 405 | || __builtin_classify_type (__real__ (Val)) != 8) \ |
d9bef9c0 JM |
406 | ? (__expr_is_real (Val) \ |
407 | ? (__tgmath_complex_type (Val)) Fct (Val) \ | |
408 | : (__tgmath_complex_type (Val)) Cfct (Val)) \ | |
2fee621d | 409 | : (sizeof (+__real__ (Val)) == sizeof (float)) \ |
d9bef9c0 JM |
410 | ? (__expr_is_real (Val) \ |
411 | ? (__tgmath_complex_type (Val)) Fct##f (Val) \ | |
412 | : (__tgmath_complex_type (Val)) Cfct##f (Val)) \ | |
413 | : __TGMATH_CF128 ((Val), \ | |
414 | (__tgmath_complex_type (Val)) Fct, \ | |
415 | (__tgmath_complex_type (Val)) Cfct, \ | |
614d15f9 | 416 | (Val)) \ |
d9bef9c0 JM |
417 | (__expr_is_real (Val) \ |
418 | ? (__tgmath_complex_type (Val)) __tgml(Fct) (Val) \ | |
419 | : (__tgmath_complex_type (Val)) __tgml(Cfct) (Val)))) | |
1c298d08 | 420 | |
be3a79a3 | 421 | # define __TGMATH_UNARY_IMAG(Val, Cfct) \ |
2fee621d | 422 | (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \ |
1c298d08 UD |
423 | || __builtin_classify_type (__real__ (Val)) != 8) \ |
424 | ? (__typeof__ ((__tgmath_real_type (Val)) 0 \ | |
425 | + _Complex_I)) Cfct (Val) \ | |
2fee621d | 426 | : (sizeof (+__real__ (Val)) == sizeof (float)) \ |
1c298d08 UD |
427 | ? (__typeof__ ((__tgmath_real_type (Val)) 0 \ |
428 | + _Complex_I)) Cfct##f (Val) \ | |
614d15f9 JM |
429 | : __TGMATH_F128 (__real__ (Val), \ |
430 | (__typeof__ \ | |
431 | ((__tgmath_real_type (Val)) 0 \ | |
432 | + _Complex_I)) Cfct, (Val)) \ | |
433 | (__typeof__ ((__tgmath_real_type (Val)) 0 \ | |
434 | + _Complex_I)) __tgml(Cfct) (Val))) | |
dfd2257a | 435 | |
58d87ee1 UD |
436 | /* XXX This definition has to be changed as soon as the compiler understands |
437 | the imaginary keyword. */ | |
be3a79a3 | 438 | # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \ |
2fee621d | 439 | (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \ |
1c298d08 | 440 | || __builtin_classify_type (__real__ (Val)) != 8) \ |
d9bef9c0 | 441 | ? (__expr_is_real (Val) \ |
1c298d08 UD |
442 | ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ |
443 | Fct (Val) \ | |
444 | : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
445 | Cfct (Val)) \ | |
2fee621d | 446 | : (sizeof (+__real__ (Val)) == sizeof (float)) \ |
d9bef9c0 | 447 | ? (__expr_is_real (Val) \ |
1c298d08 UD |
448 | ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ |
449 | Fct##f (Val) \ | |
450 | : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
451 | Cfct##f (Val)) \ | |
614d15f9 JM |
452 | : __TGMATH_CF128 ((Val), \ |
453 | (__typeof__ \ | |
454 | (__real__ \ | |
455 | (__tgmath_real_type (Val)) 0)) Fct, \ | |
456 | (__typeof__ \ | |
457 | (__real__ \ | |
458 | (__tgmath_real_type (Val)) 0)) Cfct, \ | |
459 | (Val)) \ | |
d9bef9c0 | 460 | (__expr_is_real (Val) \ |
614d15f9 JM |
461 | ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \ |
462 | __tgml(Fct) (Val) \ | |
463 | : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \ | |
464 | __tgml(Cfct) (Val)))) | |
be3a79a3 JM |
465 | # define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \ |
466 | __TGMATH_UNARY_REAL_IMAG_RET_REAL ((Val), Cfct, Cfct) | |
58d87ee1 | 467 | |
48244d09 UD |
468 | /* XXX This definition has to be changed as soon as the compiler understands |
469 | the imaginary keyword. */ | |
be3a79a3 | 470 | # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \ |
42df8d59 JM |
471 | (__extension__ ((sizeof (__real__ (Val1) \ |
472 | + __real__ (Val2)) > sizeof (double) \ | |
1c298d08 UD |
473 | && __builtin_classify_type (__real__ (Val1) \ |
474 | + __real__ (Val2)) == 8) \ | |
614d15f9 JM |
475 | ? __TGMATH_CF128 ((Val1) + (Val2), \ |
476 | (__typeof \ | |
d9bef9c0 JM |
477 | ((__tgmath_complex_type (Val1)) 0 \ |
478 | + (__tgmath_complex_type (Val2)) 0)) \ | |
614d15f9 JM |
479 | Fct, \ |
480 | (__typeof \ | |
d9bef9c0 JM |
481 | ((__tgmath_complex_type (Val1)) 0 \ |
482 | + (__tgmath_complex_type (Val2)) 0)) \ | |
614d15f9 JM |
483 | Cfct, \ |
484 | (Val1, Val2)) \ | |
d9bef9c0 JM |
485 | (__expr_is_real ((Val1) + (Val2)) \ |
486 | ? (__typeof ((__tgmath_complex_type (Val1)) 0 \ | |
487 | + (__tgmath_complex_type (Val2)) 0)) \ | |
614d15f9 | 488 | __tgml(Fct) (Val1, Val2) \ |
d9bef9c0 JM |
489 | : (__typeof ((__tgmath_complex_type (Val1)) 0 \ |
490 | + (__tgmath_complex_type (Val2)) 0)) \ | |
614d15f9 | 491 | __tgml(Cfct) (Val1, Val2)) \ |
2fee621d JM |
492 | : (sizeof (+__real__ (Val1)) == sizeof (double) \ |
493 | || sizeof (+__real__ (Val2)) == sizeof (double) \ | |
1c298d08 UD |
494 | || __builtin_classify_type (__real__ (Val1)) != 8 \ |
495 | || __builtin_classify_type (__real__ (Val2)) != 8) \ | |
d9bef9c0 JM |
496 | ? (__expr_is_real ((Val1) + (Val2)) \ |
497 | ? (__typeof ((__tgmath_complex_type (Val1)) 0 \ | |
498 | + (__tgmath_complex_type (Val2)) 0)) \ | |
1c298d08 | 499 | Fct (Val1, Val2) \ |
d9bef9c0 JM |
500 | : (__typeof ((__tgmath_complex_type (Val1)) 0 \ |
501 | + (__tgmath_complex_type (Val2)) 0)) \ | |
1c298d08 | 502 | Cfct (Val1, Val2)) \ |
d9bef9c0 JM |
503 | : (__expr_is_real ((Val1) + (Val2)) \ |
504 | ? (__typeof ((__tgmath_complex_type (Val1)) 0 \ | |
505 | + (__tgmath_complex_type (Val2)) 0)) \ | |
1c298d08 | 506 | Fct##f (Val1, Val2) \ |
d9bef9c0 JM |
507 | : (__typeof ((__tgmath_complex_type (Val1)) 0 \ |
508 | + (__tgmath_complex_type (Val2)) 0)) \ | |
1c298d08 | 509 | Cfct##f (Val1, Val2)))) |
be3a79a3 | 510 | # endif /* !__HAVE_BUILTIN_TGMATH. */ |
dfd2257a UD |
511 | #else |
512 | # error "Unsupported compiler; you cannot use <tgmath.h>" | |
513 | #endif | |
514 | ||
515 | ||
516 | /* Unary functions defined for real and complex values. */ | |
517 | ||
518 | ||
519 | /* Trigonometric functions. */ | |
520 | ||
521 | /* Arc cosine of X. */ | |
522 | #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos) | |
523 | /* Arc sine of X. */ | |
524 | #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin) | |
525 | /* Arc tangent of X. */ | |
526 | #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan) | |
527 | /* Arc tangent of Y/X. */ | |
cfb32a6c | 528 | #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2) |
dfd2257a UD |
529 | |
530 | /* Cosine of X. */ | |
531 | #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos) | |
532 | /* Sine of X. */ | |
533 | #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin) | |
534 | /* Tangent of X. */ | |
535 | #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan) | |
536 | ||
537 | ||
538 | /* Hyperbolic functions. */ | |
539 | ||
540 | /* Hyperbolic arc cosine of X. */ | |
541 | #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh) | |
542 | /* Hyperbolic arc sine of X. */ | |
543 | #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh) | |
544 | /* Hyperbolic arc tangent of X. */ | |
545 | #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh) | |
546 | ||
547 | /* Hyperbolic cosine of X. */ | |
548 | #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh) | |
549 | /* Hyperbolic sine of X. */ | |
550 | #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh) | |
551 | /* Hyperbolic tangent of X. */ | |
552 | #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh) | |
553 | ||
554 | ||
555 | /* Exponential and logarithmic functions. */ | |
556 | ||
557 | /* Exponential function of X. */ | |
558 | #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp) | |
559 | ||
560 | /* Break VALUE into a normalized fraction and an integral power of 2. */ | |
561 | #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp) | |
562 | ||
563 | /* X times (two to the EXP power). */ | |
564 | #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp) | |
565 | ||
566 | /* Natural logarithm of X. */ | |
567 | #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog) | |
568 | ||
569 | /* Base-ten logarithm of X. */ | |
cc3fa755 | 570 | #ifdef __USE_GNU |
0908a38a | 571 | # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10) |
cc3fa755 UD |
572 | #else |
573 | # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10) | |
574 | #endif | |
dfd2257a UD |
575 | |
576 | /* Return exp(X) - 1. */ | |
577 | #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1) | |
578 | ||
579 | /* Return log(1 + X). */ | |
580 | #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p) | |
581 | ||
582 | /* Return the base 2 signed integral exponent of X. */ | |
583 | #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb) | |
584 | ||
585 | /* Compute base-2 exponential of X. */ | |
586 | #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2) | |
587 | ||
588 | /* Compute base-2 logarithm of X. */ | |
589 | #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2) | |
590 | ||
591 | ||
592 | /* Power functions. */ | |
593 | ||
594 | /* Return X to the Y power. */ | |
595 | #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow) | |
596 | ||
597 | /* Return the square root of X. */ | |
598 | #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt) | |
599 | ||
600 | /* Return `sqrt(X*X + Y*Y)'. */ | |
601 | #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot) | |
602 | ||
603 | /* Return the cube root of X. */ | |
604 | #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt) | |
605 | ||
606 | ||
607 | /* Nearest integer, absolute value, and remainder functions. */ | |
608 | ||
609 | /* Smallest integral value not less than X. */ | |
610 | #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil) | |
611 | ||
612 | /* Absolute value of X. */ | |
f1debaf6 | 613 | #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs) |
dfd2257a UD |
614 | |
615 | /* Largest integer not greater than X. */ | |
616 | #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor) | |
617 | ||
618 | /* Floating-point modulo remainder of X/Y. */ | |
619 | #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod) | |
620 | ||
621 | /* Round X to integral valuein floating-point format using current | |
622 | rounding direction, but do not raise inexact exception. */ | |
623 | #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint) | |
624 | ||
625 | /* Round X to nearest integral value, rounding halfway cases away from | |
626 | zero. */ | |
627 | #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round) | |
628 | ||
629 | /* Round X to the integral value in floating-point format nearest but | |
630 | not larger in magnitude. */ | |
631 | #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc) | |
632 | ||
633 | /* Compute remainder of X and Y and put in *QUO a value with sign of x/y | |
634 | and magnitude congruent `mod 2^n' to the magnitude of the integral | |
635 | quotient x/y, with n >= 3. */ | |
636 | #define remquo(Val1, Val2, Val3) \ | |
637 | __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo) | |
638 | ||
639 | /* Round X to nearest integral value according to current rounding | |
640 | direction. */ | |
cfa44345 JM |
641 | #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint) |
642 | #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint) | |
dfd2257a UD |
643 | |
644 | /* Round X to nearest integral value, rounding halfway cases away from | |
645 | zero. */ | |
cfa44345 JM |
646 | #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround) |
647 | #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround) | |
dfd2257a UD |
648 | |
649 | ||
650 | /* Return X with its signed changed to Y's. */ | |
651 | #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign) | |
652 | ||
653 | /* Error and gamma functions. */ | |
654 | #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf) | |
655 | #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc) | |
00d8bc81 | 656 | #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma) |
dfd2257a UD |
657 | #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma) |
658 | ||
659 | ||
660 | /* Return the integer nearest X in the direction of the | |
661 | prevailing rounding mode. */ | |
662 | #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint) | |
663 | ||
0175c9e9 | 664 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
41a359e2 RS |
665 | /* Return X - epsilon. */ |
666 | # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown) | |
667 | /* Return X + epsilon. */ | |
668 | # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup) | |
669 | #endif | |
670 | ||
dfd2257a UD |
671 | /* Return X + epsilon if X < Y, X - epsilon if X > Y. */ |
672 | #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter) | |
42bd0a85 | 673 | #define nexttoward(Val1, Val2) \ |
614d15f9 | 674 | __TGMATH_BINARY_FIRST_REAL_STD_ONLY (Val1, Val2, nexttoward) |
dfd2257a UD |
675 | |
676 | /* Return the remainder of integer divison X / Y with infinite precision. */ | |
677 | #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder) | |
678 | ||
679 | /* Return X times (2 to the Nth power). */ | |
de20571d | 680 | #ifdef __USE_MISC |
614d15f9 | 681 | # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, scalb) |
26644e87 | 682 | #endif |
dfd2257a UD |
683 | |
684 | /* Return X times (2 to the Nth power). */ | |
685 | #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn) | |
686 | ||
687 | /* Return X times (2 to the Nth power). */ | |
688 | #define scalbln(Val1, Val2) \ | |
689 | __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln) | |
690 | ||
691 | /* Return the binary exponent of X, which must be nonzero. */ | |
cfa44345 | 692 | #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb) |
dfd2257a UD |
693 | |
694 | ||
695 | /* Return positive difference between X and Y. */ | |
696 | #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim) | |
697 | ||
698 | /* Return maximum numeric value from X and Y. */ | |
699 | #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax) | |
700 | ||
701 | /* Return minimum numeric value from X and Y. */ | |
702 | #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin) | |
703 | ||
704 | ||
bfce746a | 705 | /* Multiply-add function computed as a ternary operation. */ |
e7c3d12b | 706 | #define fma(Val1, Val2, Val3) \ |
bfce746a UD |
707 | __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma) |
708 | ||
0175c9e9 | 709 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
41c67149 JM |
710 | /* Round X to nearest integer value, rounding halfway cases to even. */ |
711 | # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven) | |
712 | ||
423c2b9d | 713 | # define fromfp(Val1, Val2, Val3) \ |
cfa44345 | 714 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp) |
423c2b9d JM |
715 | |
716 | # define ufromfp(Val1, Val2, Val3) \ | |
cfa44345 | 717 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp) |
423c2b9d JM |
718 | |
719 | # define fromfpx(Val1, Val2, Val3) \ | |
cfa44345 | 720 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx) |
423c2b9d JM |
721 | |
722 | # define ufromfpx(Val1, Val2, Val3) \ | |
cfa44345 | 723 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx) |
423c2b9d | 724 | |
55a38f82 | 725 | /* Like ilogb, but returning long int. */ |
cfa44345 | 726 | # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb) |
55a38f82 | 727 | |
525f8039 JM |
728 | /* Return value with maximum magnitude. */ |
729 | # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag) | |
730 | ||
731 | /* Return value with minimum magnitude. */ | |
732 | # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag) | |
0175c9e9 | 733 | #endif |
525f8039 | 734 | |
0175c9e9 | 735 | #if __GLIBC_USE (IEC_60559_BFP_EXT) |
5e9d98a3 | 736 | /* Total order operation. */ |
d12a22c5 JM |
737 | # define totalorder(Val1, Val2) \ |
738 | __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalorder) | |
cc6a8d74 JM |
739 | |
740 | /* Total order operation on absolute values. */ | |
d12a22c5 JM |
741 | # define totalordermag(Val1, Val2) \ |
742 | __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalordermag) | |
5e9d98a3 JM |
743 | #endif |
744 | ||
bfce746a | 745 | |
dfd2257a UD |
746 | /* Absolute value, conjugates, and projection. */ |
747 | ||
748 | /* Argument value of Z. */ | |
be3a79a3 | 749 | #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, carg) |
dfd2257a UD |
750 | |
751 | /* Complex conjugate of Z. */ | |
1c298d08 | 752 | #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj) |
dfd2257a UD |
753 | |
754 | /* Projection of Z onto the Riemann sphere. */ | |
1c298d08 | 755 | #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj) |
dfd2257a UD |
756 | |
757 | ||
758 | /* Decomposing complex values. */ | |
759 | ||
760 | /* Imaginary part of Z. */ | |
be3a79a3 | 761 | #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, cimag) |
dfd2257a UD |
762 | |
763 | /* Real part of Z. */ | |
be3a79a3 | 764 | #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, creal) |
dfd2257a UD |
765 | |
766 | #endif /* tgmath.h */ |