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
This commit is contained in:
Dragorn421
2022-10-15 23:29:36 +02:00
committed by GitHub
parent 0b38f6e678
commit 0283493db8
10 changed files with 104 additions and 40 deletions
+20 -4
View File
@@ -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);
}