]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/tgmath.h
Improve the accuracy of tgamma (BZ #26983)
[thirdparty/glibc.git] / math / tgmath.h
CommitLineData
2b778ceb 1/* Copyright (C) 1997-2021 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 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://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
f9fabc1b
JM
46/* Certain cases of narrowing macros only need to call a single
47 function so cannot use __builtin_tgmath and do not need any
48 complicated logic. */
49# if __HAVE_FLOAT128X
50# error "Unsupported _Float128x type for <tgmath.h>."
51# endif
52# if ((__HAVE_FLOAT64X && !__HAVE_FLOAT128) \
53 || (__HAVE_FLOAT128 && !__HAVE_FLOAT64X))
54# error "Unsupported combination of types for <tgmath.h>."
55# endif
56# define __TGMATH_2_NARROW_D(F, X, Y) \
57 (F ## l (X, Y))
58# define __TGMATH_2_NARROW_F64X(F, X, Y) \
59 (F ## f128 (X, Y))
60# if !__HAVE_FLOAT128
61# define __TGMATH_2_NARROW_F32X(F, X, Y) \
62 (F ## f64 (X, Y))
63# endif
64
be3a79a3 65# if __HAVE_BUILTIN_TGMATH
0d3fee40 66
be3a79a3
JM
67# if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
68# define __TG_F16_ARG(X) X ## f16,
69# else
70# define __TG_F16_ARG(X)
71# endif
72# if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
73# define __TG_F32_ARG(X) X ## f32,
74# else
75# define __TG_F32_ARG(X)
76# endif
77# if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
78# define __TG_F64_ARG(X) X ## f64,
79# else
80# define __TG_F64_ARG(X)
81# endif
82# if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
83# define __TG_F128_ARG(X) X ## f128,
84# else
85# define __TG_F128_ARG(X)
86# endif
87# if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
88# define __TG_F32X_ARG(X) X ## f32x,
89# else
90# define __TG_F32X_ARG(X)
91# endif
92# if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
93# define __TG_F64X_ARG(X) X ## f64x,
94# else
95# define __TG_F64X_ARG(X)
96# endif
97# if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
98# define __TG_F128X_ARG(X) X ## f128x,
99# else
100# define __TG_F128X_ARG(X)
101# endif
102
103# define __TGMATH_FUNCS(X) X ## f, X, X ## l, \
104 __TG_F16_ARG (X) __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \
105 __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
106# define __TGMATH_RCFUNCS(F, C) __TGMATH_FUNCS (F) __TGMATH_FUNCS (C)
107# define __TGMATH_1(F, X) __builtin_tgmath (__TGMATH_FUNCS (F) (X))
108# define __TGMATH_2(F, X, Y) __builtin_tgmath (__TGMATH_FUNCS (F) (X), (Y))
109# define __TGMATH_2STD(F, X, Y) __builtin_tgmath (F ## f, F, F ## l, (X), (Y))
110# define __TGMATH_3(F, X, Y, Z) __builtin_tgmath (__TGMATH_FUNCS (F) \
111 (X), (Y), (Z))
112# define __TGMATH_1C(F, C, X) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) (X))
113# define __TGMATH_2C(F, C, X, Y) __builtin_tgmath (__TGMATH_RCFUNCS (F, C) \
114 (X), (Y))
115
f9fabc1b
JM
116# define __TGMATH_NARROW_FUNCS_F(X) X, X ## l,
117# define __TGMATH_NARROW_FUNCS_F16(X) \
118 __TG_F32_ARG (X) __TG_F64_ARG (X) __TG_F128_ARG (X) \
119 __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
120# define __TGMATH_NARROW_FUNCS_F32(X) \
121 __TG_F64_ARG (X) __TG_F128_ARG (X) \
122 __TG_F32X_ARG (X) __TG_F64X_ARG (X) __TG_F128X_ARG (X)
123# define __TGMATH_NARROW_FUNCS_F64(X) \
124 __TG_F128_ARG (X) \
125 __TG_F64X_ARG (X) __TG_F128X_ARG (X)
126# define __TGMATH_NARROW_FUNCS_F32X(X) \
127 __TG_F64X_ARG (X) __TG_F128X_ARG (X) \
128 __TG_F64_ARG (X) __TG_F128_ARG (X)
129
130# define __TGMATH_2_NARROW_F(F, X, Y) \
131 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F (F) (X), (Y))
132# define __TGMATH_2_NARROW_F16(F, X, Y) \
133 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F16 (F) (X), (Y))
134# define __TGMATH_2_NARROW_F32(F, X, Y) \
135 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32 (F) (X), (Y))
136# define __TGMATH_2_NARROW_F64(F, X, Y) \
137 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F64 (F) (X), (Y))
138# if __HAVE_FLOAT128
139# define __TGMATH_2_NARROW_F32X(F, X, Y) \
140 __builtin_tgmath (__TGMATH_NARROW_FUNCS_F32X (F) (X), (Y))
141# endif
142
be3a79a3
JM
143# else /* !__HAVE_BUILTIN_TGMATH. */
144
145# ifdef __NO_LONG_DOUBLE_MATH
146# define __tgml(fct) fct
147# else
148# define __tgml(fct) fct ## l
149# endif
925e31d9 150
d9bef9c0
JM
151/* __floating_type expands to 1 if TYPE is a floating type (including
152 complex floating types), 0 if TYPE is an integer type (including
153 complex integer types). __real_integer_type expands to 1 if TYPE
154 is a real integer type. __complex_integer_type expands to 1 if
155 TYPE is a complex integer type. All these macros expand to integer
156 constant expressions. All these macros can assume their argument
157 has an arithmetic type (not vector, decimal floating-point or
158 fixed-point), valid to pass to tgmath.h macros. */
be3a79a3 159# if __GNUC_PREREQ (3, 1)
d9bef9c0
JM
160/* __builtin_classify_type expands to an integer constant expression
161 in GCC 3.1 and later. Default conversions applied to the argument
162 of __builtin_classify_type mean it always returns 1 for real
163 integer types rather than ever returning different values for
164 character, boolean or enumerated types. */
be3a79a3 165# define __floating_type(type) \
d9bef9c0 166 (__builtin_classify_type (__real__ ((type) 0)) == 8)
be3a79a3 167# define __real_integer_type(type) \
d9bef9c0 168 (__builtin_classify_type ((type) 0) == 1)
be3a79a3 169# define __complex_integer_type(type) \
d9bef9c0
JM
170 (__builtin_classify_type ((type) 0) == 9 \
171 && __builtin_classify_type (__real__ ((type) 0)) == 1)
be3a79a3 172# else
d9bef9c0
JM
173/* GCC versions predating __builtin_classify_type are also looser on
174 what counts as an integer constant expression. */
be3a79a3
JM
175# define __floating_type(type) (((type) 1.25) != 1)
176# define __real_integer_type(type) (((type) (1.25 + _Complex_I)) == 1)
177# define __complex_integer_type(type) \
d9bef9c0 178 (((type) (1.25 + _Complex_I)) == (1 + _Complex_I))
be3a79a3 179# endif
925e31d9 180
d9bef9c0 181/* Whether an expression (of arithmetic type) has a real type. */
be3a79a3 182# define __expr_is_real(E) (__builtin_classify_type (E) != 9)
d9bef9c0
JM
183
184/* The tgmath real type for T, where E is 0 if T is an integer type
185 and 1 for a floating type. If T has a complex type, it is
186 unspecified whether the return type is real or complex (but it has
187 the correct corresponding real type). */
be3a79a3 188# define __tgmath_real_type_sub(T, E) \
1c298d08
UD
189 __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
190 : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
925e31d9
UD
191
192/* The tgmath real type of EXPR. */
be3a79a3 193# define __tgmath_real_type(expr) \
2fee621d
JM
194 __tgmath_real_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
195 __floating_type (__typeof__ (+(expr))))
925e31d9 196
d9bef9c0
JM
197/* The tgmath complex type for T, where E1 is 1 if T has a floating
198 type and 0 otherwise, E2 is 1 if T has a real integer type and 0
199 otherwise, and E3 is 1 if T has a complex type and 0 otherwise. */
be3a79a3 200# define __tgmath_complex_type_sub(T, E1, E2, E3) \
d9bef9c0
JM
201 __typeof__ (*(0 \
202 ? (__typeof__ (0 ? (T *) 0 : (void *) (!(E1)))) 0 \
203 : (__typeof__ (0 \
204 ? (__typeof__ (0 \
205 ? (double *) 0 \
206 : (void *) (!(E2)))) 0 \
207 : (__typeof__ (0 \
208 ? (_Complex double *) 0 \
209 : (void *) (!(E3)))) 0)) 0))
210
211/* The tgmath complex type of EXPR. */
be3a79a3 212# define __tgmath_complex_type(expr) \
d9bef9c0
JM
213 __tgmath_complex_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
214 __floating_type (__typeof__ (+(expr))), \
215 __real_integer_type (__typeof__ (+(expr))), \
216 __complex_integer_type (__typeof__ (+(expr))))
217
be3a79a3 218# if (__HAVE_DISTINCT_FLOAT16 \
86ec4865
JM
219 || __HAVE_DISTINCT_FLOAT32 \
220 || __HAVE_DISTINCT_FLOAT64 \
221 || __HAVE_DISTINCT_FLOAT32X \
222 || __HAVE_DISTINCT_FLOAT64X \
223 || __HAVE_DISTINCT_FLOAT128X)
be3a79a3
JM
224# error "Unsupported _FloatN or _FloatNx types for <tgmath.h>."
225# endif
86ec4865 226
614d15f9
JM
227/* Expand to text that checks if ARG_COMB has type _Float128, and if
228 so calls the appropriately suffixed FCT (which may include a cast),
229 or FCT and CFCT for complex functions, with arguments ARG_CALL. */
be3a79a3
JM
230# if __HAVE_DISTINCT_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
231# if (!__HAVE_FLOAT64X \
86ec4865
JM
232 || __HAVE_FLOAT64X_LONG_DOUBLE \
233 || !__HAVE_FLOATN_NOT_TYPEDEF)
be3a79a3 234# define __TGMATH_F128(arg_comb, fct, arg_call) \
2fee621d 235 __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
614d15f9 236 ? fct ## f128 arg_call :
be3a79a3 237# define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
2fee621d 238 __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
d9bef9c0 239 ? (__expr_is_real (arg_comb) \
614d15f9
JM
240 ? fct ## f128 arg_call \
241 : cfct ## f128 arg_call) :
be3a79a3 242# else
86ec4865
JM
243/* _Float64x is a distinct type at the C language level, which must be
244 handled like _Float128. */
be3a79a3 245# define __TGMATH_F128(arg_comb, fct, arg_call) \
86ec4865
JM
246 (__builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
247 || __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float64x)) \
248 ? fct ## f128 arg_call :
be3a79a3 249# define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
86ec4865
JM
250 (__builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
251 || __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), \
252 _Float64x)) \
253 ? (__expr_is_real (arg_comb) \
254 ? fct ## f128 arg_call \
255 : cfct ## f128 arg_call) :
be3a79a3
JM
256# endif
257# else
258# define __TGMATH_F128(arg_comb, fct, arg_call) /* Nothing. */
259# define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) /* Nothing. */
86ec4865 260# endif
614d15f9 261
be3a79a3 262# endif /* !__HAVE_BUILTIN_TGMATH. */
925e31d9 263
dfd2257a
UD
264/* We have two kinds of generic macros: to support functions which are
265 only defined on real valued parameters and those which are defined
266 for complex functions as well. */
be3a79a3
JM
267# if __HAVE_BUILTIN_TGMATH
268
269# define __TGMATH_UNARY_REAL_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val))
270# define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) __TGMATH_1 (Fct, (Val))
271# define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
272 __TGMATH_2 (Fct, (Val1), (Val2))
273# define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
274 __TGMATH_2STD (Fct, (Val1), (Val2))
275# define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
276 __TGMATH_2 (Fct, (Val1), (Val2))
277# define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
278 __TGMATH_2STD (Fct, (Val1), (Val2))
be3a79a3
JM
279# define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
280 __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
281# define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
282 __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
283# define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
284 __TGMATH_3 (Fct, (Val1), (Val2), (Val3))
285# define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
286 __TGMATH_1C (Fct, Cfct, (Val))
287# define __TGMATH_UNARY_IMAG(Val, Cfct) __TGMATH_1 (Cfct, (Val))
288# define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
289 __TGMATH_1C (Fct, Cfct, (Val))
290# define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \
291 __TGMATH_1 (Cfct, (Val))
292# define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
293 __TGMATH_2C (Fct, Cfct, (Val1), (Val2))
294
295# else /* !__HAVE_BUILTIN_TGMATH. */
296
297# define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
2fee621d 298 (__extension__ ((sizeof (+(Val)) == sizeof (double) \
1c298d08
UD
299 || __builtin_classify_type (Val) != 8) \
300 ? (__tgmath_real_type (Val)) Fct (Val) \
2fee621d 301 : (sizeof (+(Val)) == sizeof (float)) \
1c298d08 302 ? (__tgmath_real_type (Val)) Fct##f (Val) \
614d15f9
JM
303 : __TGMATH_F128 ((Val), (__tgmath_real_type (Val)) Fct, \
304 (Val)) \
305 (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
71502ebe 306
be3a79a3 307# define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \
2fee621d 308 (__extension__ ((sizeof (+(Val)) == sizeof (double) \
1c298d08 309 || __builtin_classify_type (Val) != 8) \
cfa44345 310 ? Fct (Val) \
2fee621d 311 : (sizeof (+(Val)) == sizeof (float)) \
cfa44345 312 ? Fct##f (Val) \
614d15f9
JM
313 : __TGMATH_F128 ((Val), Fct, (Val)) \
314 __tgml(Fct) (Val)))
dfd2257a 315
be3a79a3 316# define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
2fee621d 317 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
614d15f9
JM
318 || __builtin_classify_type (Val1) != 8) \
319 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
2fee621d 320 : (sizeof (+(Val1)) == sizeof (float)) \
614d15f9
JM
321 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
322 : __TGMATH_F128 ((Val1), (__tgmath_real_type (Val1)) Fct, \
323 (Val1, Val2)) \
324 (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
325
be3a79a3 326# define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
2fee621d 327 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
1c298d08
UD
328 || __builtin_classify_type (Val1) != 8) \
329 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
2fee621d 330 : (sizeof (+(Val1)) == sizeof (float)) \
1c298d08
UD
331 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
332 : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
dfd2257a 333
be3a79a3 334# define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
42df8d59 335 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
1c298d08 336 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
614d15f9
JM
337 ? __TGMATH_F128 ((Val1) + (Val2), \
338 (__typeof \
339 ((__tgmath_real_type (Val1)) 0 \
340 + (__tgmath_real_type (Val2)) 0)) Fct, \
341 (Val1, Val2)) \
342 (__typeof ((__tgmath_real_type (Val1)) 0 \
343 + (__tgmath_real_type (Val2)) 0)) \
344 __tgml(Fct) (Val1, Val2) \
2fee621d
JM
345 : (sizeof (+(Val1)) == sizeof (double) \
346 || sizeof (+(Val2)) == sizeof (double) \
614d15f9
JM
347 || __builtin_classify_type (Val1) != 8 \
348 || __builtin_classify_type (Val2) != 8) \
1c298d08
UD
349 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
350 + (__tgmath_real_type (Val2)) 0)) \
614d15f9
JM
351 Fct (Val1, Val2) \
352 : (__typeof ((__tgmath_real_type (Val1)) 0 \
353 + (__tgmath_real_type (Val2)) 0)) \
354 Fct##f (Val1, Val2)))
355
be3a79a3 356# define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
42df8d59 357 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
614d15f9
JM
358 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
359 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
360 + (__tgmath_real_type (Val2)) 0)) \
1c298d08 361 __tgml(Fct) (Val1, Val2) \
2fee621d
JM
362 : (sizeof (+(Val1)) == sizeof (double) \
363 || sizeof (+(Val2)) == sizeof (double) \
1c298d08
UD
364 || __builtin_classify_type (Val1) != 8 \
365 || __builtin_classify_type (Val2) != 8) \
366 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
367 + (__tgmath_real_type (Val2)) 0)) \
368 Fct (Val1, Val2) \
369 : (__typeof ((__tgmath_real_type (Val1)) 0 \
370 + (__tgmath_real_type (Val2)) 0)) \
371 Fct##f (Val1, Val2)))
dfd2257a 372
be3a79a3 373# define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
42df8d59 374 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
1c298d08 375 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
614d15f9
JM
376 ? __TGMATH_F128 ((Val1) + (Val2), \
377 (__typeof \
378 ((__tgmath_real_type (Val1)) 0 \
379 + (__tgmath_real_type (Val2)) 0)) Fct, \
380 (Val1, Val2, Val3)) \
381 (__typeof ((__tgmath_real_type (Val1)) 0 \
382 + (__tgmath_real_type (Val2)) 0)) \
383 __tgml(Fct) (Val1, Val2, Val3) \
2fee621d
JM
384 : (sizeof (+(Val1)) == sizeof (double) \
385 || sizeof (+(Val2)) == sizeof (double) \
1c298d08
UD
386 || __builtin_classify_type (Val1) != 8 \
387 || __builtin_classify_type (Val2) != 8) \
388 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
389 + (__tgmath_real_type (Val2)) 0)) \
390 Fct (Val1, Val2, Val3) \
391 : (__typeof ((__tgmath_real_type (Val1)) 0 \
392 + (__tgmath_real_type (Val2)) 0)) \
393 Fct##f (Val1, Val2, Val3)))
bfce746a 394
be3a79a3 395# define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
42df8d59 396 (__extension__ ((sizeof ((Val1) + (Val2) + (Val3)) > sizeof (double) \
1c298d08
UD
397 && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
398 == 8) \
614d15f9
JM
399 ? __TGMATH_F128 ((Val1) + (Val2) + (Val3), \
400 (__typeof \
401 ((__tgmath_real_type (Val1)) 0 \
402 + (__tgmath_real_type (Val2)) 0 \
403 + (__tgmath_real_type (Val3)) 0)) Fct, \
404 (Val1, Val2, Val3)) \
405 (__typeof ((__tgmath_real_type (Val1)) 0 \
406 + (__tgmath_real_type (Val2)) 0 \
407 + (__tgmath_real_type (Val3)) 0)) \
1c298d08 408 __tgml(Fct) (Val1, Val2, Val3) \
2fee621d
JM
409 : (sizeof (+(Val1)) == sizeof (double) \
410 || sizeof (+(Val2)) == sizeof (double) \
411 || sizeof (+(Val3)) == sizeof (double) \
1c298d08
UD
412 || __builtin_classify_type (Val1) != 8 \
413 || __builtin_classify_type (Val2) != 8 \
414 || __builtin_classify_type (Val3) != 8) \
415 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
416 + (__tgmath_real_type (Val2)) 0 \
417 + (__tgmath_real_type (Val3)) 0)) \
418 Fct (Val1, Val2, Val3) \
419 : (__typeof ((__tgmath_real_type (Val1)) 0 \
420 + (__tgmath_real_type (Val2)) 0 \
421 + (__tgmath_real_type (Val3)) 0)) \
422 Fct##f (Val1, Val2, Val3)))
dfd2257a 423
be3a79a3 424# define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
2fee621d 425 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
423c2b9d 426 || __builtin_classify_type (Val1) != 8) \
cfa44345 427 ? Fct (Val1, Val2, Val3) \
2fee621d 428 : (sizeof (+(Val1)) == sizeof (float)) \
cfa44345 429 ? Fct##f (Val1, Val2, Val3) \
614d15f9
JM
430 : __TGMATH_F128 ((Val1), Fct, (Val1, Val2, Val3)) \
431 __tgml(Fct) (Val1, Val2, Val3)))
423c2b9d 432
48244d09
UD
433/* XXX This definition has to be changed as soon as the compiler understands
434 the imaginary keyword. */
be3a79a3 435# define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
2fee621d 436 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
1c298d08 437 || __builtin_classify_type (__real__ (Val)) != 8) \
d9bef9c0
JM
438 ? (__expr_is_real (Val) \
439 ? (__tgmath_complex_type (Val)) Fct (Val) \
440 : (__tgmath_complex_type (Val)) Cfct (Val)) \
2fee621d 441 : (sizeof (+__real__ (Val)) == sizeof (float)) \
d9bef9c0
JM
442 ? (__expr_is_real (Val) \
443 ? (__tgmath_complex_type (Val)) Fct##f (Val) \
444 : (__tgmath_complex_type (Val)) Cfct##f (Val)) \
445 : __TGMATH_CF128 ((Val), \
446 (__tgmath_complex_type (Val)) Fct, \
447 (__tgmath_complex_type (Val)) Cfct, \
614d15f9 448 (Val)) \
d9bef9c0
JM
449 (__expr_is_real (Val) \
450 ? (__tgmath_complex_type (Val)) __tgml(Fct) (Val) \
451 : (__tgmath_complex_type (Val)) __tgml(Cfct) (Val))))
1c298d08 452
be3a79a3 453# define __TGMATH_UNARY_IMAG(Val, Cfct) \
2fee621d 454 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
1c298d08
UD
455 || __builtin_classify_type (__real__ (Val)) != 8) \
456 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
457 + _Complex_I)) Cfct (Val) \
2fee621d 458 : (sizeof (+__real__ (Val)) == sizeof (float)) \
1c298d08
UD
459 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
460 + _Complex_I)) Cfct##f (Val) \
614d15f9
JM
461 : __TGMATH_F128 (__real__ (Val), \
462 (__typeof__ \
463 ((__tgmath_real_type (Val)) 0 \
464 + _Complex_I)) Cfct, (Val)) \
465 (__typeof__ ((__tgmath_real_type (Val)) 0 \
466 + _Complex_I)) __tgml(Cfct) (Val)))
dfd2257a 467
58d87ee1
UD
468/* XXX This definition has to be changed as soon as the compiler understands
469 the imaginary keyword. */
be3a79a3 470# define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
2fee621d 471 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
1c298d08 472 || __builtin_classify_type (__real__ (Val)) != 8) \
d9bef9c0 473 ? (__expr_is_real (Val) \
1c298d08
UD
474 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
475 Fct (Val) \
476 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
477 Cfct (Val)) \
2fee621d 478 : (sizeof (+__real__ (Val)) == sizeof (float)) \
d9bef9c0 479 ? (__expr_is_real (Val) \
1c298d08
UD
480 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
481 Fct##f (Val) \
482 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
483 Cfct##f (Val)) \
614d15f9
JM
484 : __TGMATH_CF128 ((Val), \
485 (__typeof__ \
486 (__real__ \
487 (__tgmath_real_type (Val)) 0)) Fct, \
488 (__typeof__ \
489 (__real__ \
490 (__tgmath_real_type (Val)) 0)) Cfct, \
491 (Val)) \
d9bef9c0 492 (__expr_is_real (Val) \
614d15f9
JM
493 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
494 __tgml(Fct) (Val) \
495 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
496 __tgml(Cfct) (Val))))
be3a79a3
JM
497# define __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME(Val, Cfct) \
498 __TGMATH_UNARY_REAL_IMAG_RET_REAL ((Val), Cfct, Cfct)
58d87ee1 499
48244d09
UD
500/* XXX This definition has to be changed as soon as the compiler understands
501 the imaginary keyword. */
be3a79a3 502# define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
42df8d59
JM
503 (__extension__ ((sizeof (__real__ (Val1) \
504 + __real__ (Val2)) > sizeof (double) \
1c298d08
UD
505 && __builtin_classify_type (__real__ (Val1) \
506 + __real__ (Val2)) == 8) \
614d15f9
JM
507 ? __TGMATH_CF128 ((Val1) + (Val2), \
508 (__typeof \
d9bef9c0
JM
509 ((__tgmath_complex_type (Val1)) 0 \
510 + (__tgmath_complex_type (Val2)) 0)) \
614d15f9
JM
511 Fct, \
512 (__typeof \
d9bef9c0
JM
513 ((__tgmath_complex_type (Val1)) 0 \
514 + (__tgmath_complex_type (Val2)) 0)) \
614d15f9
JM
515 Cfct, \
516 (Val1, Val2)) \
d9bef9c0
JM
517 (__expr_is_real ((Val1) + (Val2)) \
518 ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
519 + (__tgmath_complex_type (Val2)) 0)) \
614d15f9 520 __tgml(Fct) (Val1, Val2) \
d9bef9c0
JM
521 : (__typeof ((__tgmath_complex_type (Val1)) 0 \
522 + (__tgmath_complex_type (Val2)) 0)) \
614d15f9 523 __tgml(Cfct) (Val1, Val2)) \
2fee621d
JM
524 : (sizeof (+__real__ (Val1)) == sizeof (double) \
525 || sizeof (+__real__ (Val2)) == sizeof (double) \
1c298d08
UD
526 || __builtin_classify_type (__real__ (Val1)) != 8 \
527 || __builtin_classify_type (__real__ (Val2)) != 8) \
d9bef9c0
JM
528 ? (__expr_is_real ((Val1) + (Val2)) \
529 ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
530 + (__tgmath_complex_type (Val2)) 0)) \
1c298d08 531 Fct (Val1, Val2) \
d9bef9c0
JM
532 : (__typeof ((__tgmath_complex_type (Val1)) 0 \
533 + (__tgmath_complex_type (Val2)) 0)) \
1c298d08 534 Cfct (Val1, Val2)) \
d9bef9c0
JM
535 : (__expr_is_real ((Val1) + (Val2)) \
536 ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
537 + (__tgmath_complex_type (Val2)) 0)) \
1c298d08 538 Fct##f (Val1, Val2) \
d9bef9c0
JM
539 : (__typeof ((__tgmath_complex_type (Val1)) 0 \
540 + (__tgmath_complex_type (Val2)) 0)) \
1c298d08 541 Cfct##f (Val1, Val2))))
f9fabc1b
JM
542
543# define __TGMATH_2_NARROW_F(F, X, Y) \
544 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
545 + (__tgmath_real_type (Y)) 0) > sizeof (double) \
546 ? F ## l (X, Y) \
547 : F (X, Y)))
548/* In most cases, these narrowing macro definitions based on sizeof
549 ensure that the function called has the right argument format, as
550 for other <tgmath.h> macros for compilers before GCC 8, but may not
551 have exactly the argument type (among the types with that format)
552 specified in the standard logic.
553
554 In the case of macros for _Float32x return type, when _Float64x
555 exists, _Float64 arguments should result in the *f64 function being
556 called while _Float32x arguments should result in the *f64x
557 function being called. These cases cannot be distinguished using
558 sizeof (or at all if the types are typedefs rather than different
559 types). However, for these functions it is OK (does not affect the
560 final result) to call a function with any argument format at least
561 as wide as all the floating-point arguments, unless that affects
562 rounding of integer arguments. Integer arguments are considered to
563 have type _Float64, so the *f64 functions are preferred for f32x*
564 macros when no argument has a wider floating-point type. */
565# if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128
566# define __TGMATH_2_NARROW_F32(F, X, Y) \
567 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
568 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
569 ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
570 F ## f64x (X, Y) \
571 : F ## f64 (X, Y)))
572# define __TGMATH_2_NARROW_F64(F, X, Y) \
573 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
574 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
575 ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
576 F ## f64x (X, Y) \
577 : F ## f128 (X, Y)))
578# define __TGMATH_2_NARROW_F32X(F, X, Y) \
579 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
580 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
581 ? __TGMATH_F128 ((X) + (Y), F, (X, Y)) \
582 F ## f64x (X, Y) \
583 : F ## f64 (X, Y)))
584# elif __HAVE_FLOAT128
585# define __TGMATH_2_NARROW_F32(F, X, Y) \
586 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
587 + (__tgmath_real_type (Y)) 0) > sizeof (_Float64) \
588 ? F ## f128 (X, Y) \
589 : F ## f64 (X, Y)))
590# define __TGMATH_2_NARROW_F64(F, X, Y) \
591 (F ## f128 (X, Y))
592# define __TGMATH_2_NARROW_F32X(F, X, Y) \
593 (__extension__ (sizeof ((__tgmath_real_type (X)) 0 \
594 + (__tgmath_real_type (Y)) 0) > sizeof (_Float32x) \
595 ? F ## f64x (X, Y) \
596 : F ## f64 (X, Y)))
597# else
598# define __TGMATH_2_NARROW_F32(F, X, Y) \
599 (F ## f64 (X, Y))
600# endif
be3a79a3 601# endif /* !__HAVE_BUILTIN_TGMATH. */
dfd2257a
UD
602#else
603# error "Unsupported compiler; you cannot use <tgmath.h>"
604#endif
605
606
607/* Unary functions defined for real and complex values. */
608
609
610/* Trigonometric functions. */
611
612/* Arc cosine of X. */
613#define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
614/* Arc sine of X. */
615#define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
616/* Arc tangent of X. */
617#define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
618/* Arc tangent of Y/X. */
cfb32a6c 619#define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
dfd2257a
UD
620
621/* Cosine of X. */
622#define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
623/* Sine of X. */
624#define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
625/* Tangent of X. */
626#define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
627
628
629/* Hyperbolic functions. */
630
631/* Hyperbolic arc cosine of X. */
632#define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
633/* Hyperbolic arc sine of X. */
634#define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
635/* Hyperbolic arc tangent of X. */
636#define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
637
638/* Hyperbolic cosine of X. */
639#define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
640/* Hyperbolic sine of X. */
641#define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
642/* Hyperbolic tangent of X. */
643#define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
644
645
646/* Exponential and logarithmic functions. */
647
648/* Exponential function of X. */
649#define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
650
651/* Break VALUE into a normalized fraction and an integral power of 2. */
652#define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
653
654/* X times (two to the EXP power). */
655#define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
656
657/* Natural logarithm of X. */
658#define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
659
660/* Base-ten logarithm of X. */
cc3fa755 661#ifdef __USE_GNU
0908a38a 662# define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10)
cc3fa755
UD
663#else
664# define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
665#endif
dfd2257a
UD
666
667/* Return exp(X) - 1. */
668#define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
669
670/* Return log(1 + X). */
671#define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
672
673/* Return the base 2 signed integral exponent of X. */
674#define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
675
676/* Compute base-2 exponential of X. */
677#define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
678
679/* Compute base-2 logarithm of X. */
680#define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
681
682
683/* Power functions. */
684
685/* Return X to the Y power. */
686#define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
687
688/* Return the square root of X. */
689#define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
690
691/* Return `sqrt(X*X + Y*Y)'. */
692#define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
693
694/* Return the cube root of X. */
695#define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
696
697
698/* Nearest integer, absolute value, and remainder functions. */
699
700/* Smallest integral value not less than X. */
701#define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
702
703/* Absolute value of X. */
f1debaf6 704#define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
dfd2257a
UD
705
706/* Largest integer not greater than X. */
707#define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
708
709/* Floating-point modulo remainder of X/Y. */
710#define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
711
712/* Round X to integral valuein floating-point format using current
713 rounding direction, but do not raise inexact exception. */
714#define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
715
716/* Round X to nearest integral value, rounding halfway cases away from
717 zero. */
718#define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
719
720/* Round X to the integral value in floating-point format nearest but
721 not larger in magnitude. */
722#define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
723
724/* Compute remainder of X and Y and put in *QUO a value with sign of x/y
725 and magnitude congruent `mod 2^n' to the magnitude of the integral
726 quotient x/y, with n >= 3. */
727#define remquo(Val1, Val2, Val3) \
728 __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
729
730/* Round X to nearest integral value according to current rounding
731 direction. */
cfa44345
JM
732#define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint)
733#define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint)
dfd2257a
UD
734
735/* Round X to nearest integral value, rounding halfway cases away from
736 zero. */
cfa44345
JM
737#define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround)
738#define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround)
dfd2257a
UD
739
740
741/* Return X with its signed changed to Y's. */
742#define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
743
744/* Error and gamma functions. */
745#define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
746#define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
00d8bc81 747#define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
dfd2257a
UD
748#define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
749
750
751/* Return the integer nearest X in the direction of the
752 prevailing rounding mode. */
753#define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
754
0175c9e9 755#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
41a359e2
RS
756/* Return X - epsilon. */
757# define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
758/* Return X + epsilon. */
759# define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
760#endif
761
dfd2257a
UD
762/* Return X + epsilon if X < Y, X - epsilon if X > Y. */
763#define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
42bd0a85 764#define nexttoward(Val1, Val2) \
614d15f9 765 __TGMATH_BINARY_FIRST_REAL_STD_ONLY (Val1, Val2, nexttoward)
dfd2257a
UD
766
767/* Return the remainder of integer divison X / Y with infinite precision. */
768#define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
769
770/* Return X times (2 to the Nth power). */
de20571d 771#ifdef __USE_MISC
614d15f9 772# define scalb(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, scalb)
26644e87 773#endif
dfd2257a
UD
774
775/* Return X times (2 to the Nth power). */
776#define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
777
778/* Return X times (2 to the Nth power). */
779#define scalbln(Val1, Val2) \
780 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
781
782/* Return the binary exponent of X, which must be nonzero. */
cfa44345 783#define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb)
dfd2257a
UD
784
785
786/* Return positive difference between X and Y. */
787#define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
788
789/* Return maximum numeric value from X and Y. */
790#define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
791
792/* Return minimum numeric value from X and Y. */
793#define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
794
795
bfce746a 796/* Multiply-add function computed as a ternary operation. */
e7c3d12b 797#define fma(Val1, Val2, Val3) \
bfce746a
UD
798 __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
799
0175c9e9 800#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
41c67149
JM
801/* Round X to nearest integer value, rounding halfway cases to even. */
802# define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
803
423c2b9d 804# define fromfp(Val1, Val2, Val3) \
cfa44345 805 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp)
423c2b9d
JM
806
807# define ufromfp(Val1, Val2, Val3) \
cfa44345 808 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp)
423c2b9d
JM
809
810# define fromfpx(Val1, Val2, Val3) \
cfa44345 811 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx)
423c2b9d
JM
812
813# define ufromfpx(Val1, Val2, Val3) \
cfa44345 814 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx)
423c2b9d 815
55a38f82 816/* Like ilogb, but returning long int. */
cfa44345 817# define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb)
55a38f82 818
525f8039
JM
819/* Return value with maximum magnitude. */
820# define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
821
822/* Return value with minimum magnitude. */
823# define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
0175c9e9 824#endif
525f8039 825
bfce746a 826
dfd2257a
UD
827/* Absolute value, conjugates, and projection. */
828
829/* Argument value of Z. */
be3a79a3 830#define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, carg)
dfd2257a
UD
831
832/* Complex conjugate of Z. */
1c298d08 833#define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
dfd2257a
UD
834
835/* Projection of Z onto the Riemann sphere. */
1c298d08 836#define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
dfd2257a
UD
837
838
839/* Decomposing complex values. */
840
841/* Imaginary part of Z. */
be3a79a3 842#define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, cimag)
dfd2257a
UD
843
844/* Real part of Z. */
be3a79a3 845#define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL_SAME (Val, creal)
dfd2257a 846
f9fabc1b
JM
847
848/* Narrowing functions. */
849
850#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
851
852/* Add. */
853# define fadd(Val1, Val2) __TGMATH_2_NARROW_F (fadd, Val1, Val2)
854# define dadd(Val1, Val2) __TGMATH_2_NARROW_D (dadd, Val1, Val2)
855
856/* Divide. */
857# define fdiv(Val1, Val2) __TGMATH_2_NARROW_F (fdiv, Val1, Val2)
858# define ddiv(Val1, Val2) __TGMATH_2_NARROW_D (ddiv, Val1, Val2)
859
860/* Multiply. */
861# define fmul(Val1, Val2) __TGMATH_2_NARROW_F (fmul, Val1, Val2)
862# define dmul(Val1, Val2) __TGMATH_2_NARROW_D (dmul, Val1, Val2)
863
864/* Subtract. */
865# define fsub(Val1, Val2) __TGMATH_2_NARROW_F (fsub, Val1, Val2)
866# define dsub(Val1, Val2) __TGMATH_2_NARROW_D (dsub, Val1, Val2)
867
868#endif
869
870#if __GLIBC_USE (IEC_60559_TYPES_EXT)
871
872# if __HAVE_FLOAT16
873# define f16add(Val1, Val2) __TGMATH_2_NARROW_F16 (f16add, Val1, Val2)
874# define f16div(Val1, Val2) __TGMATH_2_NARROW_F16 (f16div, Val1, Val2)
875# define f16mul(Val1, Val2) __TGMATH_2_NARROW_F16 (f16mul, Val1, Val2)
876# define f16sub(Val1, Val2) __TGMATH_2_NARROW_F16 (f16sub, Val1, Val2)
877# endif
878
879# if __HAVE_FLOAT32
880# define f32add(Val1, Val2) __TGMATH_2_NARROW_F32 (f32add, Val1, Val2)
881# define f32div(Val1, Val2) __TGMATH_2_NARROW_F32 (f32div, Val1, Val2)
882# define f32mul(Val1, Val2) __TGMATH_2_NARROW_F32 (f32mul, Val1, Val2)
883# define f32sub(Val1, Val2) __TGMATH_2_NARROW_F32 (f32sub, Val1, Val2)
884# endif
885
886# if __HAVE_FLOAT64 && (__HAVE_FLOAT64X || __HAVE_FLOAT128)
887# define f64add(Val1, Val2) __TGMATH_2_NARROW_F64 (f64add, Val1, Val2)
888# define f64div(Val1, Val2) __TGMATH_2_NARROW_F64 (f64div, Val1, Val2)
889# define f64mul(Val1, Val2) __TGMATH_2_NARROW_F64 (f64mul, Val1, Val2)
890# define f64sub(Val1, Val2) __TGMATH_2_NARROW_F64 (f64sub, Val1, Val2)
891# endif
892
893# if __HAVE_FLOAT32X
894# define f32xadd(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xadd, Val1, Val2)
895# define f32xdiv(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xdiv, Val1, Val2)
896# define f32xmul(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xmul, Val1, Val2)
897# define f32xsub(Val1, Val2) __TGMATH_2_NARROW_F32X (f32xsub, Val1, Val2)
898# endif
899
900# if __HAVE_FLOAT64X && (__HAVE_FLOAT128X || __HAVE_FLOAT128)
901# define f64xadd(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xadd, Val1, Val2)
902# define f64xdiv(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xdiv, Val1, Val2)
903# define f64xmul(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xmul, Val1, Val2)
904# define f64xsub(Val1, Val2) __TGMATH_2_NARROW_F64X (f64xsub, Val1, Val2)
905# endif
906
907#endif
908
dfd2257a 909#endif /* tgmath.h */