From 54d5ba67489b3fdaf437c05675eb9b1f6d085a84 Mon Sep 17 00:00:00 2001 From: Marc Pervaz Boocha Date: Thu, 7 Apr 2022 19:33:30 +0530 Subject: Initial commit --- math/abs.c | 3 +++ math/div.c | 7 +++++++ math/fabs.c | 3 +++ math/fabsf.c | 3 +++ math/fabsl.c | 3 +++ math/imaxabs.c | 3 +++ math/imaxdiv.c | 7 +++++++ math/labs.c | 3 +++ math/ldiv.c | 7 +++++++ math/llabs.c | 3 +++ math/lldiv.c | 7 +++++++ math/maths.h | 41 +++++++++++++++++++++++++++++++++++++++++ math/meson.build | 13 +++++++++++++ math/wrap/meson.build | 2 ++ 14 files changed, 105 insertions(+) create mode 100644 math/abs.c create mode 100644 math/div.c create mode 100644 math/fabs.c create mode 100644 math/fabsf.c create mode 100644 math/fabsl.c create mode 100644 math/imaxabs.c create mode 100644 math/imaxdiv.c create mode 100644 math/labs.c create mode 100644 math/ldiv.c create mode 100644 math/llabs.c create mode 100644 math/lldiv.c create mode 100644 math/maths.h create mode 100644 math/meson.build create mode 100644 math/wrap/meson.build (limited to 'math') diff --git a/math/abs.c b/math/abs.c new file mode 100644 index 0000000..1bb7355 --- /dev/null +++ b/math/abs.c @@ -0,0 +1,3 @@ +#include "maths.h" + +extern int abs(int n) { return n < 0 ? -n : n; } diff --git a/math/div.c b/math/div.c new file mode 100644 index 0000000..a97a19d --- /dev/null +++ b/math/div.c @@ -0,0 +1,7 @@ +#include "maths.h" + +div_t div(int numerator, int denominator) +{ + return (div_t){.quot = numerator / denominator, + .rem = numerator % denominator}; +} diff --git a/math/fabs.c b/math/fabs.c new file mode 100644 index 0000000..8a4adf3 --- /dev/null +++ b/math/fabs.c @@ -0,0 +1,3 @@ +#include "maths.h" + +double fabs(double n) { return n < 0 ? -n : n; } diff --git a/math/fabsf.c b/math/fabsf.c new file mode 100644 index 0000000..c783069 --- /dev/null +++ b/math/fabsf.c @@ -0,0 +1,3 @@ +#include "maths.h" + +float fabsf(float n) { return n < 0 ? -n : n; } diff --git a/math/fabsl.c b/math/fabsl.c new file mode 100644 index 0000000..5390e69 --- /dev/null +++ b/math/fabsl.c @@ -0,0 +1,3 @@ +#include "maths.h" + +long double fabsl(long double n) { return n < 0 ? -n : n; } diff --git a/math/imaxabs.c b/math/imaxabs.c new file mode 100644 index 0000000..3f6c630 --- /dev/null +++ b/math/imaxabs.c @@ -0,0 +1,3 @@ +#include "maths.h" + +extern intmax_t imaxabs(intmax_t n) { return n < 0 ? -n : n; } diff --git a/math/imaxdiv.c b/math/imaxdiv.c new file mode 100644 index 0000000..52b5d39 --- /dev/null +++ b/math/imaxdiv.c @@ -0,0 +1,7 @@ +#include "maths.h" + +imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator) +{ + return (imaxdiv_t){.quot = numerator / denominator, + .rem = numerator % denominator}; +} diff --git a/math/labs.c b/math/labs.c new file mode 100644 index 0000000..cf2cae8 --- /dev/null +++ b/math/labs.c @@ -0,0 +1,3 @@ +#include "maths.h" + +extern long labs(long n) { return n < 0 ? -n : n; } diff --git a/math/ldiv.c b/math/ldiv.c new file mode 100644 index 0000000..c45a6e6 --- /dev/null +++ b/math/ldiv.c @@ -0,0 +1,7 @@ +#include "maths.h" + +ldiv_t ldiv(long numerator, long denominator) +{ + return (ldiv_t){.quot = numerator / denominator, + .rem = numerator % denominator}; +} diff --git a/math/llabs.c b/math/llabs.c new file mode 100644 index 0000000..0a8bd2f --- /dev/null +++ b/math/llabs.c @@ -0,0 +1,3 @@ +#include "maths.h" + +extern long long llabs(long long n) { return n < 0 ? -n : n; } diff --git a/math/lldiv.c b/math/lldiv.c new file mode 100644 index 0000000..3a9008c --- /dev/null +++ b/math/lldiv.c @@ -0,0 +1,7 @@ +#include "maths.h" + +lldiv_t lldiv(long long numerator, long long denominator) +{ + return (lldiv_t){.quot = numerator / denominator, + .rem = numerator % denominator}; +} diff --git a/math/maths.h b/math/maths.h new file mode 100644 index 0000000..c330d0c --- /dev/null +++ b/math/maths.h @@ -0,0 +1,41 @@ +#if !defined(MATH_H) + #define MATH_H + + #include + +extern int abs(int n); +extern long labs(long n); +extern long long llabs(long long n); +extern intmax_t imaxabs(intmax_t n); +extern float fabsf(float n); +extern double fabs(double n); +extern long double fabsl(long double n); + + #if __STDC_HOSTED__ == 1 + #include + #include + #else + +typedef struct { + int quot, rem; +} div_t; + +typedef struct { + long quot, rem; +} ldiv_t; + +typedef struct { + long long quot, rem; +} lldiv_t; + +typedef struct { + intmax_t quot, rem; +} imaxdiv_t; + #endif + +extern div_t div(int numerator, int denominator); +extern ldiv_t ldiv(long numerator, long denominator); +extern lldiv_t lldiv(long long numerator, long long denominator); +extern imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator); + +#endif diff --git a/math/meson.build b/math/meson.build new file mode 100644 index 0000000..a1f9227 --- /dev/null +++ b/math/meson.build @@ -0,0 +1,13 @@ +sources += files( +'abs.c', +'div.c', +'fabs.c', +'fabsf.c', +'fabsl.c', +'imaxabs.c', +'labs.c', +'ldiv.c', +'imaxdiv.c', +'llabs.c', +'lldiv.c' +) diff --git a/math/wrap/meson.build b/math/wrap/meson.build new file mode 100644 index 0000000..fcf4a29 --- /dev/null +++ b/math/wrap/meson.build @@ -0,0 +1,2 @@ +sources += files( +) -- cgit v1.2.3-70-g09d2