SPH
|
Additional math routines (with more includes). More...
#include "common/Assert.h"
#include "math/MathBasic.h"
#include <cmath>
#include <cstring>
#include <limits>
#include <utility>
Go to the source code of this file.
Classes | |
struct | Eps< float > |
struct | Eps< double > |
Functions | |
template<typename T > | |
INLINE T | sqrtInv (const T &f) |
template<typename T > | |
INLINE T | sqrtApprox (const T f) |
Returns an approximative value of square root. More... | |
template<typename T > | |
constexpr INLINE T | sqr (const T &f) noexcept |
Return a squared value. More... | |
constexpr INLINE bool | isPower2 (const Size n) noexcept |
Returns true if given n is a power of 2. N must at least 1. More... | |
template<typename T > | |
INLINE T | sqrt (const T f) |
Return a squared root of a value. More... | |
INLINE Float | cbrt (const Float f) |
Returns a cubed root of a value. More... | |
INLINE int | positiveMod (const int i, const int n) |
Returns a positive modulo value. More... | |
template<int N> | |
INLINE Float | root (const Float f) |
template<> | |
INLINE Float | root< 1 > (const Float f) |
template<> | |
INLINE Float | root< 2 > (const Float f) |
template<> | |
INLINE Float | root< 3 > (const Float f) |
template<> | |
INLINE Float | root< 4 > (const Float f) |
template<int N> | |
constexpr INLINE Float | pow (const Float v) |
Power for floats. More... | |
template<> | |
constexpr INLINE Float | pow< 0 > (const Float) |
template<> | |
constexpr INLINE Float | pow< 1 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 2 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 3 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 4 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 5 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 6 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 7 > (const Float v) |
template<> | |
constexpr INLINE Float | pow< 8 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-1 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-2 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-3 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-4 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-5 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-8 > (const Float v) |
template<> | |
constexpr INLINE Float | pow<-16 > (const Float v) |
template<int N> | |
constexpr INLINE Size | pow (const Size v) |
Power for ints. More... | |
template<> | |
constexpr INLINE Size | pow< 0 > (const Size) |
template<> | |
constexpr INLINE Size | pow< 1 > (const Size v) |
template<> | |
constexpr INLINE Size | pow< 2 > (const Size v) |
template<> | |
constexpr INLINE Size | pow< 3 > (const Size v) |
template<> | |
constexpr INLINE Size | pow< 4 > (const Size v) |
template<> | |
constexpr INLINE Size | pow< 5 > (const Size v) |
template<> | |
constexpr INLINE Size | pow< 6 > (const Size v) |
template<typename T > | |
INLINE T | pow (const T value, const T power) |
Mathematical functions. More... | |
INLINE Float | powFastest (const Float value, const Float power) |
INLINE Float | powFast (Float value, const Float power) |
template<typename T > | |
INLINE T | exp (const T f) |
template<typename T > | |
INLINE auto | abs (const T &f) |
template<> | |
INLINE auto | abs (const int &f) |
template<> | |
INLINE auto | abs (const Size &f) |
template<typename T > | |
INLINE T | cos (const T f) |
template<typename T > | |
INLINE T | sin (const T f) |
template<typename T > | |
INLINE T | tan (const T f) |
template<typename T > | |
INLINE T | acos (const T f) |
template<typename T > | |
INLINE T | asin (const T f) |
template<typename T > | |
INLINE T | atan (const T f) |
template<typename T > | |
INLINE T | atan2 (const T y, const T x) |
template<typename T > | |
INLINE T | exp10 (const T f) |
template<typename T > | |
INLINE T | log10 (const T f) |
template<typename T > | |
INLINE int | sgn (const T val) |
template<typename T , typename TAmount > | |
INLINE T | lerp (const T v1, const T v2, const TAmount amount) |
template<typename T > | |
INLINE auto | floor (const T &f) |
template<typename T > | |
INLINE auto | ceil (const T &f) |
template<typename T > | |
INLINE auto | round (const T &f) |
constexpr INLINE Float | sphereVolume (const Float radius) |
Computes a volume of a sphere given its radius. More... | |
constexpr INLINE Float | sphereSurfaceArea (const Float radius) |
Computes a surface area of a sphere given its radius. More... | |
INLINE bool | almostEqual (const Float &f1, const Float &f2, const Float &eps=EPS) |
Variables | |
constexpr Float | EPS = Eps<Float>::value |
constexpr Float | LARGE = 1.e20f |
constexpr Float | INFTY = std::numeric_limits<Float>::max() |
constexpr Float | PI = 3.14159265358979323846264338327950288419716939937510582097_f |
Mathematical constants. More... | |
constexpr Float | PI_INV = 1._f / PI |
constexpr Float | E = 2.718281828459045235360287471352662497757247093699959574967_f |
constexpr Float | SQRT_3 = 1.732050807568877293527446341505872366942805253810380628055_f |
constexpr Float | DEG_TO_RAD = PI / 180._f |
constexpr Float | RAD_TO_DEG = 180._f / PI |
INLINE auto abs | ( | const int & | f | ) |
Definition at line 281 of file MathUtils.h.
Definition at line 286 of file MathUtils.h.
INLINE auto abs | ( | const T & | f | ) |
Computes absolute value.
Definition at line 276 of file MathUtils.h.
INLINE T acos | ( | const T | f | ) |
Definition at line 306 of file MathUtils.h.
Checks if two values are equal to some given accuracy.
Definition at line 386 of file MathUtils.h.
INLINE T asin | ( | const T | f | ) |
Definition at line 311 of file MathUtils.h.
INLINE T atan | ( | const T | f | ) |
Definition at line 316 of file MathUtils.h.
INLINE T atan2 | ( | const T | y, |
const T | x | ||
) |
Definition at line 321 of file MathUtils.h.
Returns a cubed root of a value.
Definition at line 84 of file MathUtils.h.
INLINE auto ceil | ( | const T & | f | ) |
Definition at line 351 of file MathUtils.h.
INLINE T cos | ( | const T | f | ) |
Definition at line 291 of file MathUtils.h.
INLINE T exp | ( | const T | f | ) |
Definition at line 269 of file MathUtils.h.
INLINE T exp10 | ( | const T | f | ) |
Definition at line 326 of file MathUtils.h.
INLINE auto floor | ( | const T & | f | ) |
Definition at line 346 of file MathUtils.h.
Returns true if given n is a power of 2. N must at least 1.
Definition at line 72 of file MathUtils.h.
INLINE T lerp | ( | const T | v1, |
const T | v2, | ||
const TAmount | amount | ||
) |
Definition at line 341 of file MathUtils.h.
INLINE T log10 | ( | const T | f | ) |
Definition at line 331 of file MathUtils.h.
INLINE int positiveMod | ( | const int | i, |
const int | n | ||
) |
Returns a positive modulo value.
Definition at line 89 of file MathUtils.h.
INLINE T pow | ( | const T | value, |
const T | power | ||
) |
Mathematical functions.
Definition at line 222 of file MathUtils.h.
Definition at line 120 of file MathUtils.h.
Definition at line 190 of file MathUtils.h.
Definition at line 124 of file MathUtils.h.
Definition at line 194 of file MathUtils.h.
Definition at line 128 of file MathUtils.h.
Definition at line 198 of file MathUtils.h.
Definition at line 132 of file MathUtils.h.
Definition at line 202 of file MathUtils.h.
Definition at line 136 of file MathUtils.h.
Definition at line 206 of file MathUtils.h.
Definition at line 140 of file MathUtils.h.
Definition at line 210 of file MathUtils.h.
Definition at line 144 of file MathUtils.h.
Definition at line 214 of file MathUtils.h.
Definition at line 148 of file MathUtils.h.
Definition at line 152 of file MathUtils.h.
Definition at line 156 of file MathUtils.h.
Definition at line 180 of file MathUtils.h.
Definition at line 160 of file MathUtils.h.
Definition at line 164 of file MathUtils.h.
Definition at line 168 of file MathUtils.h.
Definition at line 172 of file MathUtils.h.
Definition at line 176 of file MathUtils.h.
Approximative version of pow function, slightly more precise than powFastest.
Expected error is about 2 %. Works only for positive values and positive powers.
Definition at line 246 of file MathUtils.h.
Approximative version of pow function.
Expected error is about 5 %. Works only for positive values and positive powers.
Definition at line 229 of file MathUtils.h.
Definition at line 109 of file MathUtils.h.
INLINE auto round | ( | const T & | f | ) |
Definition at line 356 of file MathUtils.h.
INLINE int sgn | ( | const T | val | ) |
Definition at line 336 of file MathUtils.h.
INLINE T sin | ( | const T | f | ) |
Definition at line 296 of file MathUtils.h.
Computes a surface area of a sphere given its radius.
Definition at line 380 of file MathUtils.h.
Computes a volume of a sphere given its radius.
Definition at line 375 of file MathUtils.h.
|
constexprnoexcept |
Return a squared value.
Definition at line 67 of file MathUtils.h.
INLINE T sqrt | ( | const T | f | ) |
Return a squared root of a value.
Definition at line 78 of file MathUtils.h.
INLINE T sqrtApprox | ( | const T | f | ) |
Returns an approximative value of square root.
Definition at line 57 of file MathUtils.h.
INLINE T sqrtInv | ( | const T & | f | ) |
Returns an approximate value of inverse square root.
Iters | Number of iterations of the algorithm. Higher value = more accurate result. |
Definition at line 44 of file MathUtils.h.
INLINE T tan | ( | const T | f | ) |
Definition at line 301 of file MathUtils.h.
Definition at line 369 of file MathUtils.h.
|
constexpr |
Definition at line 365 of file MathUtils.h.
Definition at line 30 of file MathUtils.h.
Largest value representable by float/double. Any increase (multiplication by 2, for example) will cause float overflow! Use carefully, maily for comparisons.
Definition at line 38 of file MathUtils.h.
|
constexpr |
Large value (compared with 1). It's safe to do basic arithmetic operations (multiply by 2, for example) without worying about float overflow.
Definition at line 34 of file MathUtils.h.
|
constexpr |
Mathematical constants.
Definition at line 361 of file MathUtils.h.
Definition at line 363 of file MathUtils.h.
Definition at line 371 of file MathUtils.h.
|
constexpr |
Definition at line 367 of file MathUtils.h.