diff options
| author | Dragorn421 <Dragorn421@users.noreply.github.com> | 2022-10-15 23:29:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-15 17:29:36 -0400 |
| commit | 0283493db8e968be67d9e591ec4719fe9d0477f0 (patch) | |
| tree | 90dbdd87c1942b16522b4c336a3966afd66fb8d9 /src/code/code_800FCE80.c | |
| parent | 0b38f6e6785e52685a80463df3c7c85db878e8ea (diff) | |
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
Diffstat (limited to 'src/code/code_800FCE80.c')
| -rw-r--r-- | src/code/code_800FCE80.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/code/code_800FCE80.c b/src/code/code_800FCE80.c index 500e2c01d..3d73123da 100644 --- a/src/code/code_800FCE80.c +++ b/src/code/code_800FCE80.c @@ -3,9 +3,13 @@ s32 gUseAtanContFrac; -f32 Math_FTanF(f32 x) { - f32 sin = sinf(x); - f32 cos = cosf(x); +/** + * @param angle radians + * @return tan(angle) + */ +f32 Math_FTanF(f32 angle) { + f32 sin = sinf(angle); + f32 cos = cosf(angle); return sin / cos; } @@ -42,7 +46,7 @@ f32 Math_FAtanTaylorQF(f32 x) { const f32* c = coeffs; f32 term; - while (1) { + while (true) { term = *c++ * exp; if (poly + term == poly) { break; @@ -124,6 +128,9 @@ f32 Math_FAtanContFracF(f32 x) { } } +/** + * @return arctan(x) in radians, in (-pi/2,pi/2) range + */ f32 Math_FAtanF(f32 x) { if (!gUseAtanContFrac) { return Math_FAtanTaylorF(x); @@ -132,6 +139,9 @@ f32 Math_FAtanF(f32 x) { } } +/** + * @return angle to (x,y) from vector (1,0) around (0,0) in radians, in (-pi,pi] range + */ f32 Math_FAtan2F(f32 y, f32 x) { if (x == 0.0f) { if (y == 0.0f) { @@ -152,10 +162,16 @@ f32 Math_FAtan2F(f32 y, f32 x) { } } +/** + * @return arcsin(x) in radians, in [-pi/2,pi/2] range + */ f32 Math_FAsinF(f32 x) { return Math_FAtan2F(x, sqrtf(1.0f - SQ(x))); } +/** + * @return arccos(x) in radians, in [0,pi] range + */ f32 Math_FAcosF(f32 x) { return M_PI / 2 - Math_FAsinF(x); } |
