diff options
| author | M4xw <m4x@m4xw.net> | 2022-03-22 02:51:23 +0100 |
|---|---|---|
| committer | M4xw <m4x@m4xw.net> | 2022-03-22 02:51:23 +0100 |
| commit | 39cc86c2608e2f75ace33fc7f43bc4f2ad743f1a (patch) | |
| tree | 0d3fd9e995d7484eaaeb158ac808bd6a39121189 /soh/src/code/sys_math.c | |
| parent | 0bb0e7b53bd80bdc7f78e08c441691737e039b2b (diff) | |
git subrepo clone https://github.com/HarbourMasters/soh.git
subrepo:
subdir: "soh"
merged: "ba904bbd0"
upstream:
origin: "https://github.com/HarbourMasters/soh.git"
branch: "master"
commit: "ba904bbd0"
git-subrepo:
version: "0.4.1"
origin: "???"
commit: "???"
Diffstat (limited to 'soh/src/code/sys_math.c')
| -rw-r--r-- | soh/src/code/sys_math.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/soh/src/code/sys_math.c b/soh/src/code/sys_math.c new file mode 100644 index 000000000..9e65cdaa3 --- /dev/null +++ b/soh/src/code/sys_math.c @@ -0,0 +1,47 @@ +#include "global.h" + +f32 sFactorialTbl[] = { 1.0f, 1.0f, 2.0f, 6.0f, 24.0f, 120.0f, 720.0f, + 5040.0f, 40320.0f, 362880.0f, 3628800.0f, 39916800.0f, 479001600.0f }; + +f32 Math_FactorialF(f32 n) { + f32 ret = 1.0f; + s32 i; + + for (i = n; i > 1; i--) { + ret *= i; + } + return ret; +} + +f32 Math_Factorial(s32 n) { + f32 ret; + s32 i; + + if ((u32)n > 12U) { + ret = sFactorialTbl[12]; + for (i = 13; i <= n; i++) { + ret *= i; + } + } else { + ret = sFactorialTbl[n]; + } + return ret; +} + +f32 Math_PowF(f32 base, s32 exp) { + f32 ret = 1.0f; + + while (exp > 0) { + exp--; + ret *= base; + } + return ret; +} + +f32 Math_SinF(f32 angle) { + return sins((s16)(angle * (32767.0f / M_PI))) * SHT_MINV; +} + +f32 Math_CosF(f32 angle) { + return coss((s16)(angle * (32767.0f / M_PI))) * SHT_MINV; +} |
