diff options
author | 2022-04-07 19:33:30 +0530 | |
---|---|---|
committer | 2022-04-07 19:33:30 +0530 | |
commit | 54d5ba67489b3fdaf437c05675eb9b1f6d085a84 (patch) | |
tree | d53df52fbfb1f440bba34799c2fcf7ff1ce75a57 /math | |
download | fflibc-main.tar fflibc-main.tar.gz fflibc-main.tar.bz2 fflibc-main.tar.lz fflibc-main.tar.xz fflibc-main.tar.zst fflibc-main.zip |
Initial commitmain
Diffstat (limited to 'math')
-rw-r--r-- | math/abs.c | 3 | ||||
-rw-r--r-- | math/div.c | 7 | ||||
-rw-r--r-- | math/fabs.c | 3 | ||||
-rw-r--r-- | math/fabsf.c | 3 | ||||
-rw-r--r-- | math/fabsl.c | 3 | ||||
-rw-r--r-- | math/imaxabs.c | 3 | ||||
-rw-r--r-- | math/imaxdiv.c | 7 | ||||
-rw-r--r-- | math/labs.c | 3 | ||||
-rw-r--r-- | math/ldiv.c | 7 | ||||
-rw-r--r-- | math/llabs.c | 3 | ||||
-rw-r--r-- | math/lldiv.c | 7 | ||||
-rw-r--r-- | math/maths.h | 41 | ||||
-rw-r--r-- | math/meson.build | 13 | ||||
-rw-r--r-- | math/wrap/meson.build | 2 |
14 files changed, 105 insertions, 0 deletions
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 <stdint.h> + +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 <inttypes.h> + #include <stdlib.h> + #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( +) |