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