feature (libnx): implemented basic math utils
This commit is contained in:
parent
b8c7dd8a4d
commit
21290535d4
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue