diff options
| author | petrie911 <69443847+petrie911@users.noreply.github.com> | 2024-04-03 09:30:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-03 11:30:50 -0300 |
| commit | ac41c180a9e68d31d18cfc57b46032f4ccaa052a (patch) | |
| tree | af76e3fc54538127cc81f19bdb14045b9e85fc5f /src/libc_math64.c | |
| parent | 5f2b690a2b1ef89a33b5dc16440b0f87d9bc3779 (diff) | |
Reorganizaton of main (#199)
* reorganize main
* more names
* libc
Diffstat (limited to 'src/libc_math64.c')
| -rw-r--r-- | src/libc_math64.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/libc_math64.c b/src/libc_math64.c new file mode 100644 index 00000000..23399534 --- /dev/null +++ b/src/libc_math64.c @@ -0,0 +1,93 @@ +#include "sys.h" + +f32 Math_TanF(f32 x) { + return __sinf(x) / __cosf(x); +} + +f32 Math_FloorF(f32 x) { + return __floorf(x); +} + +f32 Math_CeilF(f32 x) { + return __ceilf(x); +} + +f64 Math_Fabs(f64 x) { + return (x < 0.0) ? -x : x; +} + +f32 Math_FabsF(f32 x) { + return (x < 0.0f) ? -x : x; +} + +f32 Math_NearbyIntF(f32 x) { + return __nearbyintf(x); +} + +f32 Math_TruncF(f32 x) { + return __truncf(x); +} + +f32 Math_RoundF(f32 x) { + return __roundf(x); +} + +f32 Math_FAtanF(f32 x) { + s32 sector; + s32 i; + f32 sq; + f32 conv = 0.0f; + f32 z; + + if (x > 1.0f) { + sector = 1; + x = 1.0f / x; + } else if (x < -1.0f) { + sector = -1; + x = 1.0f / x; + } else { + sector = 0; + } + + sq = SQ(x); + + for (z = i = 24; i != 0; i--) { + conv = SQ(z) * sq / (2.0f * z + 1.0f + conv); + z -= 1.0f; + } + + if (sector > 0) { + return M_PI / 2.0f - (x / (1.0f + conv)); + } else if (sector < 0) { + return -M_PI / 2.0f - (x / (1.0f + conv)); + } else { + return x / (1.0f + conv); + } +} + +f32 Math_FAtan2F(f32 y, f32 x) { + if ((y == 0.0f) && (x == 0.0f)) { + return 0.0f; + } + if (x == 0.0f) { + if (y < 0.0f) { + return -M_PI / 2.0f; + } + return M_PI / 2.0f; + } + if (x < 0.0f) { + if (y < 0.0f) { + return -(M_PI - Math_FAtanF(fabs(y / x))); + } + return M_PI - Math_FAtanF(fabs(y / x)); + } + return Math_FAtanF(y / x); +} + +f32 Math_FAsinF(f32 x) { + return Math_FAtan2F(x, sqrtf(1 - SQ(x))); +} + +f32 Math_FAcosF(f32 x) { + return M_PI / 2.0f - Math_FAsinF(x); +} |
