mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-peak.git
synced 2025-06-12 19:05:58 +00:00
43 lines
592 B
C++
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
|