Files
dusklight/libs/dolphin/include/dolphin/sdk_math.h
T
Luke Street 9649319ec4 Reorganize library code into libs/ (#3119)
* Reorganize files into libs/{dolphin,JSystem,PowerPC_EABI_Support,revolution,TRK_MINNOW_DOLPHIN}

* Update configure.py and project.py for new libs structure

* Refactor `#include <dolphin/x.h>` -> `<x.h>`

* Remove `__REVOLUTION_SDK__` forwards from dolphin

* Fix dolphin/ references in revolution

* Wrap `#include <dolphin.h>` in `!__REVOLUTION_SDK__`

* Always build TRK against dolphin headers

* Resolve revolution SDK header resolution issues
2026-03-01 14:35:36 -08:00

69 lines
1.9 KiB
C

// fake MSL_C math for sdk specifically since it differs from game MSL_C math
extern inline float sqrtf(float x) {
static const double _half=.5;
static const double _three=3.0;
volatile float y;
if(x > 0.0f) {
double guess = __frsqrte((double)x); // returns an approximation to
guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
y=(float)(x*guess);
return y ;
}
return x ;
}
extern inline float sqrt(float x) {
static const double _half=.5;
static const double _three=3.0;
volatile float y;
if(x > 0.0f) {
double guess = __frsqrte((double)x); // returns an approximation to
guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
y=(float)(x*guess);
return y ;
}
return x ;
}
extern inline float fabs(float x) {
#if __MIPS__
return fabsf(x);
#else
(*(int*)&x)&=0x7fffffff;
return x;
#endif
}
extern inline float fabsf(float x) {
return __fabsf(x);
}
extern float cosf(float);
extern float sinf(float);
extern float tanf(float);
extern float acosf(float);
extern inline float cos(float x) {
return cosf(x);
}
inline float floor(float x) {
int i=(int)x;
float y=x-(float)i;
if(!y || x > 8388608.0f)
return x ; // x is already an int
if(x < 0)
return (float)--i;
// x < 0 -> int conversion of x above rounded toward zero(so decrement)
return (float)i;
}