From cba703f94f5755cff7ed171718e18aa9caeb08b8 Mon Sep 17 00:00:00 2001 From: dosisod <39638017+dosisod@users.noreply.github.com> Date: Sat, 6 Mar 2021 21:41:25 -0800 Subject: [PATCH] Implement tgmath.h Format with clang-format --- libc/isystem/tgmath.h | 2 +- libc/tgmath.h | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 libc/tgmath.h diff --git a/libc/isystem/tgmath.h b/libc/isystem/tgmath.h index 59a7eaabf..e769b08b5 100644 --- a/libc/isystem/tgmath.h +++ b/libc/isystem/tgmath.h @@ -1,4 +1,4 @@ #ifndef LIBC_ISYSTEM_TGMATH_H_ #define LIBC_ISYSTEM_TGMATH_H_ -#include "libc/math/tgmath.h" +#include "libc/tgmath.h" #endif diff --git a/libc/tgmath.h b/libc/tgmath.h new file mode 100644 index 000000000..2219ec741 --- /dev/null +++ b/libc/tgmath.h @@ -0,0 +1,60 @@ +#ifndef COSMOPOLITAN_LIBC_TGMATH_H_ +#define COSMOPOLITAN_LIBC_TGMATH_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) _Generic((x), float : powf, default : pow, long double : powl)(x) + +#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 /* COSMOPOLITAN_LIBC_TGMATH_H_ */