2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
2020-04-19 03:28:24 +00:00
|
|
|
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 };
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_FactorialF(f32 n) {
|
2020-04-19 03:28:24 +00:00
|
|
|
f32 ret = 1.0f;
|
|
|
|
s32 i;
|
2020-12-26 10:44:53 +00:00
|
|
|
|
|
|
|
for (i = n; i > 1; i--) {
|
2020-04-19 03:28:24 +00:00
|
|
|
ret *= i;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_Factorial(s32 n) {
|
2020-04-19 03:28:24 +00:00
|
|
|
f32 ret;
|
|
|
|
s32 i;
|
2020-12-26 10:44:53 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
if ((u32)n > 12U) {
|
2020-04-19 03:28:24 +00:00
|
|
|
ret = sFactorialTbl[12];
|
2020-12-26 10:44:53 +00:00
|
|
|
for (i = 13; i <= n; i++) {
|
2020-04-19 03:28:24 +00:00
|
|
|
ret *= i;
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-26 10:44:53 +00:00
|
|
|
ret = sFactorialTbl[n];
|
2020-04-19 03:28:24 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_PowF(f32 base, s32 exp) {
|
2020-04-19 03:28:24 +00:00
|
|
|
f32 ret = 1.0f;
|
2020-12-26 10:44:53 +00:00
|
|
|
|
|
|
|
while (exp > 0) {
|
|
|
|
exp--;
|
|
|
|
ret *= base;
|
2020-04-19 03:28:24 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_SinF(f32 angle) {
|
2022-04-03 18:32:18 +00:00
|
|
|
return sins((s16)(angle * (0x7FFF / M_PI))) * SHT_MINV;
|
2020-04-19 03:28:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 10:44:53 +00:00
|
|
|
f32 Math_CosF(f32 angle) {
|
2022-04-03 18:32:18 +00:00
|
|
|
return coss((s16)(angle * (0x7FFF / M_PI))) * SHT_MINV;
|
2020-04-19 03:28:24 +00:00
|
|
|
}
|