some tgmath.h macros

This commit is contained in:
bumbread 2022-06-27 14:38:44 +11:00
parent ff34259408
commit 441320f888
2 changed files with 51 additions and 30 deletions

View File

@ -1,40 +1,63 @@
#pragma once #pragma once
/* #include <math.h>
these are type generic so they're macrod and use C11's _Generic
acos #define _tg_is_ld(x) (sizeof(x) == sizeof(long double))
asin #define _tg_is_d (x) (sizeof(x) == sizeof(double))
atan
acosh #define _tg_is_ld2(x,y) (_tg_is_ld(x) || _tg_is_ld(y))
asinh #define _tg_is_d2 (x,y) (_tg_is_d (x) || _tg_is_d (y))
atanh
cos #define _tg_func1(func, x) ( _tg_is_ld(x) ? (func ## l)(x) \
sin : _tg_is_d(x) ? (func)(x) \
tan : (func ## f)(x) )
cosh
sinh #define _tf_func2(func, x, t) ( _tg_is_ld2(x,y) ? (func ## l)(x,y) \
tanh : _tg_is_d2(x,y) ? (func)(x,y) \
exp : (func ## f)(x,y) )
log
pow #define cos (x) _tg_func1(cos, x)
sqrt #define sin (x) _tg_func1(sin, x)
fabs #define tan (x) _tg_func1(tan, x)
atan2 #define acos (x) _tg_func1(acos, x)
cbrt #define asin (x) _tg_func1(asin, x)
ceil #define atan (x) _tg_func1(atan, x)
copysign #define atan2 (x,y) _tg_func2(atan2, x, y)
#define cosh (x) _tg_func1(cosh, x)
#define sinh (x) _tg_func1(sinh, x)
#define tanh (x) _tg_func1(tanh, x)
#define acosh (x) _tg_func1(acosh, x)
#define asinh (x) _tg_func1(asinh, x)
#define atanh (x) _tg_func1(atanh, x)
#define exp (x) _tg_func1(exp, x)
#define exp2 (x) _tg_func1(exp2, x)
#define pow (x,y) _tg_func2(pow, x, y)
#define log (x,y) _tg_func2(log, x, y)
#define sqrt (x) _tg_func1(sqrt, x)
#define cbrt (x) _tg_func1(cbrt, x)
#define fabs (x) _tg_func1(fabs, x)
#define ceil (x) _tg_func1(ceil, x)
#define floor (x) _tg_func1(floor, x)
#define round (x) _tg_func1(round, x)
#define trunc (x) _tg_func1(trunc, x)
#define copysign(x,y) _tg_func2(copysign, x, y)
#define fmax (x,y) _tg_func2(fmax, x, y)
#define fmin (x,y) _tg_func2(fmin, x, y)
#define fmod (x,y) _tg_func2(fmod, x, y)
/*
erf erf
erfc erfc
exp2 exp2
expm1 expm1
fdim fdim
floor
fma fma
fmax
fmin
fmod
frexp frexp
hypot hypot
ilogb ilogb
@ -54,11 +77,9 @@ nexttoward
remainder remainder
remquo remquo
rint rint
round
scalbn scalbn
scalbln scalbln
tgamma tgamma
trunc
carg carg
cimag cimag
conj conj