Remove unneeded standard math functions

This commit is contained in:
Jack Andersen
2018-06-02 20:10:58 -10:00
parent b1b4903cb1
commit 17a501f339
6 changed files with 7 additions and 148 deletions

View File

@@ -187,88 +187,6 @@ CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f
(d * t * t * t);
}
double sqrtD(double val)
{
if (val <= 0.0)
{
// Dunnno what retro is doing here,
// but this shouldn't come up anyway.
if (val != 0.0)
return 1.0 / (float)0x7FFFFFFF;
if (val == 0.0)
return 1.0 / (float)0x7F800000;
}
double q;
#if __SSE__
union {
__m128d v;
double d[2];
} qv = {val};
qv.v = _mm_sqrt_sd(qv.v, qv.v);
q = qv.d[0];
#else
// le sigh, let's use Carmack's inverse square -.-
union {
double v;
int i;
} p;
double x = val * 0.5F;
p.v = val;
p.i = 0x5fe6eb50c7b537a9 - (p.i >> 1);
p.v *= (1.5f - (x * p.v * p.v));
p.v *= (1.5f - (x * p.v * p.v));
q = p.v;
static const double half = 0.5;
static const double three = 3.0;
double sq = q * q;
q = half * q;
sq = -((val * three) - sq);
q = q * sq;
sq = q * q;
q = q * q;
sq = -((val * three) - sq);
q = q * sq;
sq = q * q;
q = half * q;
sq = -((val * three) - sq);
q = q * sq;
sq = q * q;
q = half * q;
sq = -((val * three) - sq);
sq = q * sq;
q = val * sq;
#endif
return q;
}
float fastArcCosF(float val)
{
/* If we're not at a low enough value,
* the approximation below won't provide any benefit,
* and we simply fall back to the standard implementation
*/
if (std::fabs(val) >= 0.925000011920929f)
return std::acos(val);
/* Fast Arc Cosine approximation using Taylor Polynomials
* while this implementation is fast, it's also not as accurate.
* This is a straight reimplementation of Retro's CFastArcCosR
* and as a result of the polynomials, it returns the inverse value,
* I'm not certain if this was intended originally, but we'll leave it
* in order to be as accurate as possible.
*/
double mag = (val * val);
double a = ((val * 1.5707964f) + -0.99822718f);
double b = (val * mag);
a = ((b * a) + -0.20586604f);
b *= mag;
a = ((b * a) + 0.1142542f);
b *= mag;
return ((b * a) + -0.2969782f);
}
int floorPowerOfTwo(int x)
{
if (x == 0)
@@ -302,52 +220,6 @@ int ceilingPowerOfTwo(int x)
return x;
}
float fastCosF(float val)
{
if (std::fabs(val) > M_PIF)
{
float rVal = float(uint32_t(val));
val = -((rVal * val) - 6.2831855f);
if (val <= M_PIF && val < -M_PIF)
val += 6.2831855f;
else
val -= 6.2831855f;
}
float sq = val * val;
float b = sq * sq;
val = sq + -0.4999803f;
val = (b * val) + 0.041620344f;
b = b * sq;
val = (b * val) + -0.0013636103f;
b = b * sq;
val = (b * val) + 0.000020169435f;
return val;
}
float fastSinF(float val)
{
if (std::fabs(val) > M_PIF)
{
float rVal = float(uint32_t(val));
val = -((rVal * val) - 6.2831855f);
if (val <= M_PIF && val < -M_PIF)
val += 6.2831855f;
else
val -= 6.2831855f;
}
float sq = val * val;
float ret = val * 0.99980587f;
val = val * sq;
ret = (val * ret) + -0.16621658f;
val = val * sq;
ret = (val * ret) + 0.0080871079f;
val = val * sq;
ret = (val * ret) + -0.00015297699f;
return ret;
}
float getCatmullRomSplinePoint(float a, float b, float c, float d, float t)
{
if (t <= 0.0f)