Math inlining (#182)

* Initial optimization

* something

* t&

* fix

* fix3

* documentation moved in header

* documentation 2

* format fix

* format fix2

* final change

* space fix
This commit is contained in:
Arthurpandaroux
2025-10-25 21:32:43 +02:00
committed by GitHub
parent 1805d16701
commit aceec95e6b
2 changed files with 38 additions and 45 deletions

View File

@@ -3,15 +3,46 @@
#include "ultra64.h"
f32 Math_FTanF(f32 angle);
f32 Math_FFloorF(f32 x);
f32 Math_FCeilF(f32 x);
f32 Math_FRoundF(f32 x);
f32 Math_FNearbyIntF(f32 x);
f32 Math_FTruncF(f32 x);
/**
* @param angle radians
* @return tan(angle)
*/
static inline f32 Math_FTanF(f32 angle) {
f32 sin = sinf(angle);
f32 cos = cosf(angle);
return sin / cos;
}
static inline f32 Math_FFloorF(f32 x) {
return floorf(x);
}
static inline f32 Math_FCeilF(f32 x) {
return ceilf(x);
}
static inline f32 Math_FRoundF(f32 x) {
return roundf(x);
}
static inline f32 Math_FTruncF(f32 x) {
return truncf(x);
}
static inline f32 Math_FNearbyIntF(f32 x) {
return nearbyintf(x);
}
f32 Math_FAtanF(f32 x);
f32 Math_FAtan2F(f32 y, f32 x);
f32 Math_FAsinF(f32 x);
f32 Math_FAcosF(f32 x);
/**
* @return arccos(x) in radians, in [0,pi] range
*/
static inline f32 Math_FAcosF(f32 x) {
return M_PI / 2 - Math_FAsinF(x);
}
#endif

View File

@@ -5,25 +5,6 @@
s32 gUseAtanContFrac;
#endif
/**
* @param angle radians
* @return tan(angle)
*/
f32 Math_FTanF(f32 angle) {
f32 sin = sinf(angle);
f32 cos = cosf(angle);
return sin / cos;
}
f32 Math_FFloorF(f32 x) {
return floorf(x);
}
f32 Math_FCeilF(f32 x) {
return ceilf(x);
}
#if PLATFORM_N64
f64 Math_FAbs(f64 x) {
return x < 0.0 ? -x : x;
@@ -34,18 +15,6 @@ f32 Math_FAbsF(f32 x) {
}
#endif
f32 Math_FRoundF(f32 x) {
return roundf(x);
}
f32 Math_FTruncF(f32 x) {
return truncf(x);
}
f32 Math_FNearbyIntF(f32 x) {
return nearbyintf(x);
}
#if !PLATFORM_N64
/* Arctangent approximation using a Taylor series (one quadrant) */
f32 Math_FAtanTaylorQF(f32 x) {
@@ -239,10 +208,3 @@ f32 Math_FAtan2F(f32 y, f32 x) {
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);
}