From b025e301bbba4b57375d22c2370c1514e0ae417b Mon Sep 17 00:00:00 2001 From: able Date: Tue, 9 Jan 2024 12:12:33 -0600 Subject: [PATCH] more math --- src/ableos_std/ableos_std.c | 4 ++-- src/ableos_std/math.h | 13 ------------- src/ableos_std/math/divide_up.h | 28 ++++++++++++++++++++++++++++ src/ableos_std/math/half.h | 15 +++++++++++++++ src/ableos_std/math/math.h | 5 +++++ src/ableos_std/math/square.h | 15 +++++++++++++++ src/main.c | 3 ++- 7 files changed, 67 insertions(+), 16 deletions(-) delete mode 100644 src/ableos_std/math.h create mode 100644 src/ableos_std/math/divide_up.h create mode 100644 src/ableos_std/math/half.h create mode 100644 src/ableos_std/math/math.h create mode 100644 src/ableos_std/math/square.h diff --git a/src/ableos_std/ableos_std.c b/src/ableos_std/ableos_std.c index dd30e28..57a04f8 100644 --- a/src/ableos_std/ableos_std.c +++ b/src/ableos_std/ableos_std.c @@ -8,17 +8,17 @@ #include "types/sys_id.h" #include "types/services.h" +#include "math/math.h" + #include "ecalls.c" #include "services/log_service.c" #include "services/csprng_service.c" #include "services/memory_service.c" - #include "random/random.c" #include "arguments.c" #include "process.c" #include "exit.h" - #include "collections/vec.c" \ No newline at end of file diff --git a/src/ableos_std/math.h b/src/ableos_std/math.h deleted file mode 100644 index 6a2cd21..0000000 --- a/src/ableos_std/math.h +++ /dev/null @@ -1,13 +0,0 @@ -/*Sadly sometimes dividing people in half is a bad thing actually*/ -int divide_up(int n, int d) { - if (n % d == 0) { - return n / d; - } - return 1 + n / d; -} - -int square(int a){ - return a * a; -} int half(int a){ - return a / 2; -} \ No newline at end of file diff --git a/src/ableos_std/math/divide_up.h b/src/ableos_std/math/divide_up.h new file mode 100644 index 0000000..92f0e06 --- /dev/null +++ b/src/ableos_std/math/divide_up.h @@ -0,0 +1,28 @@ +/*Sadly sometimes dividing people in half is a bad thing actually*/ +u8 divide_up_u8(u8 n, u8 d) { + if (n % d == 0) { + return n / d; + } + return 1 + n / d; +} + +u16 divide_up_u16(u16 n, u16 d) { + if (n % d == 0) { + return n / d; + } + return 1 + n / d; +} + +u32 divide_up_u32(u32 n, u32 d) { + if (n % d == 0) { + return n / d; + } + return 1 + n / d; +} + +u64 divide_up_u64(u64 n, u64 d) { + if (n % d == 0) { + return n / d; + } + return 1 + n / d; +} \ No newline at end of file diff --git a/src/ableos_std/math/half.h b/src/ableos_std/math/half.h new file mode 100644 index 0000000..a4340b9 --- /dev/null +++ b/src/ableos_std/math/half.h @@ -0,0 +1,15 @@ +u8 half_u8(u8 a){ + return a / 2; +} + +u16 half_u16(u16 a){ + return a / 2; +} + +u32 half_u32(u32 a){ + return a / 2; +} + +u64 half_u64(u64 a){ + return a / 2; +} \ No newline at end of file diff --git a/src/ableos_std/math/math.h b/src/ableos_std/math/math.h new file mode 100644 index 0000000..a8e6a52 --- /dev/null +++ b/src/ableos_std/math/math.h @@ -0,0 +1,5 @@ +// Math library with various operations on types implemented + +#include "square.h" +#include "half.h" +#include "divide_up.h" diff --git a/src/ableos_std/math/square.h b/src/ableos_std/math/square.h new file mode 100644 index 0000000..3d4bb62 --- /dev/null +++ b/src/ableos_std/math/square.h @@ -0,0 +1,15 @@ +u8 square_u8(u8 a){ + return a * a; +} + +u16 square_u16(u16 a){ + return a * a; +} + +u32 square_u32(u32 a){ + return a * a; +} + +u64 square_u64(u64 a){ + return a * a; +} diff --git a/src/main.c b/src/main.c index f5e5759..3c2f8a8 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,8 @@ int main() { register_exit_code(ecode_new("File System Error")); - return 1; + + return 0; } #include "ableos_std/start.c"