posix: Sync glob with gnulib [BZ #1062]
[glibc.git] / math / tgmath.h
blob243813cdc0bd1a1c5a6f1b80b723baef51f631bc
1 /* Copyright (C) 1997-2017 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 <http://www.gnu.org/licenses/>. */
19 * ISO C99 Standard: 7.22 Type-generic math <tgmath.h>
22 #ifndef _TGMATH_H
23 #define _TGMATH_H 1
25 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
26 #include <bits/libc-header-start.h>
28 /* Include the needed headers. */
29 #include <bits/floatn.h>
30 #include <math.h>
31 #include <complex.h>
34 /* Since `complex' is currently not really implemented in most C compilers
35 and if it is implemented, the implementations differ. This makes it
36 quite difficult to write a generic implementation of this header. We
37 do not try this for now and instead concentrate only on GNU CC. Once
38 we have more information support for other compilers might follow. */
40 #if __GNUC_PREREQ (2, 7)
42 # ifdef __NO_LONG_DOUBLE_MATH
43 # define __tgml(fct) fct
44 # else
45 # define __tgml(fct) fct ## l
46 # endif
48 /* This is ugly but unless gcc gets appropriate builtins we have to do
49 something like this. Don't ask how it works. */
51 /* __floating_type expands to 1 if TYPE is a floating type (including
52 complex floating types), 0 if TYPE is an integer type (including
53 complex integer types). __real_integer_type expands to 1 if TYPE
54 is a real integer type. __complex_integer_type expands to 1 if
55 TYPE is a complex integer type. All these macros expand to integer
56 constant expressions. All these macros can assume their argument
57 has an arithmetic type (not vector, decimal floating-point or
58 fixed-point), valid to pass to tgmath.h macros. */
59 # if __GNUC_PREREQ (3, 1)
60 /* __builtin_classify_type expands to an integer constant expression
61 in GCC 3.1 and later. Default conversions applied to the argument
62 of __builtin_classify_type mean it always returns 1 for real
63 integer types rather than ever returning different values for
64 character, boolean or enumerated types. */
65 # define __floating_type(type) \
66 (__builtin_classify_type (__real__ ((type) 0)) == 8)
67 # define __real_integer_type(type) \
68 (__builtin_classify_type ((type) 0) == 1)
69 # define __complex_integer_type(type) \
70 (__builtin_classify_type ((type) 0) == 9 \
71 && __builtin_classify_type (__real__ ((type) 0)) == 1)
72 # else
73 /* GCC versions predating __builtin_classify_type are also looser on
74 what counts as an integer constant expression. */
75 # define __floating_type(type) (((type) 1.25) != 1)
76 # define __real_integer_type(type) (((type) (1.25 + _Complex_I)) == 1)
77 # define __complex_integer_type(type) \
78 (((type) (1.25 + _Complex_I)) == (1 + _Complex_I))
79 # endif
81 /* Whether an expression (of arithmetic type) has a real type. */
82 # define __expr_is_real(E) (__builtin_classify_type (E) != 9)
84 /* The tgmath real type for T, where E is 0 if T is an integer type
85 and 1 for a floating type. If T has a complex type, it is
86 unspecified whether the return type is real or complex (but it has
87 the correct corresponding real type). */
88 # define __tgmath_real_type_sub(T, E) \
89 __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
90 : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
92 /* The tgmath real type of EXPR. */
93 # define __tgmath_real_type(expr) \
94 __tgmath_real_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
95 __floating_type (__typeof__ (+(expr))))
97 /* The tgmath complex type for T, where E1 is 1 if T has a floating
98 type and 0 otherwise, E2 is 1 if T has a real integer type and 0
99 otherwise, and E3 is 1 if T has a complex type and 0 otherwise. */
100 # define __tgmath_complex_type_sub(T, E1, E2, E3) \
101 __typeof__ (*(0 \
102 ? (__typeof__ (0 ? (T *) 0 : (void *) (!(E1)))) 0 \
103 : (__typeof__ (0 \
104 ? (__typeof__ (0 \
105 ? (double *) 0 \
106 : (void *) (!(E2)))) 0 \
107 : (__typeof__ (0 \
108 ? (_Complex double *) 0 \
109 : (void *) (!(E3)))) 0)) 0))
111 /* The tgmath complex type of EXPR. */
112 # define __tgmath_complex_type(expr) \
113 __tgmath_complex_type_sub (__typeof__ ((__typeof__ (+(expr))) 0), \
114 __floating_type (__typeof__ (+(expr))), \
115 __real_integer_type (__typeof__ (+(expr))), \
116 __complex_integer_type (__typeof__ (+(expr))))
118 /* Expand to text that checks if ARG_COMB has type _Float128, and if
119 so calls the appropriately suffixed FCT (which may include a cast),
120 or FCT and CFCT for complex functions, with arguments ARG_CALL. */
121 # if __HAVE_DISTINCT_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
122 # define __TGMATH_F128(arg_comb, fct, arg_call) \
123 __builtin_types_compatible_p (__typeof (+(arg_comb)), _Float128) \
124 ? fct ## f128 arg_call :
125 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
126 __builtin_types_compatible_p (__typeof (+__real__ (arg_comb)), _Float128) \
127 ? (__expr_is_real (arg_comb) \
128 ? fct ## f128 arg_call \
129 : cfct ## f128 arg_call) :
130 # else
131 # define __TGMATH_F128(arg_comb, fct, arg_call) /* Nothing. */
132 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) /* Nothing. */
133 # endif
136 /* We have two kinds of generic macros: to support functions which are
137 only defined on real valued parameters and those which are defined
138 for complex functions as well. */
139 # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
140 (__extension__ ((sizeof (+(Val)) == sizeof (double) \
141 || __builtin_classify_type (Val) != 8) \
142 ? (__tgmath_real_type (Val)) Fct (Val) \
143 : (sizeof (+(Val)) == sizeof (float)) \
144 ? (__tgmath_real_type (Val)) Fct##f (Val) \
145 : __TGMATH_F128 ((Val), (__tgmath_real_type (Val)) Fct, \
146 (Val)) \
147 (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
149 # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \
150 (__extension__ ((sizeof (+(Val)) == sizeof (double) \
151 || __builtin_classify_type (Val) != 8) \
152 ? Fct (Val) \
153 : (sizeof (+(Val)) == sizeof (float)) \
154 ? Fct##f (Val) \
155 : __TGMATH_F128 ((Val), Fct, (Val)) \
156 __tgml(Fct) (Val)))
158 # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
159 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
160 || __builtin_classify_type (Val1) != 8) \
161 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
162 : (sizeof (+(Val1)) == sizeof (float)) \
163 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
164 : __TGMATH_F128 ((Val1), (__tgmath_real_type (Val1)) Fct, \
165 (Val1, Val2)) \
166 (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
168 # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
169 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
170 || __builtin_classify_type (Val1) != 8) \
171 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
172 : (sizeof (+(Val1)) == sizeof (float)) \
173 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
174 : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
176 # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
177 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
178 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
179 ? __TGMATH_F128 ((Val1) + (Val2), \
180 (__typeof \
181 ((__tgmath_real_type (Val1)) 0 \
182 + (__tgmath_real_type (Val2)) 0)) Fct, \
183 (Val1, Val2)) \
184 (__typeof ((__tgmath_real_type (Val1)) 0 \
185 + (__tgmath_real_type (Val2)) 0)) \
186 __tgml(Fct) (Val1, Val2) \
187 : (sizeof (+(Val1)) == sizeof (double) \
188 || sizeof (+(Val2)) == sizeof (double) \
189 || __builtin_classify_type (Val1) != 8 \
190 || __builtin_classify_type (Val2) != 8) \
191 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
192 + (__tgmath_real_type (Val2)) 0)) \
193 Fct (Val1, Val2) \
194 : (__typeof ((__tgmath_real_type (Val1)) 0 \
195 + (__tgmath_real_type (Val2)) 0)) \
196 Fct##f (Val1, Val2)))
198 # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
199 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
200 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
201 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
202 + (__tgmath_real_type (Val2)) 0)) \
203 __tgml(Fct) (Val1, Val2) \
204 : (sizeof (+(Val1)) == sizeof (double) \
205 || sizeof (+(Val2)) == sizeof (double) \
206 || __builtin_classify_type (Val1) != 8 \
207 || __builtin_classify_type (Val2) != 8) \
208 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
209 + (__tgmath_real_type (Val2)) 0)) \
210 Fct (Val1, Val2) \
211 : (__typeof ((__tgmath_real_type (Val1)) 0 \
212 + (__tgmath_real_type (Val2)) 0)) \
213 Fct##f (Val1, Val2)))
215 # define __TGMATH_BINARY_REAL_RET_ONLY(Val1, Val2, Fct) \
216 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
217 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
218 ? __TGMATH_F128 ((Val1) + (Val2), Fct, (Val1, Val2)) \
219 __tgml(Fct) (Val1, Val2) \
220 : (sizeof (+(Val1)) == sizeof (double) \
221 || sizeof (+(Val2)) == sizeof (double) \
222 || __builtin_classify_type (Val1) != 8 \
223 || __builtin_classify_type (Val2) != 8) \
224 ? Fct (Val1, Val2) \
225 : Fct##f (Val1, Val2)))
227 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
228 (__extension__ ((sizeof ((Val1) + (Val2)) > sizeof (double) \
229 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
230 ? __TGMATH_F128 ((Val1) + (Val2), \
231 (__typeof \
232 ((__tgmath_real_type (Val1)) 0 \
233 + (__tgmath_real_type (Val2)) 0)) Fct, \
234 (Val1, Val2, Val3)) \
235 (__typeof ((__tgmath_real_type (Val1)) 0 \
236 + (__tgmath_real_type (Val2)) 0)) \
237 __tgml(Fct) (Val1, Val2, Val3) \
238 : (sizeof (+(Val1)) == sizeof (double) \
239 || sizeof (+(Val2)) == sizeof (double) \
240 || __builtin_classify_type (Val1) != 8 \
241 || __builtin_classify_type (Val2) != 8) \
242 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
243 + (__tgmath_real_type (Val2)) 0)) \
244 Fct (Val1, Val2, Val3) \
245 : (__typeof ((__tgmath_real_type (Val1)) 0 \
246 + (__tgmath_real_type (Val2)) 0)) \
247 Fct##f (Val1, Val2, Val3)))
249 # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
250 (__extension__ ((sizeof ((Val1) + (Val2) + (Val3)) > sizeof (double) \
251 && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
252 == 8) \
253 ? __TGMATH_F128 ((Val1) + (Val2) + (Val3), \
254 (__typeof \
255 ((__tgmath_real_type (Val1)) 0 \
256 + (__tgmath_real_type (Val2)) 0 \
257 + (__tgmath_real_type (Val3)) 0)) Fct, \
258 (Val1, Val2, Val3)) \
259 (__typeof ((__tgmath_real_type (Val1)) 0 \
260 + (__tgmath_real_type (Val2)) 0 \
261 + (__tgmath_real_type (Val3)) 0)) \
262 __tgml(Fct) (Val1, Val2, Val3) \
263 : (sizeof (+(Val1)) == sizeof (double) \
264 || sizeof (+(Val2)) == sizeof (double) \
265 || sizeof (+(Val3)) == sizeof (double) \
266 || __builtin_classify_type (Val1) != 8 \
267 || __builtin_classify_type (Val2) != 8 \
268 || __builtin_classify_type (Val3) != 8) \
269 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
270 + (__tgmath_real_type (Val2)) 0 \
271 + (__tgmath_real_type (Val3)) 0)) \
272 Fct (Val1, Val2, Val3) \
273 : (__typeof ((__tgmath_real_type (Val1)) 0 \
274 + (__tgmath_real_type (Val2)) 0 \
275 + (__tgmath_real_type (Val3)) 0)) \
276 Fct##f (Val1, Val2, Val3)))
278 # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
279 (__extension__ ((sizeof (+(Val1)) == sizeof (double) \
280 || __builtin_classify_type (Val1) != 8) \
281 ? Fct (Val1, Val2, Val3) \
282 : (sizeof (+(Val1)) == sizeof (float)) \
283 ? Fct##f (Val1, Val2, Val3) \
284 : __TGMATH_F128 ((Val1), Fct, (Val1, Val2, Val3)) \
285 __tgml(Fct) (Val1, Val2, Val3)))
287 /* XXX This definition has to be changed as soon as the compiler understands
288 the imaginary keyword. */
289 # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
290 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
291 || __builtin_classify_type (__real__ (Val)) != 8) \
292 ? (__expr_is_real (Val) \
293 ? (__tgmath_complex_type (Val)) Fct (Val) \
294 : (__tgmath_complex_type (Val)) Cfct (Val)) \
295 : (sizeof (+__real__ (Val)) == sizeof (float)) \
296 ? (__expr_is_real (Val) \
297 ? (__tgmath_complex_type (Val)) Fct##f (Val) \
298 : (__tgmath_complex_type (Val)) Cfct##f (Val)) \
299 : __TGMATH_CF128 ((Val), \
300 (__tgmath_complex_type (Val)) Fct, \
301 (__tgmath_complex_type (Val)) Cfct, \
302 (Val)) \
303 (__expr_is_real (Val) \
304 ? (__tgmath_complex_type (Val)) __tgml(Fct) (Val) \
305 : (__tgmath_complex_type (Val)) __tgml(Cfct) (Val))))
307 # define __TGMATH_UNARY_IMAG(Val, Cfct) \
308 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
309 || __builtin_classify_type (__real__ (Val)) != 8) \
310 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
311 + _Complex_I)) Cfct (Val) \
312 : (sizeof (+__real__ (Val)) == sizeof (float)) \
313 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
314 + _Complex_I)) Cfct##f (Val) \
315 : __TGMATH_F128 (__real__ (Val), \
316 (__typeof__ \
317 ((__tgmath_real_type (Val)) 0 \
318 + _Complex_I)) Cfct, (Val)) \
319 (__typeof__ ((__tgmath_real_type (Val)) 0 \
320 + _Complex_I)) __tgml(Cfct) (Val)))
322 /* XXX This definition has to be changed as soon as the compiler understands
323 the imaginary keyword. */
324 # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
325 (__extension__ ((sizeof (+__real__ (Val)) == sizeof (double) \
326 || __builtin_classify_type (__real__ (Val)) != 8) \
327 ? (__expr_is_real (Val) \
328 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
329 Fct (Val) \
330 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
331 Cfct (Val)) \
332 : (sizeof (+__real__ (Val)) == sizeof (float)) \
333 ? (__expr_is_real (Val) \
334 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
335 Fct##f (Val) \
336 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
337 Cfct##f (Val)) \
338 : __TGMATH_CF128 ((Val), \
339 (__typeof__ \
340 (__real__ \
341 (__tgmath_real_type (Val)) 0)) Fct, \
342 (__typeof__ \
343 (__real__ \
344 (__tgmath_real_type (Val)) 0)) Cfct, \
345 (Val)) \
346 (__expr_is_real (Val) \
347 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
348 __tgml(Fct) (Val) \
349 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
350 __tgml(Cfct) (Val))))
352 /* XXX This definition has to be changed as soon as the compiler understands
353 the imaginary keyword. */
354 # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
355 (__extension__ ((sizeof (__real__ (Val1) \
356 + __real__ (Val2)) > sizeof (double) \
357 && __builtin_classify_type (__real__ (Val1) \
358 + __real__ (Val2)) == 8) \
359 ? __TGMATH_CF128 ((Val1) + (Val2), \
360 (__typeof \
361 ((__tgmath_complex_type (Val1)) 0 \
362 + (__tgmath_complex_type (Val2)) 0)) \
363 Fct, \
364 (__typeof \
365 ((__tgmath_complex_type (Val1)) 0 \
366 + (__tgmath_complex_type (Val2)) 0)) \
367 Cfct, \
368 (Val1, Val2)) \
369 (__expr_is_real ((Val1) + (Val2)) \
370 ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
371 + (__tgmath_complex_type (Val2)) 0)) \
372 __tgml(Fct) (Val1, Val2) \
373 : (__typeof ((__tgmath_complex_type (Val1)) 0 \
374 + (__tgmath_complex_type (Val2)) 0)) \
375 __tgml(Cfct) (Val1, Val2)) \
376 : (sizeof (+__real__ (Val1)) == sizeof (double) \
377 || sizeof (+__real__ (Val2)) == sizeof (double) \
378 || __builtin_classify_type (__real__ (Val1)) != 8 \
379 || __builtin_classify_type (__real__ (Val2)) != 8) \
380 ? (__expr_is_real ((Val1) + (Val2)) \
381 ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
382 + (__tgmath_complex_type (Val2)) 0)) \
383 Fct (Val1, Val2) \
384 : (__typeof ((__tgmath_complex_type (Val1)) 0 \
385 + (__tgmath_complex_type (Val2)) 0)) \
386 Cfct (Val1, Val2)) \
387 : (__expr_is_real ((Val1) + (Val2)) \
388 ? (__typeof ((__tgmath_complex_type (Val1)) 0 \
389 + (__tgmath_complex_type (Val2)) 0)) \
390 Fct##f (Val1, Val2) \
391 : (__typeof ((__tgmath_complex_type (Val1)) 0 \
392 + (__tgmath_complex_type (Val2)) 0)) \
393 Cfct##f (Val1, Val2))))
394 #else
395 # error "Unsupported compiler; you cannot use <tgmath.h>"
396 #endif
399 /* Unary functions defined for real and complex values. */
402 /* Trigonometric functions. */
404 /* Arc cosine of X. */
405 #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
406 /* Arc sine of X. */
407 #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
408 /* Arc tangent of X. */
409 #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
410 /* Arc tangent of Y/X. */
411 #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
413 /* Cosine of X. */
414 #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
415 /* Sine of X. */
416 #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
417 /* Tangent of X. */
418 #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
421 /* Hyperbolic functions. */
423 /* Hyperbolic arc cosine of X. */
424 #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
425 /* Hyperbolic arc sine of X. */
426 #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
427 /* Hyperbolic arc tangent of X. */
428 #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
430 /* Hyperbolic cosine of X. */
431 #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
432 /* Hyperbolic sine of X. */
433 #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
434 /* Hyperbolic tangent of X. */
435 #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
438 /* Exponential and logarithmic functions. */
440 /* Exponential function of X. */
441 #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
443 /* Break VALUE into a normalized fraction and an integral power of 2. */
444 #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
446 /* X times (two to the EXP power). */
447 #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
449 /* Natural logarithm of X. */
450 #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
452 /* Base-ten logarithm of X. */
453 #ifdef __USE_GNU
454 # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10)
455 #else
456 # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
457 #endif
459 /* Return exp(X) - 1. */
460 #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
462 /* Return log(1 + X). */
463 #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
465 /* Return the base 2 signed integral exponent of X. */
466 #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
468 /* Compute base-2 exponential of X. */
469 #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
471 /* Compute base-2 logarithm of X. */
472 #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
475 /* Power functions. */
477 /* Return X to the Y power. */
478 #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
480 /* Return the square root of X. */
481 #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
483 /* Return `sqrt(X*X + Y*Y)'. */
484 #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
486 /* Return the cube root of X. */
487 #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
490 /* Nearest integer, absolute value, and remainder functions. */
492 /* Smallest integral value not less than X. */
493 #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
495 /* Absolute value of X. */
496 #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
498 /* Largest integer not greater than X. */
499 #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
501 /* Floating-point modulo remainder of X/Y. */
502 #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
504 /* Round X to integral valuein floating-point format using current
505 rounding direction, but do not raise inexact exception. */
506 #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
508 /* Round X to nearest integral value, rounding halfway cases away from
509 zero. */
510 #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
512 /* Round X to the integral value in floating-point format nearest but
513 not larger in magnitude. */
514 #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
516 /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
517 and magnitude congruent `mod 2^n' to the magnitude of the integral
518 quotient x/y, with n >= 3. */
519 #define remquo(Val1, Val2, Val3) \
520 __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
522 /* Round X to nearest integral value according to current rounding
523 direction. */
524 #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint)
525 #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint)
527 /* Round X to nearest integral value, rounding halfway cases away from
528 zero. */
529 #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround)
530 #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround)
533 /* Return X with its signed changed to Y's. */
534 #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
536 /* Error and gamma functions. */
537 #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
538 #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
539 #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
540 #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
543 /* Return the integer nearest X in the direction of the
544 prevailing rounding mode. */
545 #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
547 #if __GLIBC_USE (IEC_60559_BFP_EXT)
548 /* Return X - epsilon. */
549 # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
550 /* Return X + epsilon. */
551 # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
552 #endif
554 /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
555 #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
556 #define nexttoward(Val1, Val2) \
557 __TGMATH_BINARY_FIRST_REAL_STD_ONLY (Val1, Val2, nexttoward)
559 /* Return the remainder of integer divison X / Y with infinite precision. */
560 #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
562 /* Return X times (2 to the Nth power). */
563 #ifdef __USE_MISC
564 # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, scalb)
565 #endif
567 /* Return X times (2 to the Nth power). */
568 #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
570 /* Return X times (2 to the Nth power). */
571 #define scalbln(Val1, Val2) \
572 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
574 /* Return the binary exponent of X, which must be nonzero. */
575 #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb)
578 /* Return positive difference between X and Y. */
579 #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
581 /* Return maximum numeric value from X and Y. */
582 #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
584 /* Return minimum numeric value from X and Y. */
585 #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
588 /* Multiply-add function computed as a ternary operation. */
589 #define fma(Val1, Val2, Val3) \
590 __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
592 #if __GLIBC_USE (IEC_60559_BFP_EXT)
593 /* Round X to nearest integer value, rounding halfway cases to even. */
594 # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
596 # define fromfp(Val1, Val2, Val3) \
597 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp)
599 # define ufromfp(Val1, Val2, Val3) \
600 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp)
602 # define fromfpx(Val1, Val2, Val3) \
603 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx)
605 # define ufromfpx(Val1, Val2, Val3) \
606 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx)
608 /* Like ilogb, but returning long int. */
609 # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb)
611 /* Return value with maximum magnitude. */
612 # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
614 /* Return value with minimum magnitude. */
615 # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
617 /* Total order operation. */
618 # define totalorder(Val1, Val2) \
619 __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalorder)
621 /* Total order operation on absolute values. */
622 # define totalordermag(Val1, Val2) \
623 __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalordermag)
624 #endif
627 /* Absolute value, conjugates, and projection. */
629 /* Argument value of Z. */
630 #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, carg, carg)
632 /* Complex conjugate of Z. */
633 #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
635 /* Projection of Z onto the Riemann sphere. */
636 #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
639 /* Decomposing complex values. */
641 /* Imaginary part of Z. */
642 #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, cimag, cimag)
644 /* Real part of Z. */
645 #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, creal, creal)
647 #endif /* tgmath.h */