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