]>
Commit | Line | Data |
---|---|---|
bfff8b1b | 1 | /* Copyright (C) 1997-2017 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 | 80 | |
cfa44345 | 81 | # define __TGMATH_UNARY_REAL_RET_ONLY(Val, Fct) \ |
1c298d08 UD |
82 | (__extension__ ((sizeof (Val) == sizeof (double) \ |
83 | || __builtin_classify_type (Val) != 8) \ | |
cfa44345 | 84 | ? Fct (Val) \ |
1c298d08 | 85 | : (sizeof (Val) == sizeof (float)) \ |
cfa44345 JM |
86 | ? Fct##f (Val) \ |
87 | : __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 | 114 | |
d12a22c5 JM |
115 | # define __TGMATH_BINARY_REAL_RET_ONLY(Val1, Val2, Fct) \ |
116 | (__extension__ (((sizeof (Val1) > sizeof (double) \ | |
117 | || sizeof (Val2) > sizeof (double)) \ | |
118 | && __builtin_classify_type ((Val1) + (Val2)) == 8) \ | |
119 | ? __tgml(Fct) (Val1, Val2) \ | |
120 | : (sizeof (Val1) == sizeof (double) \ | |
121 | || sizeof (Val2) == sizeof (double) \ | |
122 | || __builtin_classify_type (Val1) != 8 \ | |
123 | || __builtin_classify_type (Val2) != 8) \ | |
124 | ? Fct (Val1, Val2) \ | |
125 | : Fct##f (Val1, Val2))) | |
126 | ||
dfd2257a | 127 | # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \ |
1c298d08 UD |
128 | (__extension__ (((sizeof (Val1) > sizeof (double) \ |
129 | || sizeof (Val2) > sizeof (double)) \ | |
130 | && __builtin_classify_type ((Val1) + (Val2)) == 8) \ | |
131 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
132 | + (__tgmath_real_type (Val2)) 0)) \ | |
133 | __tgml(Fct) (Val1, Val2, Val3) \ | |
134 | : (sizeof (Val1) == sizeof (double) \ | |
135 | || sizeof (Val2) == sizeof (double) \ | |
136 | || __builtin_classify_type (Val1) != 8 \ | |
137 | || __builtin_classify_type (Val2) != 8) \ | |
138 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
139 | + (__tgmath_real_type (Val2)) 0)) \ | |
140 | Fct (Val1, Val2, Val3) \ | |
141 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
142 | + (__tgmath_real_type (Val2)) 0)) \ | |
143 | Fct##f (Val1, Val2, Val3))) | |
bfce746a UD |
144 | |
145 | # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \ | |
1c298d08 UD |
146 | (__extension__ (((sizeof (Val1) > sizeof (double) \ |
147 | || sizeof (Val2) > sizeof (double) \ | |
148 | || sizeof (Val3) > sizeof (double)) \ | |
149 | && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \ | |
150 | == 8) \ | |
151 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
152 | + (__tgmath_real_type (Val2)) 0 \ | |
153 | + (__tgmath_real_type (Val3)) 0)) \ | |
154 | __tgml(Fct) (Val1, Val2, Val3) \ | |
155 | : (sizeof (Val1) == sizeof (double) \ | |
156 | || sizeof (Val2) == sizeof (double) \ | |
157 | || sizeof (Val3) == sizeof (double) \ | |
158 | || __builtin_classify_type (Val1) != 8 \ | |
159 | || __builtin_classify_type (Val2) != 8 \ | |
160 | || __builtin_classify_type (Val3) != 8) \ | |
161 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
162 | + (__tgmath_real_type (Val2)) 0 \ | |
163 | + (__tgmath_real_type (Val3)) 0)) \ | |
164 | Fct (Val1, Val2, Val3) \ | |
165 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
166 | + (__tgmath_real_type (Val2)) 0 \ | |
167 | + (__tgmath_real_type (Val3)) 0)) \ | |
168 | Fct##f (Val1, Val2, Val3))) | |
dfd2257a | 169 | |
cfa44345 | 170 | # define __TGMATH_TERNARY_FIRST_REAL_RET_ONLY(Val1, Val2, Val3, Fct) \ |
423c2b9d JM |
171 | (__extension__ ((sizeof (Val1) == sizeof (double) \ |
172 | || __builtin_classify_type (Val1) != 8) \ | |
cfa44345 | 173 | ? Fct (Val1, Val2, Val3) \ |
423c2b9d | 174 | : (sizeof (Val1) == sizeof (float)) \ |
cfa44345 JM |
175 | ? Fct##f (Val1, Val2, Val3) \ |
176 | : __tgml(Fct) (Val1, Val2, Val3))) | |
423c2b9d | 177 | |
48244d09 UD |
178 | /* XXX This definition has to be changed as soon as the compiler understands |
179 | the imaginary keyword. */ | |
dfd2257a | 180 | # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \ |
1c298d08 UD |
181 | (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \ |
182 | || __builtin_classify_type (__real__ (Val)) != 8) \ | |
183 | ? ((sizeof (__real__ (Val)) == sizeof (Val)) \ | |
184 | ? (__tgmath_real_type (Val)) Fct (Val) \ | |
185 | : (__tgmath_real_type (Val)) Cfct (Val)) \ | |
186 | : (sizeof (__real__ (Val)) == sizeof (float)) \ | |
187 | ? ((sizeof (__real__ (Val)) == sizeof (Val)) \ | |
188 | ? (__tgmath_real_type (Val)) Fct##f (Val) \ | |
189 | : (__tgmath_real_type (Val)) Cfct##f (Val)) \ | |
190 | : ((sizeof (__real__ (Val)) == sizeof (Val)) \ | |
191 | ? (__tgmath_real_type (Val)) __tgml(Fct) (Val) \ | |
192 | : (__tgmath_real_type (Val)) __tgml(Cfct) (Val)))) | |
193 | ||
194 | # define __TGMATH_UNARY_IMAG(Val, Cfct) \ | |
195 | (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \ | |
196 | || __builtin_classify_type (__real__ (Val)) != 8) \ | |
197 | ? (__typeof__ ((__tgmath_real_type (Val)) 0 \ | |
198 | + _Complex_I)) Cfct (Val) \ | |
199 | : (sizeof (__real__ (Val)) == sizeof (float)) \ | |
200 | ? (__typeof__ ((__tgmath_real_type (Val)) 0 \ | |
201 | + _Complex_I)) Cfct##f (Val) \ | |
202 | : (__typeof__ ((__tgmath_real_type (Val)) 0 \ | |
203 | + _Complex_I)) __tgml(Cfct) (Val))) | |
dfd2257a | 204 | |
58d87ee1 UD |
205 | /* XXX This definition has to be changed as soon as the compiler understands |
206 | the imaginary keyword. */ | |
207 | # define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \ | |
1c298d08 UD |
208 | (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \ |
209 | || __builtin_classify_type (__real__ (Val)) != 8) \ | |
210 | ? ((sizeof (__real__ (Val)) == sizeof (Val)) \ | |
211 | ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
212 | Fct (Val) \ | |
213 | : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
214 | Cfct (Val)) \ | |
215 | : (sizeof (__real__ (Val)) == sizeof (float)) \ | |
216 | ? ((sizeof (__real__ (Val)) == sizeof (Val)) \ | |
217 | ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
218 | Fct##f (Val) \ | |
219 | : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
220 | Cfct##f (Val)) \ | |
221 | : ((sizeof (__real__ (Val)) == sizeof (Val)) \ | |
222 | ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
223 | __tgml(Fct) (Val) \ | |
224 | : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\ | |
225 | __tgml(Cfct) (Val)))) | |
58d87ee1 | 226 | |
48244d09 UD |
227 | /* XXX This definition has to be changed as soon as the compiler understands |
228 | the imaginary keyword. */ | |
dfd2257a | 229 | # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \ |
1c298d08 UD |
230 | (__extension__ (((sizeof (__real__ (Val1)) > sizeof (double) \ |
231 | || sizeof (__real__ (Val2)) > sizeof (double)) \ | |
232 | && __builtin_classify_type (__real__ (Val1) \ | |
233 | + __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 | __tgml(Fct) (Val1, Val2) \ | |
239 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
240 | + (__tgmath_real_type (Val2)) 0)) \ | |
241 | __tgml(Cfct) (Val1, Val2)) \ | |
242 | : (sizeof (__real__ (Val1)) == sizeof (double) \ | |
243 | || sizeof (__real__ (Val2)) == sizeof (double) \ | |
244 | || __builtin_classify_type (__real__ (Val1)) != 8 \ | |
245 | || __builtin_classify_type (__real__ (Val2)) != 8) \ | |
246 | ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \ | |
247 | && sizeof (__real__ (Val2)) == sizeof (Val2)) \ | |
248 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
249 | + (__tgmath_real_type (Val2)) 0)) \ | |
250 | Fct (Val1, Val2) \ | |
251 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
252 | + (__tgmath_real_type (Val2)) 0)) \ | |
253 | Cfct (Val1, Val2)) \ | |
254 | : ((sizeof (__real__ (Val1)) == sizeof (Val1) \ | |
255 | && sizeof (__real__ (Val2)) == sizeof (Val2)) \ | |
256 | ? (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
257 | + (__tgmath_real_type (Val2)) 0)) \ | |
258 | Fct##f (Val1, Val2) \ | |
259 | : (__typeof ((__tgmath_real_type (Val1)) 0 \ | |
260 | + (__tgmath_real_type (Val2)) 0)) \ | |
261 | Cfct##f (Val1, Val2)))) | |
dfd2257a UD |
262 | #else |
263 | # error "Unsupported compiler; you cannot use <tgmath.h>" | |
264 | #endif | |
265 | ||
266 | ||
267 | /* Unary functions defined for real and complex values. */ | |
268 | ||
269 | ||
270 | /* Trigonometric functions. */ | |
271 | ||
272 | /* Arc cosine of X. */ | |
273 | #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos) | |
274 | /* Arc sine of X. */ | |
275 | #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin) | |
276 | /* Arc tangent of X. */ | |
277 | #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan) | |
278 | /* Arc tangent of Y/X. */ | |
cfb32a6c | 279 | #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2) |
dfd2257a UD |
280 | |
281 | /* Cosine of X. */ | |
282 | #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos) | |
283 | /* Sine of X. */ | |
284 | #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin) | |
285 | /* Tangent of X. */ | |
286 | #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan) | |
287 | ||
288 | ||
289 | /* Hyperbolic functions. */ | |
290 | ||
291 | /* Hyperbolic arc cosine of X. */ | |
292 | #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh) | |
293 | /* Hyperbolic arc sine of X. */ | |
294 | #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh) | |
295 | /* Hyperbolic arc tangent of X. */ | |
296 | #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh) | |
297 | ||
298 | /* Hyperbolic cosine of X. */ | |
299 | #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh) | |
300 | /* Hyperbolic sine of X. */ | |
301 | #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh) | |
302 | /* Hyperbolic tangent of X. */ | |
303 | #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh) | |
304 | ||
305 | ||
306 | /* Exponential and logarithmic functions. */ | |
307 | ||
308 | /* Exponential function of X. */ | |
309 | #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp) | |
310 | ||
311 | /* Break VALUE into a normalized fraction and an integral power of 2. */ | |
312 | #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp) | |
313 | ||
314 | /* X times (two to the EXP power). */ | |
315 | #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp) | |
316 | ||
317 | /* Natural logarithm of X. */ | |
318 | #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog) | |
319 | ||
320 | /* Base-ten logarithm of X. */ | |
cc3fa755 | 321 | #ifdef __USE_GNU |
0908a38a | 322 | # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, clog10) |
cc3fa755 UD |
323 | #else |
324 | # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10) | |
325 | #endif | |
dfd2257a UD |
326 | |
327 | /* Return exp(X) - 1. */ | |
328 | #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1) | |
329 | ||
330 | /* Return log(1 + X). */ | |
331 | #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p) | |
332 | ||
333 | /* Return the base 2 signed integral exponent of X. */ | |
334 | #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb) | |
335 | ||
336 | /* Compute base-2 exponential of X. */ | |
337 | #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2) | |
338 | ||
339 | /* Compute base-2 logarithm of X. */ | |
340 | #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2) | |
341 | ||
342 | ||
343 | /* Power functions. */ | |
344 | ||
345 | /* Return X to the Y power. */ | |
346 | #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow) | |
347 | ||
348 | /* Return the square root of X. */ | |
349 | #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt) | |
350 | ||
351 | /* Return `sqrt(X*X + Y*Y)'. */ | |
352 | #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot) | |
353 | ||
354 | /* Return the cube root of X. */ | |
355 | #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt) | |
356 | ||
357 | ||
358 | /* Nearest integer, absolute value, and remainder functions. */ | |
359 | ||
360 | /* Smallest integral value not less than X. */ | |
361 | #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil) | |
362 | ||
363 | /* Absolute value of X. */ | |
f1debaf6 | 364 | #define fabs(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, fabs, cabs) |
dfd2257a UD |
365 | |
366 | /* Largest integer not greater than X. */ | |
367 | #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor) | |
368 | ||
369 | /* Floating-point modulo remainder of X/Y. */ | |
370 | #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod) | |
371 | ||
372 | /* Round X to integral valuein floating-point format using current | |
373 | rounding direction, but do not raise inexact exception. */ | |
374 | #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint) | |
375 | ||
376 | /* Round X to nearest integral value, rounding halfway cases away from | |
377 | zero. */ | |
378 | #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round) | |
379 | ||
380 | /* Round X to the integral value in floating-point format nearest but | |
381 | not larger in magnitude. */ | |
382 | #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc) | |
383 | ||
384 | /* Compute remainder of X and Y and put in *QUO a value with sign of x/y | |
385 | and magnitude congruent `mod 2^n' to the magnitude of the integral | |
386 | quotient x/y, with n >= 3. */ | |
387 | #define remquo(Val1, Val2, Val3) \ | |
388 | __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo) | |
389 | ||
390 | /* Round X to nearest integral value according to current rounding | |
391 | direction. */ | |
cfa44345 JM |
392 | #define lrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lrint) |
393 | #define llrint(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llrint) | |
dfd2257a UD |
394 | |
395 | /* Round X to nearest integral value, rounding halfway cases away from | |
396 | zero. */ | |
cfa44345 JM |
397 | #define lround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, lround) |
398 | #define llround(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llround) | |
dfd2257a UD |
399 | |
400 | ||
401 | /* Return X with its signed changed to Y's. */ | |
402 | #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign) | |
403 | ||
404 | /* Error and gamma functions. */ | |
405 | #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf) | |
406 | #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc) | |
00d8bc81 | 407 | #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma) |
dfd2257a UD |
408 | #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma) |
409 | ||
410 | ||
411 | /* Return the integer nearest X in the direction of the | |
412 | prevailing rounding mode. */ | |
413 | #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint) | |
414 | ||
146f208d | 415 | #if __GLIBC_USE (IEC_60559_BFP_EXT) |
41a359e2 RS |
416 | /* Return X - epsilon. */ |
417 | # define nextdown(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextdown) | |
418 | /* Return X + epsilon. */ | |
419 | # define nextup(Val) __TGMATH_UNARY_REAL_ONLY (Val, nextup) | |
420 | #endif | |
421 | ||
dfd2257a UD |
422 | /* Return X + epsilon if X < Y, X - epsilon if X > Y. */ |
423 | #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter) | |
42bd0a85 UD |
424 | #define nexttoward(Val1, Val2) \ |
425 | __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, nexttoward) | |
dfd2257a UD |
426 | |
427 | /* Return the remainder of integer divison X / Y with infinite precision. */ | |
428 | #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder) | |
429 | ||
430 | /* Return X times (2 to the Nth power). */ | |
de20571d | 431 | #ifdef __USE_MISC |
204e299e | 432 | # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, scalb) |
26644e87 | 433 | #endif |
dfd2257a UD |
434 | |
435 | /* Return X times (2 to the Nth power). */ | |
436 | #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn) | |
437 | ||
438 | /* Return X times (2 to the Nth power). */ | |
439 | #define scalbln(Val1, Val2) \ | |
440 | __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln) | |
441 | ||
442 | /* Return the binary exponent of X, which must be nonzero. */ | |
cfa44345 | 443 | #define ilogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, ilogb) |
dfd2257a UD |
444 | |
445 | ||
446 | /* Return positive difference between X and Y. */ | |
447 | #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim) | |
448 | ||
449 | /* Return maximum numeric value from X and Y. */ | |
450 | #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax) | |
451 | ||
452 | /* Return minimum numeric value from X and Y. */ | |
453 | #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin) | |
454 | ||
455 | ||
bfce746a | 456 | /* Multiply-add function computed as a ternary operation. */ |
e7c3d12b | 457 | #define fma(Val1, Val2, Val3) \ |
bfce746a UD |
458 | __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma) |
459 | ||
5e9d98a3 | 460 | #if __GLIBC_USE (IEC_60559_BFP_EXT) |
41c67149 JM |
461 | /* Round X to nearest integer value, rounding halfway cases to even. */ |
462 | # define roundeven(Val) __TGMATH_UNARY_REAL_ONLY (Val, roundeven) | |
463 | ||
423c2b9d | 464 | # define fromfp(Val1, Val2, Val3) \ |
cfa44345 | 465 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfp) |
423c2b9d JM |
466 | |
467 | # define ufromfp(Val1, Val2, Val3) \ | |
cfa44345 | 468 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfp) |
423c2b9d JM |
469 | |
470 | # define fromfpx(Val1, Val2, Val3) \ | |
cfa44345 | 471 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, fromfpx) |
423c2b9d JM |
472 | |
473 | # define ufromfpx(Val1, Val2, Val3) \ | |
cfa44345 | 474 | __TGMATH_TERNARY_FIRST_REAL_RET_ONLY (Val1, Val2, Val3, ufromfpx) |
423c2b9d | 475 | |
55a38f82 | 476 | /* Like ilogb, but returning long int. */ |
cfa44345 | 477 | # define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, llogb) |
55a38f82 | 478 | |
525f8039 JM |
479 | /* Return value with maximum magnitude. */ |
480 | # define fmaxmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmaxmag) | |
481 | ||
482 | /* Return value with minimum magnitude. */ | |
483 | # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag) | |
484 | ||
5e9d98a3 | 485 | /* Total order operation. */ |
d12a22c5 JM |
486 | # define totalorder(Val1, Val2) \ |
487 | __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalorder) | |
cc6a8d74 JM |
488 | |
489 | /* Total order operation on absolute values. */ | |
d12a22c5 JM |
490 | # define totalordermag(Val1, Val2) \ |
491 | __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalordermag) | |
5e9d98a3 JM |
492 | #endif |
493 | ||
bfce746a | 494 | |
dfd2257a UD |
495 | /* Absolute value, conjugates, and projection. */ |
496 | ||
497 | /* Argument value of Z. */ | |
f1debaf6 | 498 | #define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, carg, carg) |
dfd2257a UD |
499 | |
500 | /* Complex conjugate of Z. */ | |
1c298d08 | 501 | #define conj(Val) __TGMATH_UNARY_IMAG (Val, conj) |
dfd2257a UD |
502 | |
503 | /* Projection of Z onto the Riemann sphere. */ | |
1c298d08 | 504 | #define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj) |
dfd2257a UD |
505 | |
506 | ||
507 | /* Decomposing complex values. */ | |
508 | ||
509 | /* Imaginary part of Z. */ | |
58d87ee1 | 510 | #define cimag(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, cimag, cimag) |
dfd2257a UD |
511 | |
512 | /* Real part of Z. */ | |
58d87ee1 | 513 | #define creal(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, creal, creal) |
dfd2257a UD |
514 | |
515 | #endif /* tgmath.h */ |