Properly fix sqrtf constants

This commit is contained in:
gamemasterplc 2024-11-09 15:49:29 -06:00
parent 4a4967d4a3
commit ce70fc74af
17 changed files with 29 additions and 32 deletions

View file

@ -10,17 +10,19 @@
#ifdef __MWERKS__
extern inline float sqrtf(float x)
{
volatile float y;
if(x > 0.0f)
{
double guess = __frsqrte((double)x); // returns an approximation to
guess = 0.5*guess*(3.0 - guess*guess*x); // now have 12 sig bits
guess = 0.5*guess*(3.0 - guess*guess*x); // now have 24 sig bits
guess = 0.5*guess*(3.0 - guess*guess*x); // now have 32 sig bits
y=(float)(x*guess);
return y;
}
return 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;
}
#else
float sqrtf(float x);