From 42b331e3b0d50b40790f660b331014f295e818f4 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Sat, 11 Feb 2023 15:59:51 +0100 Subject: [PATCH] feature (kernel): implemented function to get absolute number --- kernel/inc/utils/math.h | 1 + kernel/src/utils/math.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/kernel/inc/utils/math.h b/kernel/inc/utils/math.h index 42523da..bd506a4 100644 --- a/kernel/inc/utils/math.h +++ b/kernel/inc/utils/math.h @@ -24,5 +24,6 @@ #define FLOOR_TO(a, b) (a - (a % b)) uint64_t pow(uint64_t base, uint64_t exp); +uint64_t abs(int64_t n); #endif //NOX_MATH_H diff --git a/kernel/src/utils/math.c b/kernel/src/utils/math.c index 8af2d8b..1695705 100644 --- a/kernel/src/utils/math.c +++ b/kernel/src/utils/math.c @@ -21,4 +21,11 @@ uint64_t pow(uint64_t base, uint64_t exp) { n *= base; } return n; +} + +uint64_t abs(int64_t n) { + if (n < 0) { + return n * -1; + } + return n; } \ No newline at end of file