blob: 4d4de5461916639b0623ba8c5dbc765b3b1bbcf8 [file] [log] [blame]
Chris Lattnerb1f3fe52009-02-07 00:47:29 +00001/*===---- tgmath.h - Standard header for type generic math ----------------===*\
2 *
3 * Copyright (c) 2009 Chris Lattner
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 *
23\*===----------------------------------------------------------------------===*/
24
25#ifndef __TGMATH_H
26#define __TGMATH_H
27
28/* C99 7.22 Type-generic math <tgmath.h>. */
29#include <math.h>
30
31/* C++ handles type genericity with overloading in math.h. */
32#ifndef __cplusplus
33#include <complex.h>
34
35/* C99 7.22p4, functions in both math.h and complex.h. */
36#define acos(x) \
37 __builtin_overload(1, x, cacosl, cacos, cacosf, acosl, acos, acosf)
38#define asin(x) \
39 __builtin_overload(1, x, casinl, casin, casinf, asinl, asin, asinf)
40#define atan(x) \
41 __builtin_overload(1, x, catanl, catan, catanf, atanl, atan, atanf)
42#define acosh(x) \
43 __builtin_overload(1, x, cacoshl, cacosh, cacoshf, acoshl, acosh, acoshf)
44#define asinh(x) \
45 __builtin_overload(1, x, casinhl, casinh, casinhf, asinhl, asinh, asinhf)
46#define atanh(x) \
47 __builtin_overload(1, x, catanhl, catanh, catanhf, atanhl, atanh, atanhf)
48#define cos(x) \
49 __builtin_overload(1, x, ccosl, ccos, ccosf, cosl, cos, cosf)
50#define sin(x) \
51 __builtin_overload(1, x, csinl, csin, csinf, sinl, sin, sinf)
52#define tan(x) \
53 __builtin_overload(1, x, ctanl, ctan, ctanf, tanl, tan, tanf)
54#define cosh(x) \
55 __builtin_overload(1, x, ccoshl, ccosh, ccoshf, coshl, cosh, coshf)
56#define sinh(x) \
57 __builtin_overload(1, x, csinhl, csinh, csinhf, sinhl, sinh, sinhf)
58#define tanh(x) \
59 __builtin_overload(1, x, ctanhl, ctanh, ctanhf, tanhl, tanh, tanhf)
60#define exp(x) \
61 __builtin_overload(1, x, cexpl, cexp, cexpf, expl, exp, expf)
62#define log(x) \
63 __builtin_overload(1, x, clogl, clog, clogf, logl, log, logf)
64#define sqrt(x) \
65 __builtin_overload(1, x, csqrtl, csqrt, csqrtf, sqrtl, sqrt, sqrtf)
66#define fabs(x) \
67 __builtin_overload(1, x, cabsl, cabs, cabsf, fabsl, fabs, fabsf)
68// FIXME: POW -> binary operation.
69
70/* C99 7.22p5, functions in just math.h that have no complex counterpart. */
71
72// FIXME: atan2 -> binary operation.
73#define cbrt(x) __builtin_overload(1, x, cbrtl, cbrt, cbrtf)
74#define ceil(x) __builtin_overload(1, x, ceil, ceil, ceilf)
75// FIXME: copysign -> binary operation.
76#define erf(x) __builtin_overload(1, x, erfl, erf, erff)
77#define erfc(x) __builtin_overload(1, x, erfcl, erfc, erfcf)
78#define exp2(x) __builtin_overload(1, x, expl, exp2, exp2f)
79#define expm1(x) __builtin_overload(1, x, expm1l, expm1, expm1f)
80// FIXME: fdim -> binary operation.
81#define floor(x) __builtin_overload(1, x, floorl, floor, floorf)
82// FIXME: fma -> trinary operation.
83// FIXME: fmax -> binary operation.
84// FIXME: fmin -> binary operation.
85// FIXME: fmax -> binary operation.
86// FIXME: fmod -> binary operation.
87// FIXME: frexp -> unary + pointer operation.
88// FIXME: hypot -> binary operation.
89#define ilogb(x) __builtin_overload(1, x, ilogbl, ilogb, ilogbf)
90// FIXME: ldexp -> fp+int.
91#define lgamma(x) __builtin_overload(1, x, lgammal, lgamma, lgammaf)
92#define llrint(x) __builtin_overload(1, x, llrintl, llrint, llrintf)
93#define llround(x) __builtin_overload(1, x, llroundl, llround, llroundf)
94#define log10(x) __builtin_overload(1, x, log10l, log10, log10f)
95#define log1p(x) __builtin_overload(1, x, log1pl, log1p, log1pf)
96#define log2(x) __builtin_overload(1, x, log2l, log2, log2f)
97#define logb(x) __builtin_overload(1, x, logbl, logb, logbf)
98#define lrint(x) __builtin_overload(1, x, lrintl, lrint, lrintf)
99#define lround(x) __builtin_overload(1, x, lroundl, lround, lroundf)
100#define nearbyint(x)__builtin_overload(1, x, nearbyintl, nearbyint, nearbyintf)
101// FIXME: nextafter -> binary operation.
102// FIXME: nexttoward -> binary operation?
103// FIXME: remainder -> binary operation.
104// FIXME: remquo -> fp+fp+ptr
105#define rint(x) __builtin_overload(1, x, rintl, rint, rintf)
106#define round(x) __builtin_overload(1, x, roundl, round, roundf)
107// FIXME: scalbn -> fp+int
108// FIXME: scalbln -> fp+int
109#define tgamma(x) __builtin_overload(1, x, tgammal, tgamma, tgammaf)
110#define trunc(x) __builtin_overload(1, x, truncl, trunc, truncf)
111
112
113// FIXME: carg, cimag, conj, cproj, creal
114
115#endif /* __cplusplus */
116#endif /* __TGMATH_H */