From 67b9675c815fccbee7017a54629d15be3876eecd Mon Sep 17 00:00:00 2001 From: dosisod <39638017+dosisod@users.noreply.github.com> Date: Sat, 6 Mar 2021 22:40:18 -0800 Subject: [PATCH] Make tgmath.h available (#109) --- libc/isystem/tgmath.h | 61 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/libc/isystem/tgmath.h b/libc/isystem/tgmath.h index 59a7eaabf..2f9efe946 100644 --- a/libc/isystem/tgmath.h +++ b/libc/isystem/tgmath.h @@ -1,4 +1,63 @@ #ifndef LIBC_ISYSTEM_TGMATH_H_ #define LIBC_ISYSTEM_TGMATH_H_ -#include "libc/math/tgmath.h" + +#include "libc/math.h" + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +#if __STDC_VERSION__ + 0 >= 201112 +COSMOPOLITAN_C_START_ + +/* from https://en.cppreference.com/w/c/numeric/tgmath */ + +#define fabs(x) \ + _Generic((x), float : fabsf, default : fabs, long double : fabsl)(x) + +#define exp(x) _Generic((x), float : expf, default : exp, long double : expl)(x) + +#define log(x) _Generic((x), float : logf, default : log, long double : logl)(x) + +#define pow(x, y) \ + _Generic((x), float : powf, default : pow, long double : powl)(x, y) + +#define sqrt(x) \ + _Generic((x), float : sqrtf, default : sqrt, long double : sqrtl)(x) + +#define sin(x) _Generic((x), float : sinf, default : sin, long double : sinl)(x) + +#define cos(x) _Generic((x), float : cosf, default : cos, long double : cosl)(x) + +#define tan(x) _Generic((x), float : tanf, default : tan, long double : tanl)(x) + +#define asin(x) \ + _Generic((x), float : asinf, default : asin, long double : asinl)(x) + +#define acos(x) \ + _Generic((x), float : acosf, default : acos, long double : acosl)(x) + +#define atan(x) \ + _Generic((x), float : atanf, default : atan, long double : atanl)(x) + +#define sinh(x) \ + _Generic((x), float : sinhf, default : sinh, long double : sinhl)(x) + +#define cosh(x) \ + _Generic((x), float : coshf, default : cosh, long double : coshl)(x) + +#define tanh(x) \ + _Generic((x), float : tanhf, default : tanh, long double : tanhl)(x) + +#define asinh(x) \ + _Generic((x), float : asinhf, default : asinh, long double : asinhl)(x) + +#define acosh(x) \ + _Generic((x), float : acoshf, default : acosh, long double : acoshl)(x) + +#define atanh(x) \ + _Generic((x), float : atanhf, default : atanh, long double : atanhl)(x) + +COSMOPOLITAN_C_END_ + +#endif /* C11 */ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ + #endif