]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/tgmath.h
Add fromfp functions.
[thirdparty/glibc.git] / math / tgmath.h
CommitLineData
f7a9f785 1/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
dfd2257a
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
dfd2257a
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
dfd2257a 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
dfd2257a
UD
17
18/*
63ae7b63 19 * ISO C99 Standard: 7.22 Type-generic math <tgmath.h>
dfd2257a
UD
20 */
21
22#ifndef _TGMATH_H
23#define _TGMATH_H 1
24
25/* Include the needed headers. */
26#include <math.h>
27#include <complex.h>
28
29
30/* Since `complex' is currently not really implemented in most C compilers
31 and if it is implemented, the implementations differ. This makes it
32 quite difficult to write a generic implementation of this header. We
33 do not try this for now and instead concentrate only on GNU CC. Once
34 we have more information support for other compilers might follow. */
35
4360eafd 36#if __GNUC_PREREQ (2, 7)
dfd2257a 37
0d3fee40
UD
38# ifdef __NO_LONG_DOUBLE_MATH
39# define __tgml(fct) fct
40# else
41# define __tgml(fct) fct ## l
42# endif
43
925e31d9
UD
44/* This is ugly but unless gcc gets appropriate builtins we have to do
45 something like this. Don't ask how it works. */
46
47/* 1 if 'type' is a floating type, 0 if 'type' is an integer type.
48 Allows for _Bool. Expands to an integer constant expression. */
acd44dbc
UD
49# if __GNUC_PREREQ (3, 1)
50# define __floating_type(type) \
51 (__builtin_classify_type ((type) 0) == 8 \
52 || (__builtin_classify_type ((type) 0) == 9 \
53 && __builtin_classify_type (__real__ ((type) 0)) == 8))
54# else
55# define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))
56# endif
925e31d9
UD
57
58/* The tgmath real type for T, where E is 0 if T is an integer type and
59 1 for a floating type. */
deea1b29 60# define __tgmath_real_type_sub(T, E) \
1c298d08
UD
61 __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
62 : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
925e31d9
UD
63
64/* The tgmath real type of EXPR. */
deea1b29 65# define __tgmath_real_type(expr) \
1c298d08
UD
66 __tgmath_real_type_sub (__typeof__ ((__typeof__ (expr)) 0), \
67 __floating_type (__typeof__ (expr)))
925e31d9
UD
68
69
dfd2257a
UD
70/* We have two kinds of generic macros: to support functions which are
71 only defined on real valued parameters and those which are defined
72 for complex functions as well. */
73# define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
1c298d08
UD
74 (__extension__ ((sizeof (Val) == sizeof (double) \
75 || __builtin_classify_type (Val) != 8) \
76 ? (__tgmath_real_type (Val)) Fct (Val) \
77 : (sizeof (Val) == sizeof (float)) \
78 ? (__tgmath_real_type (Val)) Fct##f (Val) \
79 : (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
71502ebe
UD
80
81# define __TGMATH_UNARY_REAL_RET_ONLY(Val, RetType, Fct) \
1c298d08
UD
82 (__extension__ ((sizeof (Val) == sizeof (double) \
83 || __builtin_classify_type (Val) != 8) \
84 ? (RetType) Fct (Val) \
85 : (sizeof (Val) == sizeof (float)) \
86 ? (RetType) Fct##f (Val) \
87 : (RetType) __tgml(Fct) (Val)))
dfd2257a
UD
88
89# define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
1c298d08
UD
90 (__extension__ ((sizeof (Val1) == sizeof (double) \
91 || __builtin_classify_type (Val1) != 8) \
92 ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
93 : (sizeof (Val1) == sizeof (float)) \
94 ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
95 : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
dfd2257a
UD
96
97# define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
1c298d08
UD
98 (__extension__ (((sizeof (Val1) > sizeof (double) \
99 || sizeof (Val2) > sizeof (double)) \
100 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
101 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
102 + (__tgmath_real_type (Val2)) 0)) \
103 __tgml(Fct) (Val1, Val2) \
104 : (sizeof (Val1) == sizeof (double) \
105 || sizeof (Val2) == sizeof (double) \
106 || __builtin_classify_type (Val1) != 8 \
107 || __builtin_classify_type (Val2) != 8) \
108 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
109 + (__tgmath_real_type (Val2)) 0)) \
110 Fct (Val1, Val2) \
111 : (__typeof ((__tgmath_real_type (Val1)) 0 \
112 + (__tgmath_real_type (Val2)) 0)) \
113 Fct##f (Val1, Val2)))
dfd2257a
UD
114
115# define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
1c298d08
UD
116 (__extension__ (((sizeof (Val1) > sizeof (double) \
117 || sizeof (Val2) > sizeof (double)) \
118 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
119 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
120 + (__tgmath_real_type (Val2)) 0)) \
121 __tgml(Fct) (Val1, Val2, Val3) \
122 : (sizeof (Val1) == sizeof (double) \
123 || sizeof (Val2) == sizeof (double) \
124 || __builtin_classify_type (Val1) != 8 \
125 || __builtin_classify_type (Val2) != 8) \
126 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
127 + (__tgmath_real_type (Val2)) 0)) \
128 Fct (Val1, Val2, Val3) \
129 : (__typeof ((__tgmath_real_type (Val1)) 0 \
130 + (__tgmath_real_type (Val2)) 0)) \
131 Fct##f (Val1, Val2, Val3)))
bfce746a
UD
132
133# define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
1c298d08
UD
134 (__extension__ (((sizeof (Val1) > sizeof (double) \
135 || sizeof (Val2) > sizeof (double) \
136 || sizeof (Val3) > sizeof (double)) \
137 && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
138 == 8) \
139 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
140 + (__tgmath_real_type (Val2)) 0 \
141 + (__tgmath_real_type (Val3)) 0)) \
142 __tgml(Fct) (Val1, Val2, Val3) \
143 : (sizeof (Val1) == sizeof (double) \
144 || sizeof (Val2) == sizeof (double) \
145 || sizeof (Val3) == sizeof (double) \
146 || __builtin_classify_type (Val1) != 8 \
147 || __builtin_classify_type (Val2) != 8 \
148 || __builtin_classify_type (Val3) != 8) \
149 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
150 + (__tgmath_real_type (Val2)) 0 \
151 + (__tgmath_real_type (Val3)) 0)) \
152 Fct (Val1, Val2, Val3) \
153 : (__typeof ((__tgmath_real_type (Val1)) 0 \
154 + (__tgmath_real_type (Val2)) 0 \
155 + (__tgmath_real_type (Val3)) 0)) \
156 Fct##f (Val1, Val2, Val3)))
dfd2257a 157
423c2b9d
JM
158# define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, RetType, Fct) \
159 (__extension__ ((sizeof (Val1) == sizeof (double) \
160 || __builtin_classify_type (Val1) != 8) \
161 ? (RetType) Fct (Val1, Val2, Val3) \
162 : (sizeof (Val1) == sizeof (float)) \
163 ? (RetType) Fct##f (Val1, Val2, Val3) \
164 : (RetType) __tgml(Fct) (Val1, Val2, Val3)))
165
48244d09
UD
166/* XXX This definition has to be changed as soon as the compiler understands
167 the imaginary keyword. */
dfd2257a 168# define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
1c298d08
UD
169 (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
170 || __builtin_classify_type (__real__ (Val)) != 8) \
171 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
172 ? (__tgmath_real_type (Val)) Fct (Val) \
173 : (__tgmath_real_type (Val)) Cfct (Val)) \
174 : (sizeof (__real__ (Val)) == sizeof (float)) \
175 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
176 ? (__tgmath_real_type (Val)) Fct##f (Val) \
177 : (__tgmath_real_type (Val)) Cfct##f (Val)) \
178 : ((sizeof (__real__ (Val)) == sizeof (Val)) \
179 ? (__tgmath_real_type (Val)) __tgml(Fct) (Val) \
180 : (__tgmath_real_type (Val)) __tgml(Cfct) (Val))))
181
182# define __TGMATH_UNARY_IMAG(Val, Cfct) \
183 (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
184 || __builtin_classify_type (__real__ (Val)) != 8) \
185 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
186 + _Complex_I)) Cfct (Val) \
187 : (sizeof (__real__ (Val)) == sizeof (float)) \
188 ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
189 + _Complex_I)) Cfct##f (Val) \
190 : (__typeof__ ((__tgmath_real_type (Val)) 0 \
191 + _Complex_I)) __tgml(Cfct) (Val)))
dfd2257a 192
58d87ee1
UD
193/* XXX This definition has to be changed as soon as the compiler understands
194 the imaginary keyword. */
195# define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
1c298d08
UD
196 (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
197 || __builtin_classify_type (__real__ (Val)) != 8) \
198 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
199 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
200 Fct (Val) \
201 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
202 Cfct (Val)) \
203 : (sizeof (__real__ (Val)) == sizeof (float)) \
204 ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
205 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
206 Fct##f (Val) \
207 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
208 Cfct##f (Val)) \
209 : ((sizeof (__real__ (Val)) == sizeof (Val)) \
210 ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
211 __tgml(Fct) (Val) \
212 : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
213 __tgml(Cfct) (Val))))
58d87ee1 214
48244d09
UD
215/* XXX This definition has to be changed as soon as the compiler understands
216 the imaginary keyword. */
dfd2257a 217# define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
1c298d08
UD
218 (__extension__ (((sizeof (__real__ (Val1)) > sizeof (double) \
219 || sizeof (__real__ (Val2)) > sizeof (double)) \
220 && __builtin_classify_type (__real__ (Val1) \
221 + __real__ (Val2)) == 8) \
222 ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
223 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
224 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
225 + (__tgmath_real_type (Val2)) 0)) \
226 __tgml(Fct) (Val1, Val2) \
227 : (__typeof ((__tgmath_real_type (Val1)) 0 \
228 + (__tgmath_real_type (Val2)) 0)) \
229 __tgml(Cfct) (Val1, Val2)) \
230 : (sizeof (__real__ (Val1)) == sizeof (double) \
231 || sizeof (__real__ (Val2)) == sizeof (double) \
232 || __builtin_classify_type (__real__ (Val1)) != 8 \
233 || __builtin_classify_type (__real__ (Val2)) != 8) \
234 ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
235 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
236 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
237 + (__tgmath_real_type (Val2)) 0)) \
238 Fct (Val1, Val2) \
239 : (__typeof ((__tgmath_real_type (Val1)) 0 \
240 + (__tgmath_real_type (Val2)) 0)) \
241 Cfct (Val1, Val2)) \
242 : ((sizeof (__real__ (Val1)) == sizeof (Val1) \
243 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
244 ? (__typeof ((__tgmath_real_type (Val1)) 0 \
245 + (__tgmath_real_type (Val2)) 0)) \
246 Fct##f (Val1, Val2) \
247 : (__typeof ((__tgmath_real_type (Val1)) 0 \
248 + (__tgmath_real_type (Val2)) 0)) \
249 Cfct##f (Val1, Val2))))
dfd2257a
UD
250#else
251# error "Unsupported compiler; you cannot use <tgmath.h>"
252#endif
253
254
255/* Unary functions defined for real and complex values. */
256
257
258/* Trigonometric functions. */
259
260/* Arc cosine of X. */
261#define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
262/* Arc sine of X. */
263#define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
264/* Arc tangent of X. */
265#define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
266/* Arc tangent of Y/X. */
cfb32a6c 267#define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
dfd2257a
UD
268
269/* Cosine of X. */
270#define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
271/* Sine of X. */
272#define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
273/* Tangent of X. */
274#define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
275
276
277/* Hyperbolic functions. */
278
279/* Hyperbolic arc cosine of X. */
280#define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
281/* Hyperbolic arc sine of X. */
282#define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
283/* Hyperbolic arc tangent of X. */
284#define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
285
286/* Hyperbolic cosine of X. */
287#define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
288/* Hyperbolic sine of X. */
289#define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
290/* Hyperbolic tangent of X. */
291#define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
292
293
294/* Exponential and logarithmic functions. */
295
296/* Exponential function of X. */
297#define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
298
299/* Break VALUE into a normalized fraction and an integral power of 2. */
300#define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
301
302/* X times (two to the EXP power). */
303#define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
304
305/* Natural logarithm of X. */
306#define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
307
308/* Base-ten logarithm of X. */
cc3fa755
UD
309#ifdef __USE_GNU
310# define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, __clog10)
311#else
312# define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
313#endif
dfd2257a
UD
314
315/* Return exp(X) - 1. */
316#define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
317
318/* Return log(1 + X). */
319#define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
320
321/* Return the base 2 signed integral exponent of X. */
322#define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
323
324/* Compute base-2 exponential of X. */
325#define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
326
327/* Compute base-2 logarithm of X. */
328#define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
329
330
331/* Power functions. */
332
333/* Return X to the Y power. */
334#define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
335
336/* Return the square root of X. */
337#define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
338
339/* Return `sqrt(X*X + Y*Y)'. */
340#define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
341
342/* Return the cube root of X. */
343#define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
344
345
346/* Nearest integer, absolute value, and remainder functions. */
347
348/* Smallest integral value not less than X. */
349#define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
350
351/* Absolute value of X. */
f1debaf6 352#define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs)
dfd2257a
UD
353
354/* Largest integer not greater than X. */
355#define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
356
357/* Floating-point modulo remainder of X/Y. */
358#define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
359
360/* Round X to integral valuein floating-point format using current
361 rounding direction, but do not raise inexact exception. */
362#define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
363
364/* Round X to nearest integral value, rounding halfway cases away from
365 zero. */
366#define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
367
368/* Round X to the integral value in floating-point format nearest but
369 not larger in magnitude. */
370#define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
371
372/* Compute remainder of X and Y and put in *QUO a value with sign of x/y
373 and magnitude congruent `mod 2^n' to the magnitude of the integral
374 quotient x/y, with n >= 3. */
375#define remquo(Val1, Val2, Val3) \
376 __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
377
378/* Round X to nearest integral value according to current rounding
379 direction. */
71502ebe
UD
380#define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, lrint)
381#define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long long int, llrint)
dfd2257a
UD
382
383/* Round X to nearest integral value, rounding halfway cases away from
384 zero. */
71502ebe
UD
385#define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, lround)
386#define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long long int, llround)
dfd2257a
UD
387
388
389/* Return X with its signed changed to Y's. */
390#define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
391
392/* Error and gamma functions. */
393#define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
394#define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
00d8bc81 395#define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
dfd2257a
UD
396#define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
397
398
399/* Return the integer nearest X in the direction of the
400 prevailing rounding mode. */
401#define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
402
146f208d 403#if __GLIBC_USE (IEC_60559_BFP_EXT)
41a359e2
RS
404/* Return X - epsilon. */
405# define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown)
406/* Return X + epsilon. */
407# define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup)
408#endif
409
dfd2257a
UD
410/* Return X + epsilon if X < Y, X - epsilon if X > Y. */
411#define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
42bd0a85
UD
412#define nexttoward(Val1, Val2) \
413 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, nexttoward)
dfd2257a
UD
414
415/* Return the remainder of integer divison X / Y with infinite precision. */
416#define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
417
418/* Return X times (2 to the Nth power). */
de20571d 419#ifdef __USE_MISC
204e299e 420# define scalb(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, scalb)
26644e87 421#endif
dfd2257a
UD
422
423/* Return X times (2 to the Nth power). */
424#define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
425
426/* Return X times (2 to the Nth power). */
427#define scalbln(Val1, Val2) \
428 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
429
430/* Return the binary exponent of X, which must be nonzero. */
301a6724 431#define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, int, ilogb)
dfd2257a
UD
432
433
434/* Return positive difference between X and Y. */
435#define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
436
437/* Return maximum numeric value from X and Y. */
438#define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
439
440/* Return minimum numeric value from X and Y. */
441#define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
442
443
bfce746a 444/* Multiply-add function computed as a ternary operation. */
e7c3d12b 445#define fma(Val1, Val2, Val3) \
bfce746a
UD
446 __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
447
5e9d98a3 448#if __GLIBC_USE (IEC_60559_BFP_EXT)
41c67149
JM
449/* Round X to nearest integer value, rounding halfway cases to even. */
450# define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven)
451
423c2b9d
JM
452# define fromfp(Val1, Val2, Val3) \
453 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __intmax_t, fromfp)
454
455# define ufromfp(Val1, Val2, Val3) \
456 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __uintmax_t, ufromfp)
457
458# define fromfpx(Val1, Val2, Val3) \
459 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __intmax_t, fromfpx)
460
461# define ufromfpx(Val1, Val2, Val3) \
462 __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, __uintmax_t, ufromfpx)
463
55a38f82 464/* Like ilogb, but returning long int. */
60c07b05 465# define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, llogb)
55a38f82 466
525f8039
JM
467/* Return value with maximum magnitude. */
468# define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag)
469
470/* Return value with minimum magnitude. */
471# define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
472
5e9d98a3
JM
473/* Total order operation. */
474# define totalorder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \
475 totalorder)
cc6a8d74
JM
476
477/* Total order operation on absolute values. */
478# define totalordermag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \
479 totalordermag)
5e9d98a3
JM
480#endif
481
bfce746a 482
dfd2257a
UD
483/* Absolute value, conjugates, and projection. */
484
485/* Argument value of Z. */
f1debaf6 486#define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, carg, carg)
dfd2257a
UD
487
488/* Complex conjugate of Z. */
1c298d08 489#define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
dfd2257a
UD
490
491/* Projection of Z onto the Riemann sphere. */
1c298d08 492#define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
dfd2257a
UD
493
494
495/* Decomposing complex values. */
496
497/* Imaginary part of Z. */
58d87ee1 498#define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, cimag, cimag)
dfd2257a
UD
499
500/* Real part of Z. */
58d87ee1 501#define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, creal, creal)
dfd2257a
UD
502
503#endif /* tgmath.h */