23 constexpr
static float value = 1.e-6f;
27 constexpr
static double value = 1.e-12f;
47 float x2 = float(f) * 0.5f;
49 memcpy(&i, &y,
sizeof(
float));
50 i = 0x5f3759df - (i >> 1);
51 memcpy(&y, &i,
sizeof(
float));
52 return y * (1.5f - (x2 * y * y));
73 return n >= 1 && (n & (n - 1)) == 0;
90 return (i % n + n) % n;
161 return 1._f / (v * v);
165 return 1._f / (v * v * v);
221 template <
typename T>
230 SPH_ASSERT(value > 0._f && power > 0._f, value, power);
238 u.x[1] = (int)(power * (u.x[1] - 1072632447) + 1072632447);
247 SPH_ASSERT(value > 0._f && power > 0._f, value, power);
254 u.x[1] = (int)((power - e) * (u.x[1] - 1072632447) + 1072632447);
268 template <
typename T>
275 template <
typename T>
282 return int(::
abs(f));
290 template <
typename T>
295 template <
typename T>
300 template <
typename T>
305 template <
typename T>
310 template <
typename T>
315 template <
typename T>
320 template <
typename T>
325 template <
typename T>
330 template <
typename T>
335 template <
typename T>
337 return (T(0) < val) - (val < T(0));
340 template <
typename T,
typename TAmount>
341 INLINE T
lerp(
const T v1,
const T v2,
const TAmount amount) {
342 return v1 * (TAmount(1) - amount) + v2 * amount;
345 template <
typename T>
350 template <
typename T>
355 template <
typename T>
361 constexpr
Float PI = 3.14159265358979323846264338327950288419716939937510582097_f;
365 constexpr
Float E = 2.718281828459045235360287471352662497757247093699959574967_f;
367 constexpr
Float SQRT_3 = 1.732050807568877293527446341505872366942805253810380628055_f;
387 return abs(f1 - f2) <= eps * (1._f +
max(
abs(f1),
abs(f2)));
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T max(const T &f1, const T &f2)
INLINE Float root(const Float f)
constexpr INLINE Float pow< 5 >(const Float v)
INLINE T sqrtApprox(const T f)
Returns an approximative value of square root.
INLINE int positiveMod(const int i, const int n)
Returns a positive modulo value.
INLINE T lerp(const T v1, const T v2, const TAmount amount)
INLINE Float root< 1 >(const Float f)
INLINE Float root< 4 >(const Float f)
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE Float powFastest(const Float value, const Float power)
INLINE Float cbrt(const Float f)
Returns a cubed root of a value.
INLINE auto floor(const T &f)
INLINE T sqrt(const T f)
Return a squared root of a value.
constexpr INLINE Float pow< 3 >(const Float v)
constexpr INLINE bool isPower2(const Size n) noexcept
Returns true if given n is a power of 2. N must at least 1.
constexpr INLINE Float pow< 4 >(const Float v)
constexpr INLINE Float pow(const Float v)
Power for floats.
INLINE int sgn(const T val)
constexpr INLINE Float sphereVolume(const Float radius)
Computes a volume of a sphere given its radius.
constexpr Float DEG_TO_RAD
INLINE bool almostEqual(const Float &f1, const Float &f2, const Float &eps=EPS)
INLINE T log10(const T f)
INLINE Float root< 2 >(const Float f)
INLINE auto round(const T &f)
constexpr INLINE Float pow< 6 >(const Float v)
INLINE Float root< 3 >(const Float f)
constexpr INLINE Float pow< 2 >(const Float v)
INLINE T sqrtInv(const T &f)
constexpr INLINE Float pow< 0 >(const Float)
constexpr INLINE Float sphereSurfaceArea(const Float radius)
Computes a surface area of a sphere given its radius.
constexpr INLINE Float pow< 7 >(const Float v)
INLINE T atan2(const T y, const T x)
INLINE T exp10(const T f)
INLINE Float powFast(Float value, const Float power)
INLINE auto ceil(const T &f)
constexpr INLINE Float pow< 8 >(const Float v)
INLINE auto abs(const T &f)
constexpr INLINE Float pow< 1 >(const Float v)
constexpr Float RAD_TO_DEG
constexpr Float PI
Mathematical constants.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Small value (compared with 1) for given precision.