sta-peak/src/utils.cpp

43 lines
592 B
C++

#include <sta/math/utils.hpp>
#include <cstdint>
namespace sta
{
namespace math
{
float fast_inv_sqrt(float v) {
long i;
float x2, y;
const float threehalfs = 1.5f;
y = v;
x2 = y * 0.5f;
i = * (long*)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *) &i;
y = y * (threehalfs - (x2 * y * y));
//y = y * (threehalfs - (x2 * y * y));
return y;
}
float clip(float value, float min, float max)
{
if (value < min)
{
return min;
}
if (value > max)
{
return max;
}
return value;
}
} // namespace math
} // namespace sta