1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-02 07:46:01 +00:00
oot/src/code/sys_math.c
Dragorn421 0283493db8
Lightweight trigonometry doc (#1356)
* Doc units of trig functions

* "Very simple" yet I made a mistake

* sins returns in [-0x7FFF,0x7FFF] as the [-1,1] range

* Also `sys_math_atan.c`

* Remove `@param`s without descriptions

* Add note on Math_Atan2S/F arguments being unlike atan2

* "from (1,0) to (x,y)" -> "from vector ..."

* arg names -> `angle`

* Improve `@return` comment on atans
2022-10-15 17:29:36 -04:00

55 lines
1 KiB
C

#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;
}
/**
* @param angle radians
* @return sin(angle)
*/
f32 Math_SinF(f32 angle) {
return sins((s16)(angle * (0x7FFF / M_PI))) * SHT_MINV;
}
/**
* @param angle radians
* @return cos(angle)
*/
f32 Math_CosF(f32 angle) {
return coss((s16)(angle * (0x7FFF / M_PI))) * SHT_MINV;
}