mirror of
https://github.com/zeldaret/oot
synced 2026-05-29 16:44:55 -04:00
Consistent naming for Math_ functions (#542)
* Darkmeiro decompilation Bg_Gnd_Darkmeiro decompiled, matched, and documented. * give this a shot * fix conflict * one more try * could be useful * whoops * ZAP2 stuff * ZAP why * ZAP again * maths * Factoriali -> Factorial * soon, soon * renames * rand * docs * merged * formatting * little more cleanup * asm crept back in * changes to MathF * smooth criminal * functions.h
This commit is contained in:
+50
-50
@@ -1,38 +1,38 @@
|
||||
#include "global.h"
|
||||
#include "fp.h"
|
||||
|
||||
s32 use_cfrac;
|
||||
s32 gUseAtanContFrac;
|
||||
|
||||
f32 Math_tanf(f32 x) {
|
||||
f32 Math_FTanF(f32 x) {
|
||||
f32 sin = sinf(x);
|
||||
f32 cos = cosf(x);
|
||||
return sin / cos;
|
||||
}
|
||||
|
||||
f32 Math_floorf(f32 x) {
|
||||
f32 Math_FFloorF(f32 x) {
|
||||
return floorf(x);
|
||||
}
|
||||
|
||||
f32 Math_ceilf(f32 x) {
|
||||
f32 Math_FCeilF(f32 x) {
|
||||
return ceilf(x);
|
||||
}
|
||||
|
||||
f32 Math_roundf(f32 x) {
|
||||
f32 Math_FRoundF(f32 x) {
|
||||
return roundf(x);
|
||||
}
|
||||
|
||||
f32 Math_truncf(f32 x) {
|
||||
f32 Math_FTruncF(f32 x) {
|
||||
return truncf(x);
|
||||
}
|
||||
|
||||
f32 Math_nearbyintf(f32 x) {
|
||||
f32 Math_FNearbyIntF(f32 x) {
|
||||
return nearbyintf(x);
|
||||
}
|
||||
|
||||
/* Arctangent approximation using a Taylor series (one quadrant) */
|
||||
f32 Math_atanf_taylor_q(f32 x) {
|
||||
f32 Math_FAtanTaylorQF(f32 x) {
|
||||
static const f32 coeffs[] = {
|
||||
-1.f / 3, +1.f / 5, -1.f / 7, +1.f / 9, -1.f / 11, +1.f / 13, -1.f / 15, +1.f / 17, 0.f,
|
||||
-1.0f / 3, +1.0f / 5, -1.0f / 7, +1.0f / 9, -1.0f / 11, +1.0f / 13, -1.0f / 15, +1.0f / 17, 0.0f,
|
||||
};
|
||||
|
||||
f32 poly = x;
|
||||
@@ -54,31 +54,31 @@ f32 Math_atanf_taylor_q(f32 x) {
|
||||
}
|
||||
|
||||
/* Ditto for two quadrants */
|
||||
f32 Math_atanf_taylor(f32 x) {
|
||||
f32 Math_FAtanTaylorF(f32 x) {
|
||||
f32 t;
|
||||
f32 q;
|
||||
|
||||
if (x > 0.f) {
|
||||
if (x > 0.0f) {
|
||||
t = x;
|
||||
} else if (x < 0.f) {
|
||||
} else if (x < 0.0f) {
|
||||
t = -x;
|
||||
} else if (x == 0.f) {
|
||||
return 0.f;
|
||||
} else if (x == 0.0f) {
|
||||
return 0.0f;
|
||||
} else {
|
||||
return qNaN0x10000;
|
||||
}
|
||||
|
||||
if (t <= M_SQRT2 - 1.f) {
|
||||
return Math_atanf_taylor_q(x);
|
||||
if (t <= M_SQRT2 - 1.0f) {
|
||||
return Math_FAtanTaylorQF(x);
|
||||
}
|
||||
|
||||
if (t >= M_SQRT2 + 1.f) {
|
||||
q = M_PI / 2 - Math_atanf_taylor_q(1.f / t);
|
||||
if (t >= M_SQRT2 + 1.0f) {
|
||||
q = M_PI / 2 - Math_FAtanTaylorQF(1.0f / t);
|
||||
} else {
|
||||
q = M_PI / 4 - Math_atanf_taylor_q((1.f - t) / (1.f + t));
|
||||
q = M_PI / 4 - Math_FAtanTaylorQF((1.0f - t) / (1.0f + t));
|
||||
}
|
||||
|
||||
if (x > 0.f) {
|
||||
if (x > 0.0f) {
|
||||
return q;
|
||||
} else {
|
||||
return -q;
|
||||
@@ -86,33 +86,33 @@ f32 Math_atanf_taylor(f32 x) {
|
||||
}
|
||||
|
||||
/* Arctangent approximation using a continued fraction */
|
||||
f32 Math_atanf_cfrac(f32 x) {
|
||||
f32 Math_FAtanContFracF(f32 x) {
|
||||
s32 sector;
|
||||
f32 z;
|
||||
f32 conv;
|
||||
f32 sq;
|
||||
s32 i;
|
||||
|
||||
if (x >= -1.f && x <= 1.f) {
|
||||
if (x >= -1.0f && x <= 1.0f) {
|
||||
sector = 0;
|
||||
} else if (x > 1.f) {
|
||||
} else if (x > 1.0f) {
|
||||
sector = 1;
|
||||
x = 1.f / x;
|
||||
} else if (x < -1.f) {
|
||||
x = 1.0f / x;
|
||||
} else if (x < -1.0f) {
|
||||
sector = -1;
|
||||
x = 1.f / x;
|
||||
x = 1.0f / x;
|
||||
} else {
|
||||
return qNaN0x10000;
|
||||
}
|
||||
|
||||
sq = SQ(x);
|
||||
conv = 0.f;
|
||||
z = 8.f;
|
||||
conv = 0.0f;
|
||||
z = 8.0f;
|
||||
for (i = 8; i != 0; i--) {
|
||||
conv = SQ(z) * sq / (2.f * z + 1.f + conv);
|
||||
z -= 1.f;
|
||||
conv = SQ(z) * sq / (2.0f * z + 1.0f + conv);
|
||||
z -= 1.0f;
|
||||
}
|
||||
conv = x / (1.f + conv);
|
||||
conv = x / (1.0f + conv);
|
||||
|
||||
if (sector == 0) {
|
||||
return conv;
|
||||
@@ -123,38 +123,38 @@ f32 Math_atanf_cfrac(f32 x) {
|
||||
}
|
||||
}
|
||||
|
||||
f32 Math_atanf(f32 x) {
|
||||
if (use_cfrac == 0) {
|
||||
return Math_atanf_taylor(x);
|
||||
f32 Math_FAtanF(f32 x) {
|
||||
if (!gUseAtanContFrac) {
|
||||
return Math_FAtanTaylorF(x);
|
||||
} else {
|
||||
return Math_atanf_cfrac(x);
|
||||
return Math_FAtanContFracF(x);
|
||||
}
|
||||
}
|
||||
|
||||
f32 Math_atan2f(f32 y, f32 x) {
|
||||
if (x == 0.f) {
|
||||
if (y == 0.f) {
|
||||
return 0.f;
|
||||
} else if (y > 0.f) {
|
||||
f32 Math_FAtan2F(f32 y, f32 x) {
|
||||
if (x == 0.0f) {
|
||||
if (y == 0.0f) {
|
||||
return 0.0f;
|
||||
} else if (y > 0.0f) {
|
||||
return M_PI / 2;
|
||||
} else if (y < 0.f) {
|
||||
} else if (y < 0.0f) {
|
||||
return -M_PI / 2;
|
||||
} else {
|
||||
return qNaN0x10000;
|
||||
}
|
||||
} else if (x >= 0.f) {
|
||||
return Math_atanf(y / x);
|
||||
} else if (y < 0.f) {
|
||||
return Math_atanf(y / x) - M_PI;
|
||||
} else if (x >= 0.0f) {
|
||||
return Math_FAtanF(y / x);
|
||||
} else if (y < 0.0f) {
|
||||
return Math_FAtanF(y / x) - M_PI;
|
||||
} else {
|
||||
return M_PI - Math_atanf(-(y / x));
|
||||
return M_PI - Math_FAtanF(-(y / x));
|
||||
}
|
||||
}
|
||||
|
||||
f32 Math_asinf(f32 x) {
|
||||
return Math_atan2f(x, sqrtf(1.f - SQ(x)));
|
||||
f32 Math_FAsinF(f32 x) {
|
||||
return Math_FAtan2F(x, sqrtf(1.0f - SQ(x)));
|
||||
}
|
||||
|
||||
f32 Math_acosf(f32 x) {
|
||||
return M_PI / 2 - Math_asinf(x);
|
||||
f32 Math_FAcosF(f32 x) {
|
||||
return M_PI / 2 - Math_FAsinF(x);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user