75f8aa6fd131281b6a0d58b42d8d1bd8a1ac1176
[libm] / include / tgmath.h
1 #ifndef _TGMATH_H
2 #define _TGMATH_H
3
4 // C11 only
5 // See C11 6.5.1.1 for generic selections
6 // See C11 7.25 for tgmath.h
7
8 #include <math.h>
9 #include <complex.h>
10
11 #define __tg_real(__fun, x) _Generic(x, \
12         float: __fun ## f, \
13         long double: __fun ## l, \
14         default: __fun)
15 #define __tg_real_2(__fun, x, y) _Generic(x, \
16         float: __tg_real(__fun, y), \
17         long double: __fun ## l, \
18         default: _Generic(y, \
19                 long double: __fun ## l, \
20                 default: __fun))
21 #define __tg_real_3(__fun, x, y, z) _Generic(x, \
22         float: __tg_real_2(__fun, y, z), \
23         long double: __fun ## l, \
24         default: _Generic(y, \
25                 long double: __fun ## l, \
26                 default: _Generic(z, \
27                         long double: __fun ## l, \
28                         default: __fun)))
29 // FIXME: imaginary type
30 #define __tg_complex(__fun, x) _Generic(x, \
31         float: __fun ## f, \
32         long double: __fun ## l, \
33         float complex: __fun ## f, \
34         long double complex: __fun ## l, \
35         default: __fun)
36 #define __tg_real_complex(__fun, x) _Generic(x, \
37         float: __fun ## f, \
38         long double: __fun ## l, \
39         float complex: c ## __fun ## f, \
40         double complex: c ## __fun, \
41         long double complex: c ## __fun ## l, \
42         default: __fun)
43 #define __tg_real_complex_fabs(x) _Generic(x, \
44         float: fabsf, \
45         long double: fabsl, \
46         float complex: cabsf, \
47         double complex: cabs, \
48         long double complex: cabsl, \
49         default: fabs)
50
51 #define acos(x)         __tg_real_complex(acos, (x))(x)
52 #define acosh(x)        __tg_real_complex(acosh, (x))(x)
53 #define asin(x)         __tg_real_complex(asin, (x))(x)
54 #define asinh(x)        __tg_real_complex(asinh, (x))(x)
55 #define atan(x)         __tg_real_complex(atan, (x))(x)
56 #define atan2(x)        __tg_real_2(atan2, (x), (y))((x), (y))
57 #define atanh(x)        __tg_real_complex(atanh, (x))(x)
58 #define carg(x)         __tg_complex(carg, (x))(x)
59 #define cbrt(x)         __tg_real(cbrt, (x))(x)
60 #define ceil(x)         __tg_real(ceil, (x))(x)
61 #define cimag(x)        __tg_complex(cimag, (x))(x)
62 #define conj(x)         __tg_complex(conj, (x))(x)
63 #define copysign(x,y)   __tg_real_2(copysign, (x), (y))((x), (y))
64 #define cos(x)          __tg_real_complex(cos, (x))(x)
65 #define cosh(x)         __tg_real_complex(cosh, (x))(x)
66 #define cproj(x)        __tg_complex(cproj, (x))(x)
67 #define creal(x)        __tg_complex(creal, (x))(x)
68 #define erf(x)          __tg_real(erf, (x))(x)
69 #define erfc(x)         __tg_real(erfc, (x))(x)
70 #define exp(x)          __tg_real_complex(exp, (x))(x)
71 #define exp2(x)         __tg_real(exp2, (x))(x)
72 #define expm1(x)        __tg_real(expm1, (x))(x)
73 #define fabs(x)         __tg_real_complex_fabs(x)(x)
74 #define fdim(x)         __tg_real(fdim, (x))(x)
75 #define floor(x)        __tg_real(floor, (x))(x)
76 #define fma(x,y,z)      __tg_real_3(fma, (x), (y), (z))((x), (y), (z))
77 #define fmax(x,y)       __tg_real_2(fmax, (x), (y))((x), (y))
78 #define fmin(x,y)       __tg_real_2(fmin, (x), (y))((x), (y))
79 #define fmod(x,y)       __tg_real_2(fmod, (x), (y))((x), (y))
80 #define frexp(x,y)      __tg_real(frexp, (x))((x), (y))
81 #define hypot(x,y)      __tg_real_2(hypot, (x), (y))((x), (y))
82 #define ilogb(x)        __tg_real(ilogb, (x))(x)
83 #define ldexp(x,y)      __tg_real(ldexp, (x))((x), (y))
84 #define lgamma(x)       __tg_real(lgamma, (x))(x)
85 #define llrint(x)       __tg_real(llrint, (x))(x)
86 #define llround(x)      __tg_real(llround, (x))(x)
87 #define log(x)          __tg_real_complex(log, (x))(x)
88 #define log10(x)        __tg_real(log10, (x))(x)
89 #define log1p(x)        __tg_real(log1p, (x))(x)
90 #define log2(x)         __tg_real(log2, (x))(x)
91 #define logb(x)         __tg_real(logb, (x))(x)
92 #define lrint(x)        __tg_real(lrint, (x))(x)
93 #define lround(x)       __tg_real(lround, (x))(x)
94 #define nearbyint(x)    __tg_real(nearbyint, (x))(x)
95 #define nextafter(x,y)  __tg_real_2(nextafter, (x), (y)((x), (y))
96 #define nexttoward(x,y) __tg_real_2(nexttoward, (x), (y))((x), (y))
97 #define pow(x)          __tg_real_complex(pow, (x))(x)
98 #define remainder(x,y)  __tg_real_2(remainder, (x), (y))((x), (y))
99 #define remquo(x,y,z)   __tg_real_2(remquo, (x), (y))((x), (y), (z))
100 #define rint(x)         __tg_real(rint, (x))(x)
101 #define round(x)        __tg_real(round, (x))(x)
102 #define scalbln(x,y)    __tg_real(scalbln, (x))((x), (y))
103 #define scalbn(x, y)    __tg_real(scalbn, (x))((x), (y))
104 #define sin(x)          __tg_real_complex(sin, (x))(x)
105 #define sinh(x)         __tg_real_complex(sinh, (x))(x)
106 #define sqrt(x)         __tg_real_complex(sqrt, (x))(x)
107 #define tan(x)          __tg_real_complex(tan, (x))(x)
108 #define tanh(x)         __tg_real_complex(tanh, (x))(x)
109 #define tgamma(x)       __tg_real(tgamma, (x))(x)
110 #define trunc(x)        __tg_real(trunc, (x))(x)
111
112 #endif