]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/tgmath.h
f75e3dca78c338acf060f80af9c7071da6d57c28
[thirdparty/glibc.git] / math / tgmath.h
1 /* Copyright (C) 1997-2017 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 <http://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 /* 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. */
39
40 #if __GNUC_PREREQ (2, 7)
41
42 # ifdef __NO_LONG_DOUBLE_MATH
43 # define __tgml(fct) fct
44 # else
45 # define __tgml(fct) fct ## l
46 # endif
47
48 /* This is ugly but unless gcc gets appropriate builtins we have to do
49 something like this. Don't ask how it works. */
50
51 /* 1 if 'type' is a floating type, 0 if 'type' is an integer type.
52 Allows for _Bool. Expands to an integer constant expression. */
53 # if __GNUC_PREREQ (3, 1)
54 # define __floating_type(type) \
55 (__builtin_classify_type ((type) 0) == 8 \
56 || (__builtin_classify_type ((type) 0) == 9 \
57 && __builtin_classify_type (__real__ ((type) 0)) == 8))
58 # else
59 # define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))
60 # endif
61
62 /* The tgmath real type for T, where E is 0 if T is an integer type and
63 1 for a floating type. */
64 # define __tgmath_real_type_sub(T, E) \
65 __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
66 : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
67
68 /* The tgmath real type of EXPR. */
69 # define __tgmath_real_type(expr) \
70 __tgmath_real_type_sub (__typeof__ ((__typeof__ (expr)) 0), \
71 __floating_type (__typeof__ (expr)))
72
73 /* Expand to text that checks if ARG_COMB has type _Float128, and if
74 so calls the appropriately suffixed FCT (which may include a cast),
75 or FCT and CFCT for complex functions, with arguments ARG_CALL. */
76 # if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
77 # define __TGMATH_F128(arg_comb, fct, arg_call) \
78 __builtin_types_compatible_p (__typeof (arg_comb), _Float128) \
79 ? fct ## f128 arg_call :
80 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) \
81 __builtin_types_compatible_p (__typeof (__real__ (arg_comb)), _Float128) \
82 ? (sizeof (__real__ (arg_comb)) == sizeof (arg_comb) \
83 ? fct ## f128 arg_call \
84 : cfct ## f128 arg_call) :
85 # else
86 # define __TGMATH_F128(arg_comb, fct, arg_call) /* Nothing. */
87 # define __TGMATH_CF128(arg_comb, fct, cfct, arg_call) /* Nothing. */
88 # endif
89
90
91 /* We have two kinds of generic macros: to support functions which are
92 only defined on real valued parameters and those which are defined
93 for complex functions as well. */
94 # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
95 (__extension__ ((sizeof (Val) == sizeof (double) \
96 || __builtin_classify_type (Val) != 8) \
97 ? (__tgmath_real_type (Val)) Fct (Val) \
98 : (sizeof (Val) == sizeof (float)) \
99 ? (__tgmath_real_type (Val)) Fct##f (Val) \
100 : __TGMATH_F128 ((Val), (__tgmath_real_type (Val)) Fct, \
101 (Val)) \
102 (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
103
104 # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \
105 (__extension__ ((sizeof (Val) == sizeof (double) \
106 || __builtin_classify_type (Val) != 8) \
107 ? Fct (Val) \
108 : (sizeof (Val) == sizeof (float)) \
109 ? Fct##f (Val) \
110 : __TGMATH_F128 ((Val), Fct, (Val)) \
111 __tgml(Fct) (Val)))
112
113 # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
114 (__extension__ ((sizeof (Val1) == sizeof (double) \
115 || __builtin_classify_type (Val1) != 8) \
116 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
117 : (sizeof (Val1) == sizeof (float)) \
118 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
119 : __TGMATH_F128 ((Val1), (__tgmath_real_type (Val1)) Fct, \
120 (Val1, Val2)) \
121 (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
122
123 # define __TGMATH_BINARY_FIRST_REAL_STD_ONLY(Val1, Val2, Fct) \
124 (__extension__ ((sizeof (Val1) == sizeof (double) \
125 || __builtin_classify_type (Val1) != 8) \
126 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
127 : (sizeof (Val1) == sizeof (float)) \
128 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
129 : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
130
131 # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
132 (__extension__ (((sizeof (Val1) > sizeof (double) \
133 || sizeof (Val2) > sizeof (double)) \
134 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
135 ? __TGMATH_F128 ((Val1) + (Val2), \
136 (__typeof \
137 ((__tgmath_real_type (Val1)) 0 \
138 + (__tgmath_real_type (Val2)) 0)) Fct, \
139 (Val1, Val2)) \
140 (__typeof ((__tgmath_real_type (Val1)) 0 \
141 + (__tgmath_real_type (Val2)) 0)) \
142 __tgml(Fct) (Val1, Val2) \
143 : (sizeof (Val1) == sizeof (double) \
144 || sizeof (Val2) == sizeof (double) \
145 || __builtin_classify_type (Val1) != 8 \
146 || __builtin_classify_type (Val2) != 8) \
147 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
148 + (__tgmath_real_type (Val2)) 0)) \
149 Fct (Val1, Val2) \
150 : (__typeof ((__tgmath_real_type (Val1)) 0 \
151 + (__tgmath_real_type (Val2)) 0)) \
152 Fct##f (Val1, Val2)))
153
154 # define __TGMATH_BINARY_REAL_STD_ONLY(Val1, Val2, Fct) \
155 (__extension__ (((sizeof (Val1) > sizeof (double) \
156 || sizeof (Val2) > sizeof (double)) \
157 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
158 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
159 + (__tgmath_real_type (Val2)) 0)) \
160 __tgml(Fct) (Val1, Val2) \
161 : (sizeof (Val1) == sizeof (double) \
162 || sizeof (Val2) == sizeof (double) \
163 || __builtin_classify_type (Val1) != 8 \
164 || __builtin_classify_type (Val2) != 8) \
165 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
166 + (__tgmath_real_type (Val2)) 0)) \
167 Fct (Val1, Val2) \
168 : (__typeof ((__tgmath_real_type (Val1)) 0 \
169 + (__tgmath_real_type (Val2)) 0)) \
170 Fct##f (Val1, Val2)))
171
172 # define __TGMATH_BINARY_REAL_RET_ONLY(Val1, Val2, Fct) \
173 (__extension__ (((sizeof (Val1) > sizeof (double) \
174 || sizeof (Val2) > sizeof (double)) \
175 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
176 ? __TGMATH_F128 ((Val1) + (Val2), Fct, (Val1, Val2)) \
177 __tgml(Fct) (Val1, Val2) \
178 : (sizeof (Val1) == sizeof (double) \
179 || sizeof (Val2) == sizeof (double) \
180 || __builtin_classify_type (Val1) != 8 \
181 || __builtin_classify_type (Val2) != 8) \
182 ? Fct (Val1, Val2) \
183 : Fct##f (Val1, Val2)))
184
185 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
186 (__extension__ (((sizeof (Val1) > sizeof (double) \
187 || sizeof (Val2) > sizeof (double)) \
188 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
189 ? __TGMATH_F128 ((Val1) + (Val2), \
190 (__typeof \
191 ((__tgmath_real_type (Val1)) 0 \
192 + (__tgmath_real_type (Val2)) 0)) Fct, \
193 (Val1, Val2, Val3)) \
194 (__typeof ((__tgmath_real_type (Val1)) 0 \
195 + (__tgmath_real_type (Val2)) 0)) \
196 __tgml(Fct) (Val1, Val2, Val3) \
197 : (sizeof (Val1) == sizeof (double) \
198 || sizeof (Val2) == sizeof (double) \
199 || __builtin_classify_type (Val1) != 8 \
200 || __builtin_classify_type (Val2) != 8) \
201 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
202 + (__tgmath_real_type (Val2)) 0)) \
203 Fct (Val1, Val2, Val3) \
204 : (__typeof ((__tgmath_real_type (Val1)) 0 \
205 + (__tgmath_real_type (Val2)) 0)) \
206 Fct##f (Val1, Val2, Val3)))
207
208 # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
209 (__extension__ (((sizeof (Val1) > sizeof (double) \
210 || sizeof (Val2) > sizeof (double) \
211 || sizeof (Val3) > sizeof (double)) \
212 && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
213 == 8) \
214 ? __TGMATH_F128 ((Val1) + (Val2) + (Val3), \
215 (__typeof \
216 ((__tgmath_real_type (Val1)) 0 \
217 + (__tgmath_real_type (Val2)) 0 \
218 + (__tgmath_real_type (Val3)) 0)) Fct, \
219 (Val1, Val2, Val3)) \
220 (__typeof ((__tgmath_real_type (Val1)) 0 \
221 + (__tgmath_real_type (Val2)) 0 \
222 + (__tgmath_real_type (Val3)) 0)) \
223 __tgml(Fct) (Val1, Val2, Val3) \
224 : (sizeof (Val1) == sizeof (double) \
225 || sizeof (Val2) == sizeof (double) \
226 || sizeof (Val3) == sizeof (double) \
227 || __builtin_classify_type (Val1) != 8 \
228 || __builtin_classify_type (Val2) != 8 \
229 || __builtin_classify_type (Val3) != 8) \
230 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
231 + (__tgmath_real_type (Val2)) 0 \
232 + (__tgmath_real_type (Val3)) 0)) \
233 Fct (Val1, Val2, Val3) \
234 : (__typeof ((__tgmath_real_type (Val1)) 0 \
235 + (__tgmath_real_type (Val2)) 0 \
236 + (__tgmath_real_type (Val3)) 0)) \
237 Fct##f (Val1, Val2, Val3)))
238
239 # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \
240 (__extension__ ((sizeof (Val1) == sizeof (double) \
241 || __builtin_classify_type (Val1) != 8) \
242 ? Fct (Val1, Val2, Val3) \
243 : (sizeof (Val1) == sizeof (float)) \
244 ? Fct##f (Val1, Val2, Val3) \
245 : __TGMATH_F128 ((Val1), Fct, (Val1, Val2, Val3)) \
246 __tgml(Fct) (Val1, Val2, Val3)))
247
248 /* XXX This definition has to be changed as soon as the compiler understands
249 the imaginary keyword. */
250 # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
251 (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
252 || __builtin_classify_type (__real__ (Val)) != 8) \
253 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
254 ? (__tgmath_real_type (Val)) Fct (Val) \
255 : (__tgmath_real_type (Val)) Cfct (Val)) \
256 : (sizeof (__real__ (Val)) == sizeof (float)) \
257 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
258 ? (__tgmath_real_type (Val)) Fct##f (Val) \
259 : (__tgmath_real_type (Val)) Cfct##f (Val)) \
260 : __TGMATH_CF128 ((Val), (__tgmath_real_type (Val)) Fct, \
261 (__tgmath_real_type (Val)) Cfct, \
262 (Val)) \
263 ((sizeof (__real__ (Val)) == sizeof (Val)) \
264 ? (__tgmath_real_type (Val)) __tgml(Fct) (Val) \
265 : (__tgmath_real_type (Val)) __tgml(Cfct) (Val))))
266
267 # define __TGMATH_UNARY_IMAG(Val, Cfct) \
268 (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
269 || __builtin_classify_type (__real__ (Val)) != 8) \
270 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
271 + _Complex_I)) Cfct (Val) \
272 : (sizeof (__real__ (Val)) == sizeof (float)) \
273 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
274 + _Complex_I)) Cfct##f (Val) \
275 : __TGMATH_F128 (__real__ (Val), \
276 (__typeof__ \
277 ((__tgmath_real_type (Val)) 0 \
278 + _Complex_I)) Cfct, (Val)) \
279 (__typeof__ ((__tgmath_real_type (Val)) 0 \
280 + _Complex_I)) __tgml(Cfct) (Val)))
281
282 /* XXX This definition has to be changed as soon as the compiler understands
283 the imaginary keyword. */
284 # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
285 (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
286 || __builtin_classify_type (__real__ (Val)) != 8) \
287 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
288 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
289 Fct (Val) \
290 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
291 Cfct (Val)) \
292 : (sizeof (__real__ (Val)) == sizeof (float)) \
293 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
294 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
295 Fct##f (Val) \
296 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
297 Cfct##f (Val)) \
298 : __TGMATH_CF128 ((Val), \
299 (__typeof__ \
300 (__real__ \
301 (__tgmath_real_type (Val)) 0)) Fct, \
302 (__typeof__ \
303 (__real__ \
304 (__tgmath_real_type (Val)) 0)) Cfct, \
305 (Val)) \
306 ((sizeof (__real__ (Val)) == sizeof (Val)) \
307 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
308 __tgml(Fct) (Val) \
309 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0)) \
310 __tgml(Cfct) (Val))))
311
312 /* XXX This definition has to be changed as soon as the compiler understands
313 the imaginary keyword. */
314 # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
315 (__extension__ (((sizeof (__real__ (Val1)) > sizeof (double) \
316 || sizeof (__real__ (Val2)) > sizeof (double)) \
317 && __builtin_classify_type (__real__ (Val1) \
318 + __real__ (Val2)) == 8) \
319 ? __TGMATH_CF128 ((Val1) + (Val2), \
320 (__typeof \
321 ((__tgmath_real_type (Val1)) 0 \
322 + (__tgmath_real_type (Val2)) 0)) \
323 Fct, \
324 (__typeof \
325 ((__tgmath_real_type (Val1)) 0 \
326 + (__tgmath_real_type (Val2)) 0)) \
327 Cfct, \
328 (Val1, Val2)) \
329 ((sizeof (__real__ (Val1)) == sizeof (Val1) \
330 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
331 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
332 + (__tgmath_real_type (Val2)) 0)) \
333 __tgml(Fct) (Val1, Val2) \
334 : (__typeof ((__tgmath_real_type (Val1)) 0 \
335 + (__tgmath_real_type (Val2)) 0)) \
336 __tgml(Cfct) (Val1, Val2)) \
337 : (sizeof (__real__ (Val1)) == sizeof (double) \
338 || sizeof (__real__ (Val2)) == sizeof (double) \
339 || __builtin_classify_type (__real__ (Val1)) != 8 \
340 || __builtin_classify_type (__real__ (Val2)) != 8) \
341 ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
342 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
343 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
344 + (__tgmath_real_type (Val2)) 0)) \
345 Fct (Val1, Val2) \
346 : (__typeof ((__tgmath_real_type (Val1)) 0 \
347 + (__tgmath_real_type (Val2)) 0)) \
348 Cfct (Val1, Val2)) \
349 : ((sizeof (__real__ (Val1)) == sizeof (Val1) \
350 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
351 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
352 + (__tgmath_real_type (Val2)) 0)) \
353 Fct##f (Val1, Val2) \
354 : (__typeof ((__tgmath_real_type (Val1)) 0 \
355 + (__tgmath_real_type (Val2)) 0)) \
356 Cfct##f (Val1, Val2))))
357 #else
358 # error "Unsupported compiler; you cannot use <tgmath.h>"
359 #endif
360
361
362 /* Unary functions defined for real and complex values. */
363
364
365 /* Trigonometric functions. */
366
367 /* Arc cosine of X. */
368 #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
369 /* Arc sine of X. */
370 #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
371 /* Arc tangent of X. */
372 #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
373 /* Arc tangent of Y/X. */
374 #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
375
376 /* Cosine of X. */
377 #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
378 /* Sine of X. */
379 #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
380 /* Tangent of X. */
381 #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
382
383
384 /* Hyperbolic functions. */
385
386 /* Hyperbolic arc cosine of X. */
387 #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
388 /* Hyperbolic arc sine of X. */
389 #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
390 /* Hyperbolic arc tangent of X. */
391 #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
392
393 /* Hyperbolic cosine of X. */
394 #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
395 /* Hyperbolic sine of X. */
396 #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
397 /* Hyperbolic tangent of X. */
398 #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
399
400
401 /* Exponential and logarithmic functions. */
402
403 /* Exponential function of X. */
404 #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
405
406 /* Break VALUE into a normalized fraction and an integral power of 2. */
407 #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
408
409 /* X times (two to the EXP power). */
410 #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
411
412 /* Natural logarithm of X. */
413 #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
414
415 /* Base-ten logarithm of X. */
416 #ifdef __USE_GNU
417 # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10)
418 #else
419 # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
420 #endif
421
422 /* Return exp(X) - 1. */
423 #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
424
425 /* Return log(1 + X). */
426 #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
427
428 /* Return the base 2 signed integral exponent of X. */
429 #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
430
431 /* Compute base-2 exponential of X. */
432 #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
433
434 /* Compute base-2 logarithm of X. */
435 #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
436
437
438 /* Power functions. */
439
440 /* Return X to the Y power. */
441 #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
442
443 /* Return the square root of X. */
444 #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
445
446 /* Return `sqrt(X*X + Y*Y)'. */
447 #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
448
449 /* Return the cube root of X. */
450 #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
451
452
453 /* Nearest integer, absolute value, and remainder functions. */
454
455 /* Smallest integral value not less than X. */
456 #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
457
458 /* Absolute value of X. */
459 #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
460
461 /* Largest integer not greater than X. */
462 #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
463
464 /* Floating-point modulo remainder of X/Y. */
465 #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
466
467 /* Round X to integral valuein floating-point format using current
468 rounding direction, but do not raise inexact exception. */
469 #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
470
471 /* Round X to nearest integral value, rounding halfway cases away from
472 zero. */
473 #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
474
475 /* Round X to the integral value in floating-point format nearest but
476 not larger in magnitude. */
477 #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
478
479 /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
480 and magnitude congruent `mod 2^n' to the magnitude of the integral
481 quotient x/y, with n >= 3. */
482 #define remquo(Val1, Val2, Val3) \
483 __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
484
485 /* Round X to nearest integral value according to current rounding
486 direction. */
487 #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint)
488 #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint)
489
490 /* Round X to nearest integral value, rounding halfway cases away from
491 zero. */
492 #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround)
493 #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround)
494
495
496 /* Return X with its signed changed to Y's. */
497 #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
498
499 /* Error and gamma functions. */
500 #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
501 #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
502 #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
503 #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
504
505
506 /* Return the integer nearest X in the direction of the
507 prevailing rounding mode. */
508 #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
509
510 #if __GLIBC_USE (IEC_60559_BFP_EXT)
511 /* Return X - epsilon. */
512 # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
513 /* Return X + epsilon. */
514 # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
515 #endif
516
517 /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
518 #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
519 #define nexttoward(Val1, Val2) \
520 __TGMATH_BINARY_FIRST_REAL_STD_ONLY (Val1, Val2, nexttoward)
521
522 /* Return the remainder of integer divison X / Y with infinite precision. */
523 #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
524
525 /* Return X times (2 to the Nth power). */
526 #ifdef __USE_MISC
527 # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_STD_ONLY (Val1, Val2, scalb)
528 #endif
529
530 /* Return X times (2 to the Nth power). */
531 #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
532
533 /* Return X times (2 to the Nth power). */
534 #define scalbln(Val1, Val2) \
535 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
536
537 /* Return the binary exponent of X, which must be nonzero. */
538 #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb)
539
540
541 /* Return positive difference between X and Y. */
542 #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
543
544 /* Return maximum numeric value from X and Y. */
545 #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
546
547 /* Return minimum numeric value from X and Y. */
548 #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
549
550
551 /* Multiply-add function computed as a ternary operation. */
552 #define fma(Val1, Val2, Val3) \
553 __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
554
555 #if __GLIBC_USE (IEC_60559_BFP_EXT)
556 /* Round X to nearest integer value, rounding halfway cases to even. */
557 # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
558
559 # define fromfp(Val1, Val2, Val3) \
560 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp)
561
562 # define ufromfp(Val1, Val2, Val3) \
563 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp)
564
565 # define fromfpx(Val1, Val2, Val3) \
566 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx)
567
568 # define ufromfpx(Val1, Val2, Val3) \
569 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx)
570
571 /* Like ilogb, but returning long int. */
572 # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb)
573
574 /* Return value with maximum magnitude. */
575 # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
576
577 /* Return value with minimum magnitude. */
578 # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
579
580 /* Total order operation. */
581 # define totalorder(Val1, Val2) \
582 __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalorder)
583
584 /* Total order operation on absolute values. */
585 # define totalordermag(Val1, Val2) \
586 __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalordermag)
587 #endif
588
589
590 /* Absolute value, conjugates, and projection. */
591
592 /* Argument value of Z. */
593 #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, carg, carg)
594
595 /* Complex conjugate of Z. */
596 #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
597
598 /* Projection of Z onto the Riemann sphere. */
599 #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
600
601
602 /* Decomposing complex values. */
603
604 /* Imaginary part of Z. */
605 #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, cimag, cimag)
606
607 /* Real part of Z. */
608 #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, creal, creal)
609
610 #endif /* tgmath.h */