diff --git a/libnx/inc/public/nox/math.h b/libnx/inc/public/nox/math.h index 84f62a5..ee7a466 100644 --- a/libnx/inc/public/nox/math.h +++ b/libnx/inc/public/nox/math.h @@ -5,7 +5,9 @@ #include "stdtypes.h" -uint64_t min(uint64_t a, uint64_t b); -uint64_t max(uint64_t a, uint64_t b); +int64_t min(int64_t a, int64_t b); +int64_t max(int64_t a, int64_t b); +double pow(double base, int64_t exponent); +int64_t abs(int64_t n); #endif //LIBNX_MATH_H diff --git a/libnx/src/math.c b/libnx/src/math.c index c539b33..adea5ff 100644 --- a/libnx/src/math.c +++ b/libnx/src/math.c @@ -2,10 +2,31 @@ #include "public/nox/math.h" -uint64_t min (uint64_t a, uint64_t b) { +int64_t min(int64_t a, int64_t b) { return a < b ? a : b; } -uint64_t max (uint64_t a, uint64_t b) { +int64_t max(int64_t a, int64_t b) { return a > b ? a : b; } +double pow(double base, int64_t exponent) { + double result = 1; + + if (exponent >= 0) { + for (int i = 0; i < exponent; i++) { + result *= base; + } + } else { + for (int i = 0; i < abs(exponent); i++) { + result /= base; + } + } + return result; +} + +int64_t abs(int64_t n) { + if (n < 0) { + return n * -1; + } + return n; +} diff --git a/libnx/src/stdio.c b/libnx/src/stdio.c index 6846c2a..741166b 100644 --- a/libnx/src/stdio.c +++ b/libnx/src/stdio.c @@ -4,7 +4,7 @@ #include "public/nox/syscall.h" #include "public/nox/math.h" -struct file_T{ +struct file_T { uint64_t fd; uint64_t cursor; };