Introduce better fix to fake 0.5 and 3.0 double constants
Uses a new rel_sqrt_consts.h file
This commit is contained in:
parent
fa82e1e788
commit
c2506716d2
14 changed files with 70 additions and 76 deletions
|
|
@ -7,24 +7,6 @@
|
|||
#define _MATH_INLINE static inline
|
||||
#endif
|
||||
|
||||
#ifdef MATH_EXPORT_CONST
|
||||
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;
|
||||
}
|
||||
#else
|
||||
extern inline float sqrtf(float x)
|
||||
{
|
||||
volatile float y;
|
||||
|
|
@ -39,7 +21,6 @@ extern inline float sqrtf(float x)
|
|||
}
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
double atan(double x);
|
||||
double copysign(double x, double y);
|
||||
|
|
|
|||
8
include/rel_sqrt_consts.h
Normal file
8
include/rel_sqrt_consts.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _REL_SQRT_CONSTS
|
||||
#define _REL_SQRT_CONSTS
|
||||
|
||||
const double __fakeHalf = 0.5;
|
||||
const double __fakeThree = 3.0;
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue