1 /* Copyright (C) 1997-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 * ISO C99 Standard: 7.22 Type-generic math <tgmath.h>
25 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
26 #include <bits/libc-header-start.h>
28 /* Include the needed headers. */
29 #include <bits/floatn.h>
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). Because of a long series
41 of defect fixes made after the initial release of TS 18661-1, GCC
42 versions before GCC 13 have __builtin_tgmath semantics that, when
43 integer arguments are passed to narrowing macros returning
44 _Float32x, or non-narrowing macros with at least two generic
45 arguments, do not always correspond to the C2X semantics, so more
46 complicated macro definitions are also used in some cases for
47 versions from GCC 8 to GCC 12. */
49 #define __HAVE_BUILTIN_TGMATH __GNUC_PREREQ (8, 0)
50 #define __HAVE_BUILTIN_TGMATH_C2X __GNUC_PREREQ (13, 0)
52 #if __GNUC_PREREQ (2, 7)
54 /* Certain cases of narrowing macros only need to call a single
55 function so cannot use __builtin_tgmath and do not need any
58 # error "Unsupported _Float128x type for <tgmath.h>."
60 # if ((__HAVE_FLOAT64X && !__HAVE_FLOAT128) \
61 || (__HAVE_FLOAT128 && !__HAVE_FLOAT64X))
62 # error "Unsupported combination of types for <tgmath.h>."
64 # define __TGMATH_1_NARROW_D(F, X) \
66 # define __TGMATH_2_NARROW_D(F, X, Y) \
68 # define __TGMATH_3_NARROW_D(F, X, Y, Z) \
70 # define __TGMATH_1_NARROW_F64X(F, X) \
72 # define __TGMATH_2_NARROW_F64X(F, X, Y) \
74 # define __TGMATH_3_NARROW_F64X(F, X, Y, Z) \
77 # define __TGMATH_1_NARROW_F32X(F, X) \
79 # define __TGMATH_2_NARROW_F32X(F, X, Y) \
81 # define __TGMATH_3_NARROW_F32X(F, X, Y, Z) \
85 # if __HAVE_BUILTIN_TGMATH
87 # if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
88 # define __TG_F16_ARG(X) X ## f16,
90 # define __TG_F16_ARG(X)
92 # if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
93 # define __TG_F32_ARG(X) X ## f32,
95 # define __TG_F32_ARG(X)
97 # if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
98 # define __TG_F64_ARG(X) X ## f64,
100 # define __TG_F64_ARG(X)
102 # if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
103 # define __TG_F128_ARG(X) X ## f128,
105 # define __TG_F128_ARG(X)
107 # if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
108 # define __TG_F32X_ARG(X) X ## f32x,
110 # define __TG_F32X_ARG(X)
112 # if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
113 # define __TG_F64X_ARG(X) X ## f64x,
115 # define __TG_F64X_ARG(X)
117 # if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
118 # define __TG_F128X_ARG(X) X ## f128x,
120 # define __TG_F128X_ARG(X)
123 # define __TGMATH_FUNCS(X) X ## f, X, X ## l, \
124 __TG_F16_ARG (X) __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \
125 __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
126 # define __TGMATH_RCFUNCS(F, C) __TGMATH_FUNCS (F) __TGMATH_FUNCS (C)
127 # define __TGMATH_1(F, X) __builtin_tgmath (__TGMATH_FUNCS (F) (X))
128 # define __TGMATH_2(F, X, Y) __builtin_tgmath (__TGMATH_FUNCS (F) (X), (Y))
129 # define __TGMATH_2STD(F, X, Y) __builtin_tgmath (F ## f, F, F ## l, (X), (Y))
130 # define __TGMATH_3(F, X, Y, Z) __builtin_tgmath (__TGMATH_FUNCS (F) \
132 # define __TGMATH_1C(F, C, X) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) (X))
133 # define __TGMATH_2C(F, C, X, Y) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) \
136 # define __TGMATH_NARROW_FUNCS_F(X) X, X ## l,
137 # define __TGMATH_NARROW_FUNCS_F16(X) \
138 __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \
139 __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
140 # define __TGMATH_NARROW_FUNCS_F32(X) \
141 __TG_F64_ARG (X) __TG_F128_ARG (X) \
142 __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
143 # define __TGMATH_NARROW_FUNCS_F64(X) \
145 __TG_F64X_ARG (X) __TG_F128X_ARG (X)
146 # define __TGMATH_NARROW_FUNCS_F32X(X) \
147 __TG_F64X_ARG (X) __TG_F128X_ARG (X) \
148 __TG_F64_ARG (X) __TG_F128_ARG (X)
150 # define __TGMATH_1_NARROW_F(F, X) \
151 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F (F) (X))
152 # define __TGMATH_2_NARROW_F(F, X, Y) \
153 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F (F) (X), (Y))
154 # define __TGMATH_3_NARROW_F(F, X, Y, Z) \
155 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F (F) (X), (Y), (Z))
156 # define __TGMATH_1_NARROW_F16(F, X) \
157 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F16 (F) (X))
158 # define __TGMATH_2_NARROW_F16(F, X, Y) \
159 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F16 (F) (X), (Y))
160 # define __TGMATH_3_NARROW_F16(F, X, Y, Z) \
161 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F16 (F) (X), (Y), (Z))
162 # define __TGMATH_1_NARROW_F32(F, X) \
163 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32 (F) (X))
164 # define __TGMATH_2_NARROW_F32(F, X, Y) \
165 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32 (F) (X), (Y))
166 # define __TGMATH_3_NARROW_F32(F, X, Y, Z) \
167 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32 (F) (X), (Y), (Z))
168 # define __TGMATH_1_NARROW_F64(F, X) \
169 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F64 (F) (X))
170 # define __TGMATH_2_NARROW_F64(F, X, Y) \
171 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F64 (F) (X), (Y))
172 # define __TGMATH_3_NARROW_F64(F, X, Y, Z) \
173 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F64 (F) (X), (Y), (Z))
174 # if __HAVE_FLOAT128 && __HAVE_BUILTIN_TGMATH_C2X
175 # define __TGMATH_1_NARROW_F32X(F, X) \
176 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32X (F) (X))
177 # define __TGMATH_2_NARROW_F32X(F, X, Y) \
178 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32X (F) (X), (Y))
179 # define __TGMATH_3_NARROW_F32X(F, X, Y, Z) \
180 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32X (F) (X), (Y), (Z))
185 # if !__HAVE_BUILTIN_TGMATH_C2X
186 # ifdef __NO_LONG_DOUBLE_MATH
187 # define __tgml(fct) fct
189 # define __tgml(fct) fct ## l
192 /* __floating_type expands to 1 if TYPE is a floating type (including
193 complex floating types), 0 if TYPE is an integer type (including
194 complex integer types). __real_integer_type expands to 1 if TYPE
195 is a real integer type. __complex_integer_type expands to 1 if
196 TYPE is a complex integer type. All these macros expand to integer
197 constant expressions. All these macros can assume their argument
198 has an arithmetic type (not vector, decimal floating-point or
199 fixed-point), valid to pass to tgmath.h macros. */
200 # if __GNUC_PREREQ (3, 1)
201 /* __builtin_classify_type expands to an integer constant expression
202 in GCC 3.1 and later. Default conversions applied to the argument
203 of __builtin_classify_type mean it always returns 1 for real
204 integer types rather than ever returning different values for
205 character, boolean or enumerated types. */
206 # define __floating_type(type) \
207 (__builtin_classify_type (__real__ ((type) 0)) == 8)
208 # define __real_integer_type(type) \
209 (__builtin_classify_type ((type) 0) == 1)
210 # define __complex_integer_type(type) \
211 (__builtin_classify_type ((type) 0) == 9 \
212 && __builtin_classify_type (__real__ ((type) 0)) == 1)
214 /* GCC versions predating __builtin_classify_type are also looser on
215 what counts as an integer constant expression. */
216 # define __floating_type(type) (((type) 1.25) != 1)
217 # define __real_integer_type(type) (((type) (1.25 + _Complex_I)) == 1)
218 # define __complex_integer_type(type) \
219 (((type) (1.25 + _Complex_I)) == (1 + _Complex_I))
222 /* Whether an expression (of arithmetic type) has a real type. */
223 # define __expr_is_real(E) (__builtin_classify_type (E) != 9)
225 /* Type T1 if E is 1, type T2 is E is 0. */
226 # define __tgmath_type_if(T1, T2, E) \
227 __typeof__ (*(0 ? (__typeof__ (0 ? (T2 *) 0 : (void *) (E))) 0 \
228 : (__typeof__ (0 ? (T1 *) 0 : (void *) (!(E)))) 0))
230 /* The tgmath real type for T, where E is 0 if T is an integer type
231 and 1 for a floating type. If T has a complex type, it is
232 unspecified whether the return type is real or complex (but it has
233 the correct corresponding real type). */
234 # define __tgmath_real_type_sub(T, E) \
235 __tgmath_type_if (T, double, E)
237 /* The tgmath real type of EXPR. */
238 # define __tgmath_real_type(expr) \
239 __tgmath_real_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
240 __floating_type (__typeof__ (+(expr))))
242 /* The tgmath complex type for T, where E1 is 1 if T has a floating
243 type and 0 otherwise, E2 is 1 if T has a real integer type and 0
244 otherwise, and E3 is 1 if T has a complex type and 0 otherwise. */
245 # define __tgmath_complex_type_sub(T, E1, E2, E3) \
247 ? (__typeof__ (0 ? (T *) 0 : (void *) (!(E1)))) 0 \
251 : (void *) (!(E2)))) 0 \
253 ? (_Complex double *) 0 \
254 : (void *) (!(E3)))) 0)) 0))
256 /* The tgmath complex type of EXPR. */
257 # define __tgmath_complex_type(expr) \
258 __tgmath_complex_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
259 __floating_type (__typeof__ (+(expr))), \
260 __real_integer_type (__typeof__ (+(expr))), \
261 __complex_integer_type (__typeof__ (+(expr))))
263 /* The tgmath real type of EXPR1 combined with EXPR2, without handling
264 the C2X rule of interpreting integer arguments as _Float32x if any
265 argument is _FloatNx. */
266 # define __tgmath_real_type2_base(expr1, expr2) \
267 __typeof ((__tgmath_real_type (expr1)) 0 + (__tgmath_real_type (expr2)) 0)
269 /* The tgmath complex type of EXPR1 combined with EXPR2, without
270 handling the C2X rule of interpreting integer arguments as
271 _Float32x if any argument is _FloatNx. */
272 # define __tgmath_complex_type2_base(expr1, expr2) \
273 __typeof ((__tgmath_complex_type (expr1)) 0 \
274 + (__tgmath_complex_type (expr2)) 0)
276 /* The tgmath real type of EXPR1 combined with EXPR2 and EXPR3,
277 without handling the C2X rule of interpreting integer arguments as
278 _Float32x if any argument is _FloatNx. */
279 # define __tgmath_real_type3_base(expr1, expr2, expr3) \
280 __typeof ((__tgmath_real_type (expr1)) 0 \
281 + (__tgmath_real_type (expr2)) 0 \
282 + (__tgmath_real_type (expr3)) 0)
284 /* The tgmath real or complex type of EXPR1 combined with EXPR2 (and
285 EXPR3 if applicable). */
286 # if __HAVE_FLOATN_NOT_TYPEDEF
287 # define __tgmath_real_type2(expr1, expr2) \
288 __tgmath_type_if (_Float32x, __tgmath_real_type2_base (expr1, expr2), \
289 _Generic ((expr1) + (expr2), _Float32x: 1, default: 0))
290 # define __tgmath_complex_type2(expr1, expr2) \
291 __tgmath_type_if (_Float32x, \
292 __tgmath_type_if (_Complex _Float32x, \
293 __tgmath_complex_type2_base (expr1, \
295 _Generic ((expr1) + (expr2), \
296 _Complex _Float32x: 1, \
298 _Generic ((expr1) + (expr2), _Float32x: 1, default: 0))
299 # define __tgmath_real_type3(expr1, expr2, expr3) \
300 __tgmath_type_if (_Float32x, \
301 __tgmath_real_type3_base (expr1, expr2, expr3), \
302 _Generic ((expr1) + (expr2) + (expr3), \
303 _Float32x: 1, default: 0))
305 # define __tgmath_real_type2(expr1, expr2) \
306 __tgmath_real_type2_base (expr1, expr2)
307 # define __tgmath_complex_type2(expr1, expr2) \
308 __tgmath_complex_type2_base (expr1, expr2)
309 # define __tgmath_real_type3(expr1, expr2, expr3) \
310 __tgmath_real_type3_base (expr1, expr2, expr3)
313 # if (__HAVE_DISTINCT_FLOAT16 \
314 || __HAVE_DISTINCT_FLOAT32 \
315 || __HAVE_DISTINCT_FLOAT64 \
316 || __HAVE_DISTINCT_FLOAT32X \
317 || __HAVE_DISTINCT_FLOAT64X \
318 || __HAVE_DISTINCT_FLOAT128X)
319 # error "Unsupported _FloatN or _FloatNx types for <tgmath.h>."
322 /* Expand to text that checks if ARG_COMB has type _Float128, and if
323 so calls the appropriately suffixed FCT (which may include a cast),
324 or FCT and CFCT for complex functions, with arguments ARG_CALL.
325 __TGMATH_F128LD (only used in the __HAVE_FLOAT64X_LONG_DOUBLE case,
326 for narrowing macros) handles long double the same as
328 # if __HAVE_DISTINCT_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
329 # if (!__HAVE_FLOAT64X \
330 || __HAVE_FLOAT64X_LONG_DOUBLE \
331 || !__HAVE_FLOATN_NOT_TYPEDEF)
332 # define __TGMATH_F128(arg_comb, fct, arg_call) \
333 __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
334 ? fct ## f128 arg_call :
335 # define __TGMATH_F128LD(arg_comb, fct, arg_call) \
336 (__builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
337 || __builtin_types_compatible_p (__typeof (+(arg_comb)), long double)) \
338 ? fct ## f128 arg_call :
339 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
340 __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
341 ? (__expr_is_real (arg_comb) \
342 ? fct ## f128 arg_call \
343 : cfct ## f128 arg_call) :
345 /* _Float64x is a distinct type at the C language level, which must be
346 handled like _Float128. */
347 # define __TGMATH_F128(arg_comb, fct, arg_call) \
348 (__builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
349 || __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float64x)) \
350 ? fct ## f128 arg_call :
351 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
352 (__builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
353 || __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), \
355 ? (__expr_is_real (arg_comb) \
356 ? fct ## f128 arg_call \
357 : cfct ## f128 arg_call) :
360 # define __TGMATH_F128(arg_comb, fct, arg_call) /* Nothing. */
361 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) /* Nothing. */
364 # endif /* !__HAVE_BUILTIN_TGMATH_C2X. */
366 /* We have two kinds of generic macros: to support functions which are
367 only defined on real valued parameters and those which are defined
368 for complex functions as well. */
369 # if __HAVE_BUILTIN_TGMATH
371 # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val))
372 # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val))
373 # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
374 __TGMATH_2 (Fct, (Val1), (Val2))
375 # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
376 __TGMATH_2STD (Fct, (Val1), (Val2))
377 # if __HAVE_BUILTIN_TGMATH_C2X
378 # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
379 __TGMATH_2 (Fct, (Val1), (Val2))
381 # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
382 __TGMATH_2STD (Fct, (Val1), (Val2))
383 # if __HAVE_BUILTIN_TGMATH_C2X
384 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
385 __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
386 # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
387 __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
389 # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
390 __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
391 # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
392 __TGMATH_1C (Fct, Cfct, (Val))
393 # define __TGMATH_UNARY_IMAG(Val, Cfct) __TGMATH_1 (Cfct, (Val))
394 # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
395 __TGMATH_1C (Fct, Cfct, (Val))
396 # define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \
397 __TGMATH_1 (Cfct, (Val))
398 # if __HAVE_BUILTIN_TGMATH_C2X
399 # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
400 __TGMATH_2C (Fct, Cfct, (Val1), (Val2))
405 # if !__HAVE_BUILTIN_TGMATH
406 # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
407 (__extension__ ((sizeof (+(Val)) == sizeof (double) \
408 || __builtin_classify_type (Val) != 8) \
409 ? (__tgmath_real_type (Val)) Fct (Val) \
410 : (sizeof (+(Val)) == sizeof (float)) \
411 ? (__tgmath_real_type (Val)) Fct##f (Val) \
412 : __TGMATH_F128 ((Val), (__tgmath_real_type (Val)) Fct, \
414 (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
416 # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \
417 (__extension__ ((sizeof (+(Val)) == sizeof (double) \
418 || __builtin_classify_type (Val) != 8) \
420 : (sizeof (+(Val)) == sizeof (float)) \
422 : __TGMATH_F128 ((Val), Fct, (Val)) \
425 # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
426 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
427 || __builtin_classify_type (Val1) != 8) \
428 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
429 : (sizeof (+(Val1)) == sizeof (float)) \
430 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
431 : __TGMATH_F128 ((Val1), (__tgmath_real_type (Val1)) Fct, \
433 (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
435 # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
436 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
437 || __builtin_classify_type (Val1) != 8) \
438 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
439 : (sizeof (+(Val1)) == sizeof (float)) \
440 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
441 : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
444 # if !__HAVE_BUILTIN_TGMATH_C2X
445 # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
446 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
447 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
448 ? __TGMATH_F128 ((Val1) + (Val2), \
449 (__tgmath_real_type2 (Val1, Val2)) Fct, \
451 (__tgmath_real_type2 (Val1, Val2)) \
452 __tgml(Fct) (Val1, Val2) \
453 : (sizeof (+(Val1)) == sizeof (double) \
454 || sizeof (+(Val2)) == sizeof (double) \
455 || __builtin_classify_type (Val1) != 8 \
456 || __builtin_classify_type (Val2) != 8) \
457 ? (__tgmath_real_type2 (Val1, Val2)) \
459 : (__tgmath_real_type2 (Val1, Val2)) \
460 Fct##f (Val1, Val2)))
463 # if !__HAVE_BUILTIN_TGMATH
464 # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
465 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
466 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
467 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
468 + (__tgmath_real_type (Val2)) 0)) \
469 __tgml(Fct) (Val1, Val2) \
470 : (sizeof (+(Val1)) == sizeof (double) \
471 || sizeof (+(Val2)) == sizeof (double) \
472 || __builtin_classify_type (Val1) != 8 \
473 || __builtin_classify_type (Val2) != 8) \
474 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
475 + (__tgmath_real_type (Val2)) 0)) \
477 : (__typeof ((__tgmath_real_type (Val1)) 0 \
478 + (__tgmath_real_type (Val2)) 0)) \
479 Fct##f (Val1, Val2)))
482 # if !__HAVE_BUILTIN_TGMATH_C2X
483 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
484 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
485 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
486 ? __TGMATH_F128 ((Val1) + (Val2), \
487 (__tgmath_real_type2 (Val1, Val2)) Fct, \
488 (Val1, Val2, Val3)) \
489 (__tgmath_real_type2 (Val1, Val2)) \
490 __tgml(Fct) (Val1, Val2, Val3) \
491 : (sizeof (+(Val1)) == sizeof (double) \
492 || sizeof (+(Val2)) == sizeof (double) \
493 || __builtin_classify_type (Val1) != 8 \
494 || __builtin_classify_type (Val2) != 8) \
495 ? (__tgmath_real_type2 (Val1, Val2)) \
496 Fct (Val1, Val2, Val3) \
497 : (__tgmath_real_type2 (Val1, Val2)) \
498 Fct##f (Val1, Val2, Val3)))
500 # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
501 (__extension__ ((sizeof ((Val1) + (Val2) + (Val3)) > sizeof (double) \
502 && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
504 ? __TGMATH_F128 ((Val1) + (Val2) + (Val3), \
505 (__tgmath_real_type3 (Val1, Val2, \
507 (Val1, Val2, Val3)) \
508 (__tgmath_real_type3 (Val1, Val2, Val3)) \
509 __tgml(Fct) (Val1, Val2, Val3) \
510 : (sizeof (+(Val1)) == sizeof (double) \
511 || sizeof (+(Val2)) == sizeof (double) \
512 || sizeof (+(Val3)) == sizeof (double) \
513 || __builtin_classify_type (Val1) != 8 \
514 || __builtin_classify_type (Val2) != 8 \
515 || __builtin_classify_type (Val3) != 8) \
516 ? (__tgmath_real_type3 (Val1, Val2, Val3)) \
517 Fct (Val1, Val2, Val3) \
518 : (__tgmath_real_type3 (Val1, Val2, Val3)) \
519 Fct##f (Val1, Val2, Val3)))
522 # if !__HAVE_BUILTIN_TGMATH
523 # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
524 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
525 || __builtin_classify_type (Val1) != 8) \
526 ? Fct (Val1, Val2, Val3) \
527 : (sizeof (+(Val1)) == sizeof (float)) \
528 ? Fct##f (Val1, Val2, Val3) \
529 : __TGMATH_F128 ((Val1), Fct, (Val1, Val2, Val3)) \
530 __tgml(Fct) (Val1, Val2, Val3)))
532 /* XXX This definition has to be changed as soon as the compiler understands
533 the imaginary keyword. */
534 # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
535 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
536 || __builtin_classify_type (__real__ (Val)) != 8) \
537 ? (__expr_is_real (Val) \
538 ? (__tgmath_complex_type (Val)) Fct (Val) \
539 : (__tgmath_complex_type (Val)) Cfct (Val)) \
540 : (sizeof (+__real__ (Val)) == sizeof (float)) \
541 ? (__expr_is_real (Val) \
542 ? (__tgmath_complex_type (Val)) Fct##f (Val) \
543 : (__tgmath_complex_type (Val)) Cfct##f (Val)) \
544 : __TGMATH_CF128 ((Val), \
545 (__tgmath_complex_type (Val)) Fct, \
546 (__tgmath_complex_type (Val)) Cfct, \
548 (__expr_is_real (Val) \
549 ? (__tgmath_complex_type (Val)) __tgml(Fct) (Val) \
550 : (__tgmath_complex_type (Val)) __tgml(Cfct) (Val))))
552 # define __TGMATH_UNARY_IMAG(Val, Cfct) \
553 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
554 || __builtin_classify_type (__real__ (Val)) != 8) \
555 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
556 + _Complex_I)) Cfct (Val) \
557 : (sizeof (+__real__ (Val)) == sizeof (float)) \
558 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
559 + _Complex_I)) Cfct##f (Val) \
560 : __TGMATH_F128 (__real__ (Val), \
562 ((__tgmath_real_type (Val)) 0 \
563 + _Complex_I)) Cfct, (Val)) \
564 (__typeof__ ((__tgmath_real_type (Val)) 0 \
565 + _Complex_I)) __tgml(Cfct) (Val)))
567 /* XXX This definition has to be changed as soon as the compiler understands
568 the imaginary keyword. */
569 # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
570 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
571 || __builtin_classify_type (__real__ (Val)) != 8) \
572 ? (__expr_is_real (Val) \
573 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
575 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
577 : (sizeof (+__real__ (Val)) == sizeof (float)) \
578 ? (__expr_is_real (Val) \
579 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
581 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
583 : __TGMATH_CF128 ((Val), \
586 (__tgmath_real_type (Val)) 0)) Fct, \
589 (__tgmath_real_type (Val)) 0)) Cfct, \
591 (__expr_is_real (Val) \
592 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
594 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
595 __tgml(Cfct) (Val))))
596 # define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \
597 __TGMATH_UNARY_REAL_IMAG_RET_REAL ((Val), Cfct, Cfct)
600 # if !__HAVE_BUILTIN_TGMATH_C2X
601 /* XXX This definition has to be changed as soon as the compiler understands
602 the imaginary keyword. */
603 # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
604 (__extension__ ((sizeof (__real__ (Val1) \
605 + __real__ (Val2)) > sizeof (double) \
606 && __builtin_classify_type (__real__ (Val1) \
607 + __real__ (Val2)) == 8) \
608 ? __TGMATH_CF128 ((Val1) + (Val2), \
609 (__tgmath_complex_type2 (Val1, Val2)) \
611 (__tgmath_complex_type2 (Val1, Val2)) \
614 (__expr_is_real ((Val1) + (Val2)) \
615 ? (__tgmath_complex_type2 (Val1, Val2)) \
616 __tgml(Fct) (Val1, Val2) \
617 : (__tgmath_complex_type2 (Val1, Val2)) \
618 __tgml(Cfct) (Val1, Val2)) \
619 : (sizeof (+__real__ (Val1)) == sizeof (double) \
620 || sizeof (+__real__ (Val2)) == sizeof (double) \
621 || __builtin_classify_type (__real__ (Val1)) != 8 \
622 || __builtin_classify_type (__real__ (Val2)) != 8) \
623 ? (__expr_is_real ((Val1) + (Val2)) \
624 ? (__tgmath_complex_type2 (Val1, Val2)) \
626 : (__tgmath_complex_type2 (Val1, Val2)) \
628 : (__expr_is_real ((Val1) + (Val2)) \
629 ? (__tgmath_complex_type2 (Val1, Val2)) \
630 Fct##f (Val1, Val2) \
631 : (__tgmath_complex_type2 (Val1, Val2)) \
632 Cfct##f (Val1, Val2))))
635 # if !__HAVE_BUILTIN_TGMATH
636 # define __TGMATH_1_NARROW_F(F, X) \
637 (__extension__ (sizeof ((__tgmath_real_type (X)) 0) > sizeof (double) \
640 # define __TGMATH_2_NARROW_F(F, X, Y) \
641 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
642 + (__tgmath_real_type (Y)) 0) > sizeof (double) \
645 # define __TGMATH_3_NARROW_F(F, X, Y, Z) \
646 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
647 + (__tgmath_real_type (Y)) 0 \
648 + (__tgmath_real_type (Z)) 0) > sizeof (double) \
652 /* In most cases, these narrowing macro definitions based on sizeof
653 ensure that the function called has the right argument format, as
654 for other <tgmath.h> macros for compilers before GCC 8, but may not
655 have exactly the argument type (among the types with that format)
656 specified in the standard logic.
658 In the case of macros for _Float32x return type, when _Float64x
659 exists, _Float64 arguments should result in the *f64 function being
660 called while _Float32x, float and double arguments should result in
661 the *f64x function being called (and integer arguments are
662 considered to have type _Float32x if any argument has type
663 _FloatNx, or double otherwise). These cases cannot be
664 distinguished using sizeof (or at all if the types are typedefs
665 rather than different types, in which case we err on the side of
666 using the wider type if unsure). */
667 # if !__HAVE_BUILTIN_TGMATH_C2X
668 # if __HAVE_FLOATN_NOT_TYPEDEF
669 # define __TGMATH_NARROW_F32X_USE_F64X(X) \
670 !__builtin_types_compatible_p (__typeof (+(X)), _Float64)
672 # define __TGMATH_NARROW_F32X_USE_F64X(X) \
673 (__builtin_types_compatible_p (__typeof (+(X)), double) \
674 || __builtin_types_compatible_p (__typeof (+(X)), float) \
675 || !__floating_type (__typeof (+(X))))
678 # if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128
679 # if !__HAVE_BUILTIN_TGMATH
680 # define __TGMATH_1_NARROW_F32(F, X) \
681 (__extension__ (sizeof ((__tgmath_real_type (X)) 0) > sizeof (_Float64) \
682 ? __TGMATH_F128LD ((X), F, (X)) \
685 # define __TGMATH_2_NARROW_F32(F, X, Y) \
686 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
687 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
688 ? __TGMATH_F128LD ((X) + (Y), F, (X, Y)) \
691 # define __TGMATH_3_NARROW_F32(F, X, Y, Z) \
692 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
693 + (__tgmath_real_type (Y)) 0 \
694 + (__tgmath_real_type (Z)) 0) > sizeof (_Float64) \
695 ? __TGMATH_F128LD ((X) + (Y) + (Z), F, (X, Y, Z)) \
696 F ## f64x (X, Y, Z) \
697 : F ## f64 (X, Y, Z)))
698 # define __TGMATH_1_NARROW_F64(F, X) \
699 (__extension__ (sizeof ((__tgmath_real_type (X)) 0) > sizeof (_Float64) \
700 ? __TGMATH_F128LD ((X), F, (X)) \
703 # define __TGMATH_2_NARROW_F64(F, X, Y) \
704 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
705 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
706 ? __TGMATH_F128LD ((X) + (Y), F, (X, Y)) \
709 # define __TGMATH_3_NARROW_F64(F, X, Y, Z) \
710 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
711 + (__tgmath_real_type (Y)) 0 \
712 + (__tgmath_real_type (Z)) 0) > sizeof (_Float64) \
713 ? __TGMATH_F128LD ((X) + (Y) + (Z), F, (X, Y, Z)) \
714 F ## f64x (X, Y, Z) \
715 : F ## f128 (X, Y, Z)))
717 # if !__HAVE_BUILTIN_TGMATH_C2X
718 # define __TGMATH_1_NARROW_F32X(F, X) \
719 (__extension__ (sizeof ((__tgmath_real_type (X)) 0) > sizeof (_Float64) \
720 || __TGMATH_NARROW_F32X_USE_F64X (X) \
721 ? __TGMATH_F128 ((X), F, (X)) \
724 # define __TGMATH_2_NARROW_F32X(F, X, Y) \
725 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
726 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
727 || __TGMATH_NARROW_F32X_USE_F64X ((X) + (Y)) \
728 ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
731 # define __TGMATH_3_NARROW_F32X(F, X, Y, Z) \
732 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
733 + (__tgmath_real_type (Y)) 0 \
734 + (__tgmath_real_type (Z)) 0) > sizeof (_Float64) \
735 || __TGMATH_NARROW_F32X_USE_F64X ((X) + (Y) + (Z)) \
736 ? __TGMATH_F128 ((X) + (Y) + (Z), F, (X, Y, Z)) \
737 F ## f64x (X, Y, Z) \
738 : F ## f64 (X, Y, Z)))
740 # elif __HAVE_FLOAT128
741 # if !__HAVE_BUILTIN_TGMATH
742 # define __TGMATH_1_NARROW_F32(F, X) \
743 (__extension__ (sizeof ((__tgmath_real_type (X)) 0) > sizeof (_Float64) \
746 # define __TGMATH_2_NARROW_F32(F, X, Y) \
747 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
748 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
751 # define __TGMATH_3_NARROW_F32(F, X, Y, Z) \
752 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
753 + (__tgmath_real_type (Y)) 0 \
754 + (__tgmath_real_type (Z)) 0) > sizeof (_Float64) \
755 ? F ## f128 (X, Y, Z) \
756 : F ## f64 (X, Y, Z)))
757 # define __TGMATH_1_NARROW_F64(F, X) \
759 # define __TGMATH_2_NARROW_F64(F, X, Y) \
761 # define __TGMATH_3_NARROW_F64(F, X, Y, Z) \
762 (F ## f128 (X, Y, Z))
764 # if !__HAVE_BUILTIN_TGMATH_C2X
765 # define __TGMATH_1_NARROW_F32X(F, X) \
766 (__extension__ (sizeof ((__tgmath_real_type (X)) 0) > sizeof (_Float32x) \
767 || __TGMATH_NARROW_F32X_USE_F64X (X) \
770 # define __TGMATH_2_NARROW_F32X(F, X, Y) \
771 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
772 + (__tgmath_real_type (Y)) 0) > sizeof (_Float32x) \
773 || __TGMATH_NARROW_F32X_USE_F64X ((X) + (Y)) \
776 # define __TGMATH_3_NARROW_F32X(F, X, Y, Z) \
777 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
778 + (__tgmath_real_type (Y)) 0 \
779 + (__tgmath_real_type (Z)) 0) > sizeof (_Float32x) \
780 || __TGMATH_NARROW_F32X_USE_F64X ((X) + (Y) + (Z)) \
781 ? F ## f64x (X, Y, Z) \
782 : F ## f64 (X, Y, Z)))
785 # if !__HAVE_BUILTIN_TGMATH
786 # define __TGMATH_1_NARROW_F32(F, X) \
788 # define __TGMATH_2_NARROW_F32(F, X, Y) \
790 # define __TGMATH_3_NARROW_F32(F, X, Y, Z) \
795 # error "Unsupported compiler; you cannot use <tgmath.h>"
799 /* Unary functions defined for real and complex values. */
802 /* Trigonometric functions. */
804 /* Arc cosine of X. */
805 #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
807 #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
808 /* Arc tangent of X. */
809 #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
810 /* Arc tangent of Y/X. */
811 #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
814 #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
816 #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
818 #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
821 /* Hyperbolic functions. */
823 /* Hyperbolic arc cosine of X. */
824 #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
825 /* Hyperbolic arc sine of X. */
826 #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
827 /* Hyperbolic arc tangent of X. */
828 #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
830 /* Hyperbolic cosine of X. */
831 #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
832 /* Hyperbolic sine of X. */
833 #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
834 /* Hyperbolic tangent of X. */
835 #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
838 /* Exponential and logarithmic functions. */
840 /* Exponential function of X. */
841 #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
843 /* Break VALUE into a normalized fraction and an integral power of 2. */
844 #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
846 /* X times (two to the EXP power). */
847 #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
849 /* Natural logarithm of X. */
850 #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
852 /* Base-ten logarithm of X. */
854 # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10)
856 # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
859 /* Return exp(X) - 1. */
860 #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
862 /* Return log(1 + X). */
863 #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
865 /* Return the base 2 signed integral exponent of X. */
866 #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
868 /* Compute base-2 exponential of X. */
869 #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
871 /* Compute base-2 logarithm of X. */
872 #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
874 #if __GLIBC_USE (IEC_60559_FUNCS_EXT_C2X)
875 /* Compute exponent to base ten. */
876 #define exp10(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp10)
880 /* Power functions. */
882 /* Return X to the Y power. */
883 #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
885 /* Return the square root of X. */
886 #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
888 /* Return `sqrt(X*X + Y*Y)'. */
889 #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
891 /* Return the cube root of X. */
892 #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
895 /* Nearest integer, absolute value, and remainder functions. */
897 /* Smallest integral value not less than X. */
898 #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
900 /* Absolute value of X. */
901 #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
903 /* Largest integer not greater than X. */
904 #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
906 /* Floating-point modulo remainder of X/Y. */
907 #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
909 /* Round X to integral valuein floating-point format using current
910 rounding direction, but do not raise inexact exception. */
911 #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
913 /* Round X to nearest integral value, rounding halfway cases away from
915 #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
917 /* Round X to the integral value in floating-point format nearest but
918 not larger in magnitude. */
919 #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
921 /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
922 and magnitude congruent `mod 2^n' to the magnitude of the integral
923 quotient x/y, with n >= 3. */
924 #define remquo(Val1, Val2, Val3) \
925 __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
927 /* Round X to nearest integral value according to current rounding
929 #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint)
930 #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint)
932 /* Round X to nearest integral value, rounding halfway cases away from
934 #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround)
935 #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround)
938 /* Return X with its signed changed to Y's. */
939 #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
941 /* Error and gamma functions. */
942 #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
943 #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
944 #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
945 #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
948 /* Return the integer nearest X in the direction of the
949 prevailing rounding mode. */
950 #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
952 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
953 /* Return X - epsilon. */
954 # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
955 /* Return X + epsilon. */
956 # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
959 /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
960 #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
961 #define nexttoward(Val1, Val2) \
962 __TGMATH_BINARY_FIRST_REAL_STD_ONLY (Val1, Val2, nexttoward)
964 /* Return the remainder of integer division X / Y with infinite precision. */
965 #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
967 /* Return X times (2 to the Nth power). */
969 # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, scalb)
972 /* Return X times (2 to the Nth power). */
973 #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
975 /* Return X times (2 to the Nth power). */
976 #define scalbln(Val1, Val2) \
977 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
979 /* Return the binary exponent of X, which must be nonzero. */
980 #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb)
983 /* Return positive difference between X and Y. */
984 #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
986 #if __GLIBC_USE (ISOC2X) && !defined __USE_GNU
987 /* Return maximum numeric value from X and Y. */
988 # define fmax(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, fmax)
990 /* Return minimum numeric value from X and Y. */
991 # define fmin(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, fmin)
993 /* Return maximum numeric value from X and Y. */
994 # define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
996 /* Return minimum numeric value from X and Y. */
997 # define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
1001 /* Multiply-add function computed as a ternary operation. */
1002 #define fma(Val1, Val2, Val3) \
1003 __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
1005 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
1006 /* Round X to nearest integer value, rounding halfway cases to even. */
1007 # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
1009 # define fromfp(Val1, Val2, Val3) \
1010 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp)
1012 # define ufromfp(Val1, Val2, Val3) \
1013 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp)
1015 # define fromfpx(Val1, Val2, Val3) \
1016 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx)
1018 # define ufromfpx(Val1, Val2, Val3) \
1019 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx)
1021 /* Like ilogb, but returning long int. */
1022 # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb)
1025 #if __GLIBC_USE (IEC_60559_BFP_EXT)
1026 /* Return value with maximum magnitude. */
1027 # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
1029 /* Return value with minimum magnitude. */
1030 # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
1033 #if __GLIBC_USE (ISOC2X)
1034 /* Return maximum value from X and Y. */
1035 # define fmaximum(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum)
1037 /* Return minimum value from X and Y. */
1038 # define fminimum(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum)
1040 /* Return maximum numeric value from X and Y. */
1041 # define fmaximum_num(Val1, Val2) \
1042 __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum_num)
1044 /* Return minimum numeric value from X and Y. */
1045 # define fminimum_num(Val1, Val2) \
1046 __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum_num)
1048 /* Return value with maximum magnitude. */
1049 # define fmaximum_mag(Val1, Val2) \
1050 __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum_mag)
1052 /* Return value with minimum magnitude. */
1053 # define fminimum_mag(Val1, Val2) \
1054 __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum_mag)
1056 /* Return numeric value with maximum magnitude. */
1057 # define fmaximum_mag_num(Val1, Val2) \
1058 __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaximum_mag_num)
1060 /* Return numeric value with minimum magnitude. */
1061 # define fminimum_mag_num(Val1, Val2) \
1062 __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminimum_mag_num)
1066 /* Absolute value, conjugates, and projection. */
1068 /* Argument value of Z. */
1069 #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, carg)
1071 /* Complex conjugate of Z. */
1072 #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
1074 /* Projection of Z onto the Riemann sphere. */
1075 #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
1078 /* Decomposing complex values. */
1080 /* Imaginary part of Z. */
1081 #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, cimag)
1083 /* Real part of Z. */
1084 #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, creal)
1087 /* Narrowing functions. */
1089 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
1092 # define fadd(Val1, Val2) __TGMATH_2_NARROW_F (fadd, Val1, Val2)
1093 # define dadd(Val1, Val2) __TGMATH_2_NARROW_D (dadd, Val1, Val2)
1096 # define fdiv(Val1, Val2) __TGMATH_2_NARROW_F (fdiv, Val1, Val2)
1097 # define ddiv(Val1, Val2) __TGMATH_2_NARROW_D (ddiv, Val1, Val2)
1100 # define fmul(Val1, Val2) __TGMATH_2_NARROW_F (fmul, Val1, Val2)
1101 # define dmul(Val1, Val2) __TGMATH_2_NARROW_D (dmul, Val1, Val2)
1104 # define fsub(Val1, Val2) __TGMATH_2_NARROW_F (fsub, Val1, Val2)
1105 # define dsub(Val1, Val2) __TGMATH_2_NARROW_D (dsub, Val1, Val2)
1108 # define fsqrt(Val) __TGMATH_1_NARROW_F (fsqrt, Val)
1109 # define dsqrt(Val) __TGMATH_1_NARROW_D (dsqrt, Val)
1111 /* Fused multiply-add. */
1112 # define ffma(Val1, Val2, Val3) __TGMATH_3_NARROW_F (ffma, Val1, Val2, Val3)
1113 # define dfma(Val1, Val2, Val3) __TGMATH_3_NARROW_D (dfma, Val1, Val2, Val3)
1117 #if __GLIBC_USE (IEC_60559_TYPES_EXT)
1120 # define f16add(Val1, Val2) __TGMATH_2_NARROW_F16 (f16add, Val1, Val2)
1121 # define f16div(Val1, Val2) __TGMATH_2_NARROW_F16 (f16div, Val1, Val2)
1122 # define f16mul(Val1, Val2) __TGMATH_2_NARROW_F16 (f16mul, Val1, Val2)
1123 # define f16sub(Val1, Val2) __TGMATH_2_NARROW_F16 (f16sub, Val1, Val2)
1124 # define f16sqrt(Val) __TGMATH_1_NARROW_F16 (f16sqrt, Val)
1125 # define f16fma(Val1, Val2, Val3) \
1126 __TGMATH_3_NARROW_F16 (f16fma, Val1, Val2, Val3)
1130 # define f32add(Val1, Val2) __TGMATH_2_NARROW_F32 (f32add, Val1, Val2)
1131 # define f32div(Val1, Val2) __TGMATH_2_NARROW_F32 (f32div, Val1, Val2)
1132 # define f32mul(Val1, Val2) __TGMATH_2_NARROW_F32 (f32mul, Val1, Val2)
1133 # define f32sub(Val1, Val2) __TGMATH_2_NARROW_F32 (f32sub, Val1, Val2)
1134 # define f32sqrt(Val) __TGMATH_1_NARROW_F32 (f32sqrt, Val)
1135 # define f32fma(Val1, Val2, Val3) \
1136 __TGMATH_3_NARROW_F32 (f32fma, Val1, Val2, Val3)
1139 # if __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)
1140 # define f64add(Val1, Val2) __TGMATH_2_NARROW_F64 (f64add, Val1, Val2)
1141 # define f64div(Val1, Val2) __TGMATH_2_NARROW_F64 (f64div, Val1, Val2)
1142 # define f64mul(Val1, Val2) __TGMATH_2_NARROW_F64 (f64mul, Val1, Val2)
1143 # define f64sub(Val1, Val2) __TGMATH_2_NARROW_F64 (f64sub, Val1, Val2)
1144 # define f64sqrt(Val) __TGMATH_1_NARROW_F64 (f64sqrt, Val)
1145 # define f64fma(Val1, Val2, Val3) \
1146 __TGMATH_3_NARROW_F64 (f64fma, Val1, Val2, Val3)
1149 # if __HAVE_FLOAT32X
1150 # define f32xadd(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xadd, Val1, Val2)
1151 # define f32xdiv(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xdiv, Val1, Val2)
1152 # define f32xmul(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xmul, Val1, Val2)
1153 # define f32xsub(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xsub, Val1, Val2)
1154 # define f32xsqrt(Val) __TGMATH_1_NARROW_F32X (f32xsqrt, Val)
1155 # define f32xfma(Val1, Val2, Val3) \
1156 __TGMATH_3_NARROW_F32X (f32xfma, Val1, Val2, Val3)
1159 # if __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)
1160 # define f64xadd(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xadd, Val1, Val2)
1161 # define f64xdiv(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xdiv, Val1, Val2)
1162 # define f64xmul(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xmul, Val1, Val2)
1163 # define f64xsub(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xsub, Val1, Val2)
1164 # define f64xsqrt(Val) __TGMATH_1_NARROW_F64X (f64xsqrt, Val)
1165 # define f64xfma(Val1, Val2, Val3) \
1166 __TGMATH_3_NARROW_F64X (f64xfma, Val1, Val2, Val3)
1171 #endif /* tgmath.h */