feature (libnx): implemented basic math utils

This commit is contained in:
antifallobst 2023-06-07 10:14:55 +02:00
parent b8c7dd8a4d
commit 21290535d4
3 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
};