diff --git a/code/math/abs.c b/code/math/abs.c new file mode 100644 index 0000000..246376b --- /dev/null +++ b/code/math/abs.c @@ -0,0 +1,16 @@ + +#include + +double fabs(double x) { + if(x >= 0) { + return x; + } + return -x; +} + +float fabsf(float x) { + if(x >= 0) { + return x; + } + return -x; +} diff --git a/code/math/acos.c b/code/math/acos.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/acosh.c b/code/math/acosh.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/asin.c b/code/math/asin.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/asinh.c b/code/math/asinh.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/atan.c b/code/math/atan.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/atanh.c b/code/math/atanh.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/cbrt.c b/code/math/cbrt.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/ceil.c b/code/math/ceil.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/copysign.c b/code/math/copysign.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/cosh.c b/code/math/cosh.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/erf.c b/code/math/erf.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/erfc.c b/code/math/erfc.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/exp.c b/code/math/exp.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/fdim.c b/code/math/fdim.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/floats.c b/code/math/floats.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/floor.c b/code/math/floor.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/fma.c b/code/math/fma.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/fmax.c b/code/math/fmax.c new file mode 100644 index 0000000..ca5193a --- /dev/null +++ b/code/math/fmax.c @@ -0,0 +1,12 @@ + +double fmax(double x, double y) { + if(x>y) return x; + return y; +} + +float fmaxf(float x, float y) { + if(x>y) return x; + return y; +} + + diff --git a/code/math/fmod.c b/code/math/fmod.c new file mode 100644 index 0000000..2029d25 --- /dev/null +++ b/code/math/fmod.c @@ -0,0 +1,18 @@ + +double fmod(double x, double y) { + int n = 0; + while(y < x*n) { + ++n; + } + return y - n*x; +} + +float fmodf(float x, float y) { + int n = 0; + while(y < x*n) { + ++n; + } + return y - n*x; +} + + diff --git a/code/math/frexp.c b/code/math/frexp.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/hypot.c b/code/math/hypot.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/ilogb.c b/code/math/ilogb.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/ldexp.c b/code/math/ldexp.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/lgamma.c b/code/math/lgamma.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/llrint.c b/code/math/llrint.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/llround.c b/code/math/llround.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/log.c b/code/math/log.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/lrint.c b/code/math/lrint.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/mod.c b/code/math/mod.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/nan.c b/code/math/nan.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/nearbyint.c b/code/math/nearbyint.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/nextafter.c b/code/math/nextafter.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/pow.c b/code/math/pow.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/remainder.c b/code/math/remainder.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/remquo.c b/code/math/remquo.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/rint.c b/code/math/rint.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/scalbln.c b/code/math/scalbln.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/scalbnf.c b/code/math/scalbnf.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/sin.c b/code/math/sin.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/sinh.c b/code/math/sinh.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/sqrt.c b/code/math/sqrt.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/tan.c b/code/math/tan.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/tanh.c b/code/math/tanh.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/tgamma.c b/code/math/tgamma.c new file mode 100644 index 0000000..e69de29 diff --git a/code/math/trunc.c b/code/math/trunc.c new file mode 100644 index 0000000..e69de29 diff --git a/inc/math.h b/inc/math.h index 22ece91..244aee2 100644 --- a/inc/math.h +++ b/inc/math.h @@ -11,221 +11,192 @@ typedef double double_t; #define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF)) #define HUGE_VAL ((double)INFINITY) #define HUGE_VALF ((float)INFINITY) -#define HUGE_VALL ((long double)INFINITY) -// Positive NaN #define NAN (-(float)(INFINITY * 0.0F)) -#define FP_SUBNORMAL (-2) -#define FP_NORMAL (-1) -#define FP_ZERO 0 -#define FP_INFINITE 1 -#define FP_NAN 2 +// FP_ILOGB0 +// FP_ILOGBNAN -//FP_INFINITE -//FP_NAN -//FP_NORMAL -//FP_SUBNORMAL -//FP_ZERO -#define FP_FAST_FMA 1 -#define FP_FAST_FMAF 1 -#define FP_FAST_FMAL 1 +#define MATH_ERRNO 0 +#define MATH_ERREXCEPT 1 -#define FP_ILOGB0 (-0x7FFFFFFFu - 1u) -#define FP_ILOGBNAN 0x7FFFFFFFu +#define math_errhandling MATH_ERRNO -#define MATH_ERRNO 1 -#define MATH_ERREXCEPT 2 -#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) - -// TODO: implement this -#define fpclassify(x) 0 - -// HACK: If its fine just remove the comment -#define isfinite(x) ((double)(x) != HUGE_VAL && (double)(x) != -HUGE_VAL) -#define isinf(x) (!(isinf(x))) - -#define isnan(x) 0 -#define isnormal(x) 0 -#define signbit(x) 0 - -// TODO: implement this, search it up, they're a bit different semantics than -// the names might suggest -#define isgreater(x, y) 0 -#define isgreaterequal(x, y) 0 -#define isless(x, y) 0 -#define islessequal(x, y) 0 -#define islessgreater(x, y) 0 -#define isunordered(x, y) 0 +#define FP_INFINITE 0 +#define FP_NAN 1 +#define FP_NORMAL 2 +#define FP_SUBNORMAL 3 +#define FP_ZERO 4 +#define fpclassify(x) ( \ + _is_float(x) ? _fpclassify_f(x) : + _is_double(x) ? _fpclassify_d(x) : + FP_NAN) double acos(double x); float acosf(float x); -long double acosl(long double x); + double asin(double x); float asinf(float x); -long double asinl(long double x); + double atan(double x); float atanf(float x); -long double atanl(long double x); + double atan2(double y, double x); float atan2f(float y, float x); -long double atan2l(long double y, long double x); + double cos(double x); float cosf(float x); -long double cosl(long double x); + double sin(double x); float sinf(float x); -long double sinl(long double x); + double tan(double x); float tanf(float x); -long double tanl(long double x); + double acosh(double x); float acoshf(float x); -long double acoshl(long double x); + double asinh(double x); float asinhf(float x); -long double asinhl(long double x); + double atanh(double x); float atanhf(float x); -long double atanhl(long double x); + double cosh(double x); float coshf(float x); -long double coshl(long double x); + double sinh(double x); float sinhf(float x); -long double sinhl(long double x); + double tanh(double x); float tanhf(float x); -long double tanhl(long double x); + double exp(double x); float expf(float x); -long double expl(long double x); + double exp2(double x); float exp2f(float x); -long double exp2l(long double x); + double expm1(double x); float expm1f(float x); -long double expm1l(long double x); + double frexp(double value, int *exp); float frexpf(float value, int *exp); -long double frexpl(long double value, int *exp); + int ilogb(double x); int ilogbf(float x); -int ilogbl(long double x); + double ldexp(double x, int exp); float ldexpf(float x, int exp); -long double ldexpl(long double x, int exp); + double log(double x); float logf(float x); -long double logl(long double x); + double log10(double x); float log10f(float x); -long double log10l(long double x); + double log1p(double x); float log1pf(float x); -long double log1pl(long double x); + double log2(double x); float log2f(float x); -long double log2l(long double x); + double logb(double x); float logbf(float x); -long double logbl(long double x); + double modf(double value, double *iptr); float modff(float value, float *iptr); -long double modfl(long double value, long double *iptr); + double scalbn(double x, int n); float scalbnf(float x, int n); -long double scalbnl(long double x, int n); + double scalbln(double x, long int n); float scalblnf(float x, long int n); -long double scalblnl(long double x, long int n); + double cbrt(double x); float cbrtf(float x); -long double cbrtl(long double x); + double fabs(double x); float fabsf(float x); -long double fabsl(long double x); + double hypot(double x, double y); float hypotf(float x, float y); -long double hypotl(long double x, long double y); + double pow(double x, double y); float powf(float x, float y); -long double powl(long double x, long double y); + double sqrt(double x); float sqrtf(float x); -long double sqrtl(long double x); + double erf(double x); float erff(float x); -long double erfl(long double x); + double erfc(double x); float erfcf(float x); -long double erfcl(long double x); + double lgamma(double x); float lgammaf(float x); -long double lgammal(long double x); + double tgamma(double x); float tgammaf(float x); -long double tgammal(long double x); + double ceil(double x); float ceilf(float x); -long double ceill(long double x); + double floor(double x); float floorf(float x); -long double floorl(long double x); + double nearbyint(double x); float nearbyintf(float x); -long double nearbyintl(long double x); + double rint(double x); float rintf(float x); -long double rintl(long double x); + long int lrint(double x); long int lrintf(float x); -long int lrintl(long double x); + long long int llrint(double x); long long int llrintf(float x); -long long int llrintl(long double x); + double round(double x); float roundf(float x); -long double roundl(long double x); + long int lround(double x); long int lroundf(float x); -long int lroundl(long double x); + long long int llround(double x); long long int llroundf(float x); -long long int llroundl(long double x); + double trunc(double x); float truncf(float x); -long double truncl(long double x); + double fmod(double x, double y); float fmodf(float x, float y); -long double fmodl(long double x, long double y); + double remainder(double x, double y); float remainderf(float x, float y); -long double remainderl(long double x, long double y); + double remquo(double x, double y, int *quo); float remquof(float x, float y, int *quo); -long double remquol(long double x, long double y, int *quo); + double copysign(double x, double y); float copysignf(float x, float y); -long double copysignl(long double x, long double y); + double nan(const char *tagp); float nanf(const char *tagp); -long double nanl(const char *tagp); + double nextafter(double x, double y); float nextafterf(float x, float y); -long double nextafterl(long double x, long double y); -double nexttoward(double x, long double y); -float nexttowardf(float x, long double y); -long double nexttowardl(long double x, long double y); + double fdim(double x, double y); float fdimf(float x, float y); -long double fdiml(long double x, long double y); + double fmax(double x, double y); float fmaxf(float x, float y); -long double fmaxl(long double x, long double y); + double fmin(double x, double y); float fminf(float x, float y); -long double fminl(long double x, long double y); + double fma(double x, double y, double z); float fmaf(float x, float y, float z); -long double fmal(long double x, long double y, long double z); +