mirror of
https://github.com/bkaradzic/bx.git
synced 2026-06-08 11:13:49 +00:00
bx math API cleanup.
This commit is contained in:
@@ -36,12 +36,12 @@ namespace bx
|
||||
|
||||
inline float easeSmoothStep(float _t)
|
||||
{
|
||||
return fsq(_t)*(3.0f - 2.0f*_t);
|
||||
return square(_t)*(3.0f - 2.0f*_t);
|
||||
}
|
||||
|
||||
inline float easeInQuad(float _t)
|
||||
{
|
||||
return fsq(_t);
|
||||
return square(_t);
|
||||
}
|
||||
|
||||
inline float easeOutQuad(float _t)
|
||||
@@ -121,7 +121,7 @@ namespace bx
|
||||
|
||||
inline float easeInSine(float _t)
|
||||
{
|
||||
return 1.0f - fcos(_t*kPiHalf);
|
||||
return 1.0f - cos(_t*kPiHalf);
|
||||
}
|
||||
|
||||
inline float easeOutSine(float _t)
|
||||
@@ -141,7 +141,7 @@ namespace bx
|
||||
|
||||
inline float easeInExpo(float _t)
|
||||
{
|
||||
return fpow(2.0f, 10.0f * (_t - 1.0f) ) - 0.001f;
|
||||
return pow(2.0f, 10.0f * (_t - 1.0f) ) - 0.001f;
|
||||
}
|
||||
|
||||
inline float easeOutExpo(float _t)
|
||||
@@ -161,7 +161,7 @@ namespace bx
|
||||
|
||||
inline float easeInCirc(float _t)
|
||||
{
|
||||
return -(fsqrt(1.0f - _t*_t) - 1.0f);
|
||||
return -(sqrt(1.0f - _t*_t) - 1.0f);
|
||||
}
|
||||
|
||||
inline float easeOutCirc(float _t)
|
||||
@@ -181,7 +181,7 @@ namespace bx
|
||||
|
||||
inline float easeOutElastic(float _t)
|
||||
{
|
||||
return fpow(2.0f, -10.0f*_t)*fsin( (_t-0.3f/4.0f)*(2.0f*kPi)/0.3f) + 1.0f;
|
||||
return pow(2.0f, -10.0f*_t)*sin( (_t-0.3f/4.0f)*(2.0f*kPi)/0.3f) + 1.0f;
|
||||
}
|
||||
|
||||
inline float easeInElastic(float _t)
|
||||
@@ -201,7 +201,7 @@ namespace bx
|
||||
|
||||
inline float easeInBack(float _t)
|
||||
{
|
||||
return easeInCubic(_t) - _t*fsin(_t*kPi);
|
||||
return easeInCubic(_t) - _t*sin(_t*kPi);
|
||||
}
|
||||
|
||||
inline float easeOutBack(float _t)
|
||||
|
||||
@@ -92,125 +92,125 @@ namespace bx
|
||||
return tmp == UINT64_C(0x7ff0000000000000);
|
||||
}
|
||||
|
||||
inline float fround(float _f)
|
||||
inline float round(float _f)
|
||||
{
|
||||
return ffloor(_f + 0.5f);
|
||||
return floor(_f + 0.5f);
|
||||
}
|
||||
|
||||
inline float fceil(float _a)
|
||||
inline float ceil(float _a)
|
||||
{
|
||||
return -ffloor(-_a);
|
||||
return -floor(-_a);
|
||||
}
|
||||
|
||||
inline float flerp(float _a, float _b, float _t)
|
||||
inline float lerp(float _a, float _b, float _t)
|
||||
{
|
||||
return _a + (_b - _a) * _t;
|
||||
}
|
||||
|
||||
inline float fabs(float _a)
|
||||
inline float abs(float _a)
|
||||
{
|
||||
return _a < 0.0f ? -_a : _a;
|
||||
}
|
||||
|
||||
inline float fsign(float _a)
|
||||
inline float sign(float _a)
|
||||
{
|
||||
return _a < 0.0f ? -1.0f : 1.0f;
|
||||
}
|
||||
|
||||
inline float fsq(float _a)
|
||||
inline float square(float _a)
|
||||
{
|
||||
return _a * _a;
|
||||
}
|
||||
|
||||
inline float fexp2(float _a)
|
||||
inline float exp2(float _a)
|
||||
{
|
||||
return fpow(2.0f, _a);
|
||||
return pow(2.0f, _a);
|
||||
}
|
||||
|
||||
inline float flog2(float _a)
|
||||
inline float log2(float _a)
|
||||
{
|
||||
return flog(_a) * kInvLogNat2;
|
||||
return log(_a) * kInvLogNat2;
|
||||
}
|
||||
|
||||
inline float frsqrt(float _a)
|
||||
inline float rsqrt(float _a)
|
||||
{
|
||||
return 1.0f/fsqrt(_a);
|
||||
return 1.0f/sqrt(_a);
|
||||
}
|
||||
|
||||
inline float ftrunc(float _a)
|
||||
inline float trunc(float _a)
|
||||
{
|
||||
return float(int(_a) );
|
||||
}
|
||||
|
||||
inline float ffract(float _a)
|
||||
inline float fract(float _a)
|
||||
{
|
||||
return _a - ftrunc(_a);
|
||||
return _a - trunc(_a);
|
||||
}
|
||||
|
||||
inline float fmod(float _a, float _b)
|
||||
inline float mod(float _a, float _b)
|
||||
{
|
||||
return _a - _b * ffloor(_a / _b);
|
||||
return _a - _b * floor(_a / _b);
|
||||
}
|
||||
|
||||
inline bool fequal(float _a, float _b, float _epsilon)
|
||||
inline bool equal(float _a, float _b, float _epsilon)
|
||||
{
|
||||
// http://realtimecollisiondetection.net/blog/?p=89
|
||||
const float lhs = fabs(_a - _b);
|
||||
const float rhs = _epsilon * max(1.0f, fabs(_a), fabs(_b) );
|
||||
const float lhs = abs(_a - _b);
|
||||
const float rhs = _epsilon * max(1.0f, abs(_a), abs(_b) );
|
||||
return lhs <= rhs;
|
||||
}
|
||||
|
||||
inline bool fequal(const float* _a, const float* _b, uint32_t _num, float _epsilon)
|
||||
inline bool equal(const float* _a, const float* _b, uint32_t _num, float _epsilon)
|
||||
{
|
||||
bool equal = fequal(_a[0], _b[0], _epsilon);
|
||||
for (uint32_t ii = 1; equal && ii < _num; ++ii)
|
||||
bool result = equal(_a[0], _b[0], _epsilon);
|
||||
for (uint32_t ii = 1; result && ii < _num; ++ii)
|
||||
{
|
||||
equal = fequal(_a[ii], _b[ii], _epsilon);
|
||||
result = equal(_a[ii], _b[ii], _epsilon);
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
|
||||
inline float fwrap(float _a, float _wrap)
|
||||
{
|
||||
const float mod = fmod(_a, _wrap);
|
||||
const float result = mod < 0.0f ? _wrap + mod : mod;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline float fstep(float _edge, float _a)
|
||||
inline float wrap(float _a, float _wrap)
|
||||
{
|
||||
const float tmp0 = mod(_a, _wrap);
|
||||
const float result = tmp0 < 0.0f ? _wrap + tmp0 : tmp0;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline float step(float _edge, float _a)
|
||||
{
|
||||
return _a < _edge ? 0.0f : 1.0f;
|
||||
}
|
||||
|
||||
inline float fpulse(float _a, float _start, float _end)
|
||||
inline float pulse(float _a, float _start, float _end)
|
||||
{
|
||||
return fstep(_a, _start) - fstep(_a, _end);
|
||||
return step(_a, _start) - step(_a, _end);
|
||||
}
|
||||
|
||||
inline float fsmoothstep(float _a)
|
||||
inline float smoothStep(float _a)
|
||||
{
|
||||
return fsq(_a)*(3.0f - 2.0f*_a);
|
||||
return square(_a)*(3.0f - 2.0f*_a);
|
||||
}
|
||||
|
||||
inline float fbias(float _time, float _bias)
|
||||
inline float bias(float _time, float _bias)
|
||||
{
|
||||
return _time / ( ( (1.0f/_bias - 2.0f)*(1.0f - _time) ) + 1.0f);
|
||||
}
|
||||
|
||||
inline float fgain(float _time, float _gain)
|
||||
inline float gain(float _time, float _gain)
|
||||
{
|
||||
if (_time < 0.5f)
|
||||
{
|
||||
return fbias(_time * 2.0f, _gain) * 0.5f;
|
||||
return bias(_time * 2.0f, _gain) * 0.5f;
|
||||
}
|
||||
|
||||
return fbias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f;
|
||||
return bias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f;
|
||||
}
|
||||
|
||||
inline float angleDiff(float _a, float _b)
|
||||
{
|
||||
const float dist = fwrap(_b - _a, kPi2);
|
||||
return fwrap(dist*2.0f, kPi2) - dist;
|
||||
const float dist = wrap(_b - _a, kPi2);
|
||||
return wrap(dist*2.0f, kPi2) - dist;
|
||||
}
|
||||
|
||||
inline float angleLerp(float _a, float _b, float _t)
|
||||
@@ -227,9 +227,9 @@ namespace bx
|
||||
|
||||
inline void vec3Abs(float* _result, const float* _a)
|
||||
{
|
||||
_result[0] = fabs(_a[0]);
|
||||
_result[1] = fabs(_a[1]);
|
||||
_result[2] = fabs(_a[2]);
|
||||
_result[0] = abs(_a[0]);
|
||||
_result[1] = abs(_a[1]);
|
||||
_result[2] = abs(_a[2]);
|
||||
}
|
||||
|
||||
inline void vec3Neg(float* _result, const float* _a)
|
||||
@@ -295,21 +295,21 @@ namespace bx
|
||||
|
||||
inline float vec3Length(const float* _a)
|
||||
{
|
||||
return fsqrt(vec3Dot(_a, _a) );
|
||||
return sqrt(vec3Dot(_a, _a) );
|
||||
}
|
||||
|
||||
inline void vec3Lerp(float* _result, const float* _a, const float* _b, float _t)
|
||||
{
|
||||
_result[0] = flerp(_a[0], _b[0], _t);
|
||||
_result[1] = flerp(_a[1], _b[1], _t);
|
||||
_result[2] = flerp(_a[2], _b[2], _t);
|
||||
_result[0] = lerp(_a[0], _b[0], _t);
|
||||
_result[1] = lerp(_a[1], _b[1], _t);
|
||||
_result[2] = lerp(_a[2], _b[2], _t);
|
||||
}
|
||||
|
||||
inline void vec3Lerp(float* _result, const float* _a, const float* _b, const float* _c)
|
||||
{
|
||||
_result[0] = flerp(_a[0], _b[0], _c[0]);
|
||||
_result[1] = flerp(_a[1], _b[1], _c[1]);
|
||||
_result[2] = flerp(_a[2], _b[2], _c[2]);
|
||||
_result[0] = lerp(_a[0], _b[0], _c[0]);
|
||||
_result[1] = lerp(_a[1], _b[1], _c[1]);
|
||||
_result[2] = lerp(_a[2], _b[2], _c[2]);
|
||||
}
|
||||
|
||||
inline float vec3Norm(float* _result, const float* _a)
|
||||
@@ -349,60 +349,60 @@ namespace bx
|
||||
const float ny = _n[1];
|
||||
const float nz = _n[2];
|
||||
|
||||
if (bx::fabs(nx) > bx::fabs(nz) )
|
||||
if (abs(nx) > abs(nz) )
|
||||
{
|
||||
float invLen = 1.0f / bx::fsqrt(nx*nx + nz*nz);
|
||||
float invLen = 1.0f / sqrt(nx*nx + nz*nz);
|
||||
_t[0] = -nz * invLen;
|
||||
_t[1] = 0.0f;
|
||||
_t[2] = nx * invLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
float invLen = 1.0f / bx::fsqrt(ny*ny + nz*nz);
|
||||
float invLen = 1.0f / sqrt(ny*ny + nz*nz);
|
||||
_t[0] = 0.0f;
|
||||
_t[1] = nz * invLen;
|
||||
_t[2] = -ny * invLen;
|
||||
}
|
||||
|
||||
bx::vec3Cross(_b, _n, _t);
|
||||
vec3Cross(_b, _n, _t);
|
||||
}
|
||||
|
||||
inline void vec3TangentFrame(const float* _n, float* _t, float* _b, float _angle)
|
||||
{
|
||||
vec3TangentFrame(_n, _t, _b);
|
||||
|
||||
const float sa = fsin(_angle);
|
||||
const float ca = fcos(_angle);
|
||||
const float sa = sin(_angle);
|
||||
const float ca = cos(_angle);
|
||||
|
||||
_t[0] = -sa * _b[0] + ca * _t[0];
|
||||
_t[1] = -sa * _b[1] + ca * _t[1];
|
||||
_t[2] = -sa * _b[2] + ca * _t[2];
|
||||
|
||||
bx::vec3Cross(_b, _n, _t);
|
||||
vec3Cross(_b, _n, _t);
|
||||
}
|
||||
|
||||
inline void vec3FromLatLong(float* _vec, float _u, float _v)
|
||||
{
|
||||
const float phi = _u * bx::kPi2;
|
||||
const float theta = _v * bx::kPi;
|
||||
const float phi = _u * kPi2;
|
||||
const float theta = _v * kPi;
|
||||
|
||||
const float st = bx::fsin(theta);
|
||||
const float sp = bx::fsin(phi);
|
||||
const float ct = bx::fcos(theta);
|
||||
const float cp = bx::fcos(phi);
|
||||
const float st = sin(theta);
|
||||
const float sp = sin(phi);
|
||||
const float ct = cos(theta);
|
||||
const float cp = cos(phi);
|
||||
|
||||
_vec[0] = -st*sp;
|
||||
_vec[1] = ct;
|
||||
_vec[1] = ct;
|
||||
_vec[2] = -st*cp;
|
||||
}
|
||||
|
||||
inline void vec3ToLatLong(float* _u, float* _v, const float* _vec)
|
||||
{
|
||||
const float phi = bx::fatan2(_vec[0], _vec[2]);
|
||||
const float theta = bx::facos(_vec[1]);
|
||||
const float phi = atan2(_vec[0], _vec[2]);
|
||||
const float theta = acos(_vec[1]);
|
||||
|
||||
*_u = (bx::kPi + phi)*bx::kInvPi*0.5f;
|
||||
*_v = theta*bx::kInvPi;
|
||||
*_u = (kPi + phi)*kInvPi*0.5f;
|
||||
*_v = theta*kInvPi;
|
||||
}
|
||||
|
||||
inline void quatIdentity(float* _result)
|
||||
@@ -478,7 +478,7 @@ namespace bx
|
||||
const float norm = quatDot(_quat, _quat);
|
||||
if (0.0f < norm)
|
||||
{
|
||||
const float invNorm = 1.0f / fsqrt(norm);
|
||||
const float invNorm = 1.0f / sqrt(norm);
|
||||
_result[0] = _quat[0] * invNorm;
|
||||
_result[1] = _quat[1] * invNorm;
|
||||
_result[2] = _quat[2] * invNorm;
|
||||
@@ -501,16 +501,16 @@ namespace bx
|
||||
const float zz = z * z;
|
||||
|
||||
const float xx = x * x;
|
||||
_result[0] = fatan2(2.0f * (x * w - y * z), 1.0f - 2.0f * (xx + zz) );
|
||||
_result[1] = fatan2(2.0f * (y * w + x * z), 1.0f - 2.0f * (yy + zz) );
|
||||
_result[2] = fasin (2.0f * (x * y + z * w) );
|
||||
_result[0] = atan2(2.0f * (x * w - y * z), 1.0f - 2.0f * (xx + zz) );
|
||||
_result[1] = atan2(2.0f * (y * w + x * z), 1.0f - 2.0f * (yy + zz) );
|
||||
_result[2] = asin (2.0f * (x * y + z * w) );
|
||||
}
|
||||
|
||||
inline void quatRotateAxis(float* _result, const float* _axis, float _angle)
|
||||
{
|
||||
const float ha = _angle * 0.5f;
|
||||
const float ca = fcos(ha);
|
||||
const float sa = fsin(ha);
|
||||
const float ca = cos(ha);
|
||||
const float sa = sin(ha);
|
||||
_result[0] = _axis[0] * sa;
|
||||
_result[1] = _axis[1] * sa;
|
||||
_result[2] = _axis[2] * sa;
|
||||
@@ -520,8 +520,8 @@ namespace bx
|
||||
inline void quatRotateX(float* _result, float _ax)
|
||||
{
|
||||
const float hx = _ax * 0.5f;
|
||||
const float cx = fcos(hx);
|
||||
const float sx = fsin(hx);
|
||||
const float cx = cos(hx);
|
||||
const float sx = sin(hx);
|
||||
_result[0] = sx;
|
||||
_result[1] = 0.0f;
|
||||
_result[2] = 0.0f;
|
||||
@@ -531,8 +531,8 @@ namespace bx
|
||||
inline void quatRotateY(float* _result, float _ay)
|
||||
{
|
||||
const float hy = _ay * 0.5f;
|
||||
const float cy = fcos(hy);
|
||||
const float sy = fsin(hy);
|
||||
const float cy = cos(hy);
|
||||
const float sy = sin(hy);
|
||||
_result[0] = 0.0f;
|
||||
_result[1] = sy;
|
||||
_result[2] = 0.0f;
|
||||
@@ -542,8 +542,8 @@ namespace bx
|
||||
inline void quatRotateZ(float* _result, float _az)
|
||||
{
|
||||
const float hz = _az * 0.5f;
|
||||
const float cz = fcos(hz);
|
||||
const float sz = fsin(hz);
|
||||
const float cz = cos(hz);
|
||||
const float sz = sin(hz);
|
||||
_result[0] = 0.0f;
|
||||
_result[1] = 0.0f;
|
||||
_result[2] = sz;
|
||||
@@ -712,7 +712,7 @@ namespace bx
|
||||
float yy = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13];
|
||||
float zz = _vec[0] * _mat[ 2] + _vec[1] * _mat[6] + _vec[2] * _mat[10] + _mat[14];
|
||||
float ww = _vec[0] * _mat[ 3] + _vec[1] * _mat[7] + _vec[2] * _mat[11] + _mat[15];
|
||||
float invW = fsign(ww)/ww;
|
||||
float invW = sign(ww)/ww;
|
||||
_result[0] = xx*invW;
|
||||
_result[1] = yy*invW;
|
||||
_result[2] = zz*invW;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace bx
|
||||
{
|
||||
inline uint32_t toUnorm(float _value, float _scale)
|
||||
{
|
||||
return uint32_t(fround(clamp(_value, 0.0f, 1.0f) * _scale) );
|
||||
return uint32_t(round(clamp(_value, 0.0f, 1.0f) * _scale) );
|
||||
}
|
||||
|
||||
inline float fromUnorm(uint32_t _value, float _scale)
|
||||
@@ -21,7 +21,7 @@ namespace bx
|
||||
|
||||
inline int32_t toSnorm(float _value, float _scale)
|
||||
{
|
||||
return int32_t(fround(
|
||||
return int32_t(round(
|
||||
clamp(_value, -1.0f, 1.0f) * _scale)
|
||||
);
|
||||
}
|
||||
@@ -719,18 +719,18 @@ namespace bx
|
||||
const float mm = max(rr, gg, bb);
|
||||
union { float ff; uint32_t ui; } cast = { mm };
|
||||
int32_t expShared = int32_t(uint32_imax(uint32_t(-expBias-1), ( ( (cast.ui>>23) & 0xff) - 127) ) ) + 1 + expBias;
|
||||
float denom = fpow(2.0f, float(expShared - expBias - MantissaBits) );
|
||||
float denom = pow(2.0f, float(expShared - expBias - MantissaBits) );
|
||||
|
||||
if ( (1<<MantissaBits) == int32_t(fround(mm/denom) ) )
|
||||
if ( (1<<MantissaBits) == int32_t(round(mm/denom) ) )
|
||||
{
|
||||
denom *= 2.0f;
|
||||
++expShared;
|
||||
}
|
||||
|
||||
const float invDenom = 1.0f/denom;
|
||||
_dst[0] = fround(rr * invDenom);
|
||||
_dst[1] = fround(gg * invDenom);
|
||||
_dst[2] = fround(bb * invDenom);
|
||||
_dst[0] = round(rr * invDenom);
|
||||
_dst[1] = round(gg * invDenom);
|
||||
_dst[2] = round(bb * invDenom);
|
||||
_dst[3] = float(expShared);
|
||||
}
|
||||
|
||||
@@ -739,7 +739,7 @@ namespace bx
|
||||
{
|
||||
const int32_t expBias = (1<<(ExpBits - 1) ) - 1;
|
||||
const float exponent = _src[3]-float(expBias-MantissaBits);
|
||||
const float scale = fpow(2.0f, exponent);
|
||||
const float scale = pow(2.0f, exponent);
|
||||
_dst[0] = _src[0] * scale;
|
||||
_dst[1] = _src[1] * scale;
|
||||
_dst[2] = _src[2] * scale;
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace bx
|
||||
{
|
||||
const float angle = frnd(_rng) * kPi2;
|
||||
|
||||
_result[0] = fcos(angle);
|
||||
_result[0] = cos(angle);
|
||||
_result[1] = 0.0f;
|
||||
_result[2] = fsin(angle);
|
||||
_result[2] = sin(angle);
|
||||
}
|
||||
|
||||
template <typename Rng>
|
||||
@@ -74,10 +74,10 @@ namespace bx
|
||||
{
|
||||
const float rand0 = frnd(_rng) * 2.0f - 1.0f;
|
||||
const float rand1 = frnd(_rng) * kPi2;
|
||||
const float sqrtf1 = fsqrt(1.0f - rand0*rand0);
|
||||
const float sqrtf1 = sqrt(1.0f - rand0*rand0);
|
||||
|
||||
_result[0] = sqrtf1 * fcos(rand1);
|
||||
_result[1] = sqrtf1 * fsin(rand1);
|
||||
_result[0] = sqrtf1 * cos(rand1);
|
||||
_result[1] = sqrtf1 * sin(rand1);
|
||||
_result[2] = rand0;
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ namespace bx
|
||||
|
||||
const float phi = (ii + 0.5f) / _num;
|
||||
const float phirad = phi * kPi2;
|
||||
const float st = fsqrt(1.0f-tt*tt) * _scale;
|
||||
const float st = sqrt(1.0f-tt*tt) * _scale;
|
||||
|
||||
float* xyz = (float*)data;
|
||||
data += _stride;
|
||||
|
||||
xyz[0] = st * fcos(phirad);
|
||||
xyz[1] = st * fsin(phirad);
|
||||
xyz[0] = st * cos(phirad);
|
||||
xyz[1] = st * sin(phirad);
|
||||
xyz[2] = tt * _scale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,10 +364,10 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf);
|
||||
BX_SIMD_FORCE_INLINE simd128_ref_t simd_sqrt(simd128_ref_t _a)
|
||||
{
|
||||
simd128_ref_t result;
|
||||
result.fxyzw[0] = fsqrt(_a.fxyzw[0]);
|
||||
result.fxyzw[1] = fsqrt(_a.fxyzw[1]);
|
||||
result.fxyzw[2] = fsqrt(_a.fxyzw[2]);
|
||||
result.fxyzw[3] = fsqrt(_a.fxyzw[3]);
|
||||
result.fxyzw[0] = sqrt(_a.fxyzw[0]);
|
||||
result.fxyzw[1] = sqrt(_a.fxyzw[1]);
|
||||
result.fxyzw[2] = sqrt(_a.fxyzw[2]);
|
||||
result.fxyzw[3] = sqrt(_a.fxyzw[3]);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -375,10 +375,10 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf);
|
||||
BX_SIMD_FORCE_INLINE simd128_ref_t simd_rsqrt_est(simd128_ref_t _a)
|
||||
{
|
||||
simd128_ref_t result;
|
||||
result.fxyzw[0] = 1.0f / fsqrt(_a.fxyzw[0]);
|
||||
result.fxyzw[1] = 1.0f / fsqrt(_a.fxyzw[1]);
|
||||
result.fxyzw[2] = 1.0f / fsqrt(_a.fxyzw[2]);
|
||||
result.fxyzw[3] = 1.0f / fsqrt(_a.fxyzw[3]);
|
||||
result.fxyzw[0] = rsqrt(_a.fxyzw[0]);
|
||||
result.fxyzw[1] = rsqrt(_a.fxyzw[1]);
|
||||
result.fxyzw[2] = rsqrt(_a.fxyzw[2]);
|
||||
result.fxyzw[3] = rsqrt(_a.fxyzw[3]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,98 +84,98 @@ namespace bx
|
||||
bool isInfinite(double _f);
|
||||
|
||||
///
|
||||
float ffloor(float _f);
|
||||
float floor(float _f);
|
||||
|
||||
///
|
||||
float fceil(float _f);
|
||||
float ceil(float _f);
|
||||
|
||||
///
|
||||
float fround(float _f);
|
||||
float round(float _f);
|
||||
|
||||
///
|
||||
float flerp(float _a, float _b, float _t);
|
||||
float lerp(float _a, float _b, float _t);
|
||||
|
||||
///
|
||||
float fsign(float _a);
|
||||
float sign(float _a);
|
||||
|
||||
///
|
||||
float fabs(float _a);
|
||||
float abs(float _a);
|
||||
|
||||
///
|
||||
float fsq(float _a);
|
||||
float square(float _a);
|
||||
|
||||
///
|
||||
float fsin(float _a);
|
||||
float sin(float _a);
|
||||
|
||||
///
|
||||
float fasin(float _a);
|
||||
float asin(float _a);
|
||||
|
||||
///
|
||||
float fcos(float _a);
|
||||
float cos(float _a);
|
||||
|
||||
///
|
||||
float ftan(float _a);
|
||||
float tan(float _a);
|
||||
|
||||
///
|
||||
float facos(float _a);
|
||||
float acos(float _a);
|
||||
|
||||
///
|
||||
float fatan2(float _y, float _x);
|
||||
float atan2(float _y, float _x);
|
||||
|
||||
///
|
||||
float fpow(float _a, float _b);
|
||||
float pow(float _a, float _b);
|
||||
|
||||
///
|
||||
float fexp2(float _a);
|
||||
float exp2(float _a);
|
||||
|
||||
///
|
||||
float flog(float _a);
|
||||
float log(float _a);
|
||||
|
||||
///
|
||||
float flog2(float _a);
|
||||
float log2(float _a);
|
||||
|
||||
///
|
||||
float fsqrt(float _a);
|
||||
float sqrt(float _a);
|
||||
|
||||
///
|
||||
float frsqrt(float _a);
|
||||
float rsqrt(float _a);
|
||||
|
||||
///
|
||||
float ftrunc(float _a);
|
||||
float trunc(float _a);
|
||||
|
||||
///
|
||||
float ffract(float _a);
|
||||
float fract(float _a);
|
||||
|
||||
///
|
||||
float fmod(float _a, float _b);
|
||||
float mod(float _a, float _b);
|
||||
|
||||
///
|
||||
bool fequal(float _a, float _b, float _epsilon);
|
||||
bool equal(float _a, float _b, float _epsilon);
|
||||
|
||||
///
|
||||
bool fequal(const float* _a, const float* _b, uint32_t _num, float _epsilon);
|
||||
bool equal(const float* _a, const float* _b, uint32_t _num, float _epsilon);
|
||||
|
||||
///
|
||||
float fwrap(float _a, float _wrap);
|
||||
float wrap(float _a, float _wrap);
|
||||
|
||||
///
|
||||
float fstep(float _edge, float _a);
|
||||
float step(float _edge, float _a);
|
||||
|
||||
///
|
||||
float fpulse(float _a, float _start, float _end);
|
||||
float pulse(float _a, float _start, float _end);
|
||||
|
||||
///
|
||||
float fsmoothstep(float _a);
|
||||
float smoothStep(float _a);
|
||||
|
||||
// References:
|
||||
// - Bias And Gain Are Your Friend
|
||||
// http://blog.demofox.org/2012/09/24/bias-and-gain-are-your-friend/
|
||||
// - http://demofox.org/biasgain.html
|
||||
///
|
||||
float fbias(float _time, float _bias);
|
||||
float bias(float _time, float _bias);
|
||||
|
||||
///
|
||||
float fgain(float _time, float _gain);
|
||||
float gain(float _time, float _gain);
|
||||
|
||||
///
|
||||
float angleDiff(float _a, float _b);
|
||||
|
||||
Reference in New Issue
Block a user