GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / arm-brcm-linux-uclibcgnueabi / sysroot / usr / include / tgmath.h
blobfc9c9ffaf6c8223670eb319d178c256b15b6741c
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
20 * ISO C99 Standard: 7.22 Type-generic math <tgmath.h>
23 #ifndef _TGMATH_H
24 #define _TGMATH_H 1
26 /* Include the needed headers. */
27 #include <math.h>
28 #include <complex.h>
31 /* Since `complex' is currently not really implemented in most C compilers
32 and if it is implemented, the implementations differ. This makes it
33 quite difficult to write a generic implementation of this header. We
34 do not try this for now and instead concentrate only on GNU CC. Once
35 we have more information support for other compilers might follow. */
37 #if __GNUC_PREREQ (2, 7)
39 # ifdef __NO_LONG_DOUBLE_MATH
40 # define __tgml(fct) fct
41 # else
42 # define __tgml(fct) fct ## l
43 # endif
45 /* This is ugly but unless gcc gets appropriate builtins we have to do
46 something like this. Don't ask how it works. */
48 /* 1 if 'type' is a floating type, 0 if 'type' is an integer type.
49 Allows for _Bool. Expands to an integer constant expression. */
50 # define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))
52 /* The tgmath real type for T, where E is 0 if T is an integer type and
53 1 for a floating type. */
54 # define __tgmath_real_type_sub(T, E) \
55 __typeof__(*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
56 : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
58 /* The tgmath real type of EXPR. */
59 # define __tgmath_real_type(expr) \
60 __tgmath_real_type_sub(__typeof__(expr), __floating_type(__typeof__(expr)))
63 /* We have two kinds of generic macros: to support functions which are
64 only defined on real valued parameters and those which are defined
65 for complex functions as well. */
66 # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
67 (__extension__ ({ __tgmath_real_type (Val) __tgmres; \
68 if (sizeof (Val) == sizeof (double) \
69 || __builtin_classify_type (Val) != 8) \
70 __tgmres = Fct (Val); \
71 else if (sizeof (Val) == sizeof (float)) \
72 __tgmres = Fct##f (Val); \
73 else \
74 __tgmres = __tgml(Fct) (Val); \
75 __tgmres; }))
77 # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
78 (__extension__ ({ __tgmath_real_type (Val1) __tgmres; \
79 if (sizeof (Val1) == sizeof (double) \
80 || __builtin_classify_type (Val1) != 8) \
81 __tgmres = Fct (Val1, Val2); \
82 else if (sizeof (Val1) == sizeof (float)) \
83 __tgmres = Fct##f (Val1, Val2); \
84 else \
85 __tgmres = __tgml(Fct) (Val1, Val2); \
86 __tgmres; }))
88 # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
89 (__extension__ ({ __tgmath_real_type ((Val1) + (Val2)) __tgmres; \
90 if ((sizeof (Val1) > sizeof (double) \
91 || sizeof (Val2) > sizeof (double)) \
92 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
93 __tgmres = __tgml(Fct) (Val1, Val2); \
94 else if (sizeof (Val1) == sizeof (double) \
95 || sizeof (Val2) == sizeof (double) \
96 || __builtin_classify_type (Val1) != 8 \
97 || __builtin_classify_type (Val2) != 8) \
98 __tgmres = Fct (Val1, Val2); \
99 else \
100 __tgmres = Fct##f (Val1, Val2); \
101 __tgmres; }))
103 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
104 (__extension__ ({ __tgmath_real_type ((Val1) + (Val2)) __tgmres; \
105 if ((sizeof (Val1) > sizeof (double) \
106 || sizeof (Val2) > sizeof (double)) \
107 && __builtin_classify_type ((Val1) + (Val2)) == 8) \
108 __tgmres = __tgml(Fct) (Val1, Val2, Val3); \
109 else if (sizeof (Val1) == sizeof (double) \
110 || sizeof (Val2) == sizeof (double) \
111 || __builtin_classify_type (Val1) != 8 \
112 || __builtin_classify_type (Val2) != 8) \
113 __tgmres = Fct (Val1, Val2, Val3); \
114 else \
115 __tgmres = Fct##f (Val1, Val2, Val3); \
116 __tgmres; }))
118 # define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
119 (__extension__ ({ __tgmath_real_type ((Val1) + (Val2) + (Val3)) __tgmres;\
120 if ((sizeof (Val1) > sizeof (double) \
121 || sizeof (Val2) > sizeof (double) \
122 || sizeof (Val3) > sizeof (double)) \
123 && __builtin_classify_type ((Val1) + (Val2) \
124 + (Val3)) == 8) \
125 __tgmres = __tgml(Fct) (Val1, Val2, Val3); \
126 else if (sizeof (Val1) == sizeof (double) \
127 || sizeof (Val2) == sizeof (double) \
128 || sizeof (Val3) == sizeof (double) \
129 || __builtin_classify_type (Val1) != 8 \
130 || __builtin_classify_type (Val2) != 8 \
131 || __builtin_classify_type (Val3) != 8) \
132 __tgmres = Fct (Val1, Val2, Val3); \
133 else \
134 __tgmres = Fct##f (Val1, Val2, Val3); \
135 __tgmres; }))
137 /* XXX This definition has to be changed as soon as the compiler understands
138 the imaginary keyword. */
139 # define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
140 (__extension__ ({ __tgmath_real_type (Val) __tgmres; \
141 if (sizeof (__real__ (Val)) > sizeof (double) \
142 && __builtin_classify_type (__real__ (Val)) == 8) \
144 if (sizeof (__real__ (Val)) == sizeof (Val)) \
145 __tgmres = __tgml(Fct) (Val); \
146 else \
147 __tgmres = __tgml(Cfct) (Val); \
149 else if (sizeof (__real__ (Val)) == sizeof (double) \
150 || __builtin_classify_type (__real__ (Val)) \
151 != 8) \
153 if (sizeof (__real__ (Val)) == sizeof (Val)) \
154 __tgmres = Fct (Val); \
155 else \
156 __tgmres = Cfct (Val); \
158 else \
160 if (sizeof (__real__ (Val)) == sizeof (Val)) \
161 __tgmres = Fct##f (Val); \
162 else \
163 __tgmres = Cfct##f (Val); \
165 __tgmres; }))
167 /* XXX This definition has to be changed as soon as the compiler understands
168 the imaginary keyword. */
169 # define __TGMATH_UNARY_IMAG_ONLY(Val, Fct) \
170 (__extension__ ({ __tgmath_real_type (Val) __tgmres; \
171 if (sizeof (Val) == sizeof (__complex__ double) \
172 || __builtin_classify_type (__real__ (Val)) != 8) \
173 __tgmres = Fct (Val); \
174 else if (sizeof (Val) == sizeof (__complex__ float)) \
175 __tgmres = Fct##f (Val); \
176 else \
177 __tgmres = __tgml(Fct) (Val); \
178 __tgmres; }))
180 /* XXX This definition has to be changed as soon as the compiler understands
181 the imaginary keyword. */
182 # define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
183 (__extension__ ({ __tgmath_real_type ((Val1) + (Val2)) __tgmres; \
184 if ((sizeof (__real__ (Val1)) > sizeof (double) \
185 || sizeof (__real__ (Val2)) > sizeof (double)) \
186 && __builtin_classify_type (__real__ (Val1) \
187 + __real__ (Val2)) \
188 == 8) \
190 if (sizeof (__real__ (Val1)) == sizeof (Val1) \
191 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
192 __tgmres = __tgml(Fct) (Val1, Val2); \
193 else \
194 __tgmres = __tgml(Cfct) (Val1, Val2); \
196 else if (sizeof (__real__ (Val1)) == sizeof (double) \
197 || sizeof (__real__ (Val2)) == sizeof(double) \
198 || (__builtin_classify_type (__real__ (Val1)) \
199 != 8) \
200 || (__builtin_classify_type (__real__ (Val2)) \
201 != 8)) \
203 if (sizeof (__real__ (Val1)) == sizeof (Val1) \
204 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
205 __tgmres = Fct (Val1, Val2); \
206 else \
207 __tgmres = Cfct (Val1, Val2); \
209 else \
211 if (sizeof (__real__ (Val1)) == sizeof (Val1) \
212 && sizeof (__real__ (Val2)) == sizeof (Val2)) \
213 __tgmres = Fct##f (Val1, Val2); \
214 else \
215 __tgmres = Cfct##f (Val1, Val2); \
217 __tgmres; }))
218 #else
219 # error "Unsupported compiler; you cannot use <tgmath.h>"
220 #endif
223 /* Unary functions defined for real and complex values. */
226 /* Trigonometric functions. */
228 /* Arc cosine of X. */
229 #define acos(Val) __TGMATH_UNARY_REAL_IMAG (Val, acos, cacos)
230 /* Arc sine of X. */
231 #define asin(Val) __TGMATH_UNARY_REAL_IMAG (Val, asin, casin)
232 /* Arc tangent of X. */
233 #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
234 /* Arc tangent of Y/X. */
235 #define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
237 /* Cosine of X. */
238 #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
239 /* Sine of X. */
240 #define sin(Val) __TGMATH_UNARY_REAL_IMAG (Val, sin, csin)
241 /* Tangent of X. */
242 #define tan(Val) __TGMATH_UNARY_REAL_IMAG (Val, tan, ctan)
245 /* Hyperbolic functions. */
247 /* Hyperbolic arc cosine of X. */
248 #define acosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, acosh, cacosh)
249 /* Hyperbolic arc sine of X. */
250 #define asinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, asinh, casinh)
251 /* Hyperbolic arc tangent of X. */
252 #define atanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, atanh, catanh)
254 /* Hyperbolic cosine of X. */
255 #define cosh(Val) __TGMATH_UNARY_REAL_IMAG (Val, cosh, ccosh)
256 /* Hyperbolic sine of X. */
257 #define sinh(Val) __TGMATH_UNARY_REAL_IMAG (Val, sinh, csinh)
258 /* Hyperbolic tangent of X. */
259 #define tanh(Val) __TGMATH_UNARY_REAL_IMAG (Val, tanh, ctanh)
262 /* Exponential and logarithmic functions. */
264 /* Exponential function of X. */
265 #define exp(Val) __TGMATH_UNARY_REAL_IMAG (Val, exp, cexp)
267 /* Break VALUE into a normalized fraction and an integral power of 2. */
268 #define frexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, frexp)
270 /* X times (two to the EXP power). */
271 #define ldexp(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, ldexp)
273 /* Natural logarithm of X. */
274 #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
276 /* Base-ten logarithm of X. */
277 #ifdef __USE_GNU
278 # define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, __clog10)
279 #else
280 # define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
281 #endif
283 /* Return exp(X) - 1. */
284 #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
286 /* Return log(1 + X). */
287 #define log1p(Val) __TGMATH_UNARY_REAL_ONLY (Val, log1p)
289 /* Return the base 2 signed integral exponent of X. */
290 #define logb(Val) __TGMATH_UNARY_REAL_ONLY (Val, logb)
292 /* Compute base-2 exponential of X. */
293 #define exp2(Val) __TGMATH_UNARY_REAL_ONLY (Val, exp2)
295 /* Compute base-2 logarithm of X. */
296 #define log2(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2)
299 /* Power functions. */
301 /* Return X to the Y power. */
302 #define pow(Val1, Val2) __TGMATH_BINARY_REAL_IMAG (Val1, Val2, pow, cpow)
304 /* Return the square root of X. */
305 #define sqrt(Val) __TGMATH_UNARY_REAL_IMAG (Val, sqrt, csqrt)
307 /* Return `sqrt(X*X + Y*Y)'. */
308 #define hypot(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, hypot)
310 /* Return the cube root of X. */
311 #define cbrt(Val) __TGMATH_UNARY_REAL_ONLY (Val, cbrt)
314 /* Nearest integer, absolute value, and remainder functions. */
316 /* Smallest integral value not less than X. */
317 #define ceil(Val) __TGMATH_UNARY_REAL_ONLY (Val, ceil)
319 /* Absolute value of X. */
320 #define fabs(Val) __TGMATH_UNARY_REAL_IMAG (Val, fabs, cabs)
322 /* Largest integer not greater than X. */
323 #define floor(Val) __TGMATH_UNARY_REAL_ONLY (Val, floor)
325 /* Floating-point modulo remainder of X/Y. */
326 #define fmod(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmod)
328 /* Round X to integral valuein floating-point format using current
329 rounding direction, but do not raise inexact exception. */
330 #define nearbyint(Val) __TGMATH_UNARY_REAL_ONLY (Val, nearbyint)
332 /* Round X to nearest integral value, rounding halfway cases away from
333 zero. */
334 #define round(Val) __TGMATH_UNARY_REAL_ONLY (Val, round)
336 /* Round X to the integral value in floating-point format nearest but
337 not larger in magnitude. */
338 #define trunc(Val) __TGMATH_UNARY_REAL_ONLY (Val, trunc)
340 /* Compute remainder of X and Y and put in *QUO a value with sign of x/y
341 and magnitude congruent `mod 2^n' to the magnitude of the integral
342 quotient x/y, with n >= 3. */
343 #define remquo(Val1, Val2, Val3) \
344 __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY (Val1, Val2, Val3, remquo)
346 /* Round X to nearest integral value according to current rounding
347 direction. */
348 #define lrint(Val) __TGMATH_UNARY_REAL_ONLY (Val, lrint)
349 #define llrint(Val) __TGMATH_UNARY_REAL_ONLY (Val, llrint)
351 /* Round X to nearest integral value, rounding halfway cases away from
352 zero. */
353 #define lround(Val) __TGMATH_UNARY_REAL_ONLY (Val, lround)
354 #define llround(Val) __TGMATH_UNARY_REAL_ONLY (Val, llround)
357 /* Return X with its signed changed to Y's. */
358 #define copysign(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, copysign)
360 /* Error and gamma functions. */
361 #define erf(Val) __TGMATH_UNARY_REAL_ONLY (Val, erf)
362 #define erfc(Val) __TGMATH_UNARY_REAL_ONLY (Val, erfc)
363 #define tgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, tgamma)
364 #define lgamma(Val) __TGMATH_UNARY_REAL_ONLY (Val, lgamma)
367 /* Return the integer nearest X in the direction of the
368 prevailing rounding mode. */
369 #define rint(Val) __TGMATH_UNARY_REAL_ONLY (Val, rint)
371 /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
372 #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
373 #define nexttoward(Val1, Val2) \
374 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, nexttoward)
376 /* Return the remainder of integer divison X / Y with infinite precision. */
377 #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
379 #if defined __UCLIBC_SUSV3_LEGACY__
380 /* Return X times (2 to the Nth power). */
381 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
382 # define scalb(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, scalb)
383 #endif
385 /* Return X times (2 to the Nth power). */
386 #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
388 /* Return X times (2 to the Nth power). */
389 #define scalbln(Val1, Val2) \
390 __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbln)
391 #endif /* UCLIBC_SUSV3_LEGACY */
393 /* Return the binary exponent of X, which must be nonzero. */
394 #define ilogb(Val) __TGMATH_UNARY_REAL_ONLY (Val, ilogb)
397 /* Return positive difference between X and Y. */
398 #define fdim(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fdim)
400 /* Return maximum numeric value from X and Y. */
401 #define fmax(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmax)
403 /* Return minimum numeric value from X and Y. */
404 #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
407 /* Multiply-add function computed as a ternary operation. */
408 #define fma(Val1, Val2, Val3) \
409 __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
412 /* Absolute value, conjugates, and projection. */
414 /* Argument value of Z. */
415 #define carg(Val) __TGMATH_UNARY_IMAG_ONLY (Val, carg)
417 /* Complex conjugate of Z. */
418 #define conj(Val) __TGMATH_UNARY_IMAG_ONLY (Val, conj)
420 /* Projection of Z onto the Riemann sphere. */
421 #define cproj(Val) __TGMATH_UNARY_IMAG_ONLY (Val, cproj)
424 /* Decomposing complex values. */
426 /* Imaginary part of Z. */
427 #define cimag(Val) __TGMATH_UNARY_IMAG_ONLY (Val, cimag)
429 /* Real part of Z. */
430 #define creal(Val) __TGMATH_UNARY_IMAG_ONLY (Val, creal)
432 #endif /* tgmath.h */