Skip to content

Math

Approximate double comparison. More...

Functions

Name
FORCE_INLINE boolareElementsSame(const glm::vec3 vec)
FORCE_INLINE booleq(const float lhs, const float rhs, const float epsilon)<br>Comparison of two floats using epsilon, useful for comparison to zero and to one.
FORCE_INLINE booleq(const float lhs, const float rhs, const int factor =FACTOR_SIMILAR)<br>Comparison of two floats using factor * difference to nextafter() value, useful for comparison of two floats of unknown value.
FORCE_INLINE booleq(const glm::mat4 & lhs, const glm::mat4 & rhs, const float epsilon)
FORCE_INLINE booleq(const glm::mat4 & lhs, const glm::mat4 & rhs, const int factor =FACTOR_SIMILAR)
FORCE_INLINE booleq(const glm::quat & lhs, const glm::quat & rhs, const int factor =FACTOR_SIMILAR)
FORCE_INLINE booleq(const glm::vec3 & lhs, const glm::vec3 & rhs, const int factor =FACTOR_SIMILAR)
FORCE_INLINE booleq(const glm::vec4 & lhs, const glm::vec4 & rhs, const int factor =FACTOR_SIMILAR)
FORCE_INLINE booleqToOne(const float value, const float epsilon =FLT_EPSILON_FIVE_DECIMALS)
FORCE_INLINE booleqToZero(const float value, const float epsilon =FLT_EPSILON_FIVE_DECIMALS)
template <typename T &gt; <br>boolisNormalized(const T & val)
glm::mat4lerp(const glm::mat4 & lhs, const glm::mat4 & rhs, float alpha, bool useQuat =false)<br>Linear interpolation between two 4x4 matrices lhs and rhs including translation columns.
glm::vec3lerp(glm::vec3 a, glm::vec3 b, float alpha)<br>Linear interpolation between two vectors vec3 a and b.
glm::vec4lerp(glm::vec4 a, glm::vec4 b, float alpha)<br>Linear interpolation between two vectors vec4 a and b.
voidprefixSum(std::vector< int > & arr)
floatrandomf()<br>Random float from interval 0 .
floatrandomfHalf()<br>Random float from interval -0.5 .
intrandomi(const int downIncluded, const int topNotInclude)<br>Random integer from interval downIncluded .
intrandomi(const int topNotInclude)<br>Random integer from interval 0..topNotInclude.
glm::vec3randomVec()
floatrange(const float value, const float low1, const float high1, const float low2, const float high2)
floatsmoothAlpha(const float a)<br>Fifth order interpolation.
FORCE_INLINE boolwithinInterval(const float val, const float from, const float to)

Attributes

Name
constexpr intFACTOR_NEARLY_EQUAL <br>interval weight for comparison of nearly equal values
constexpr intFACTOR_ROUGHLY_SIMILAR <br>interval weight for comparison of very roughly similar values
constexpr intFACTOR_SIMILAR <br>interval weight for comparison of similar values
constexpr floatFLT_EPSILON_10 <br>1.192093 E-6
constexpr floatFLT_EPSILON_100 <br>1.192093 E-5
constexpr floatFLT_EPSILON_1000 <br>1.192093 E-4
constexpr floatFLT_EPSILON_FIVE_DECIMALS <br>simple interval (1.0 +- epsilon)

Detailed Description

Approximate double comparison.

Parameters:

  • a first double
  • b second double
  • factor a factor of epsilon

Return: true if the double values represent nearly the same value (precision interval is widened by factor)

Functions Documentation

function areElementsSame

cpp
FORCE_INLINE bool areElementsSame(
    const glm::vec3 vec
)
FORCE_INLINE bool areElementsSame(
    const glm::vec3 vec
)

function eq

cpp
FORCE_INLINE bool eq(
    const float lhs,
    const float rhs,
    const float epsilon
)
FORCE_INLINE bool eq(
    const float lhs,
    const float rhs,
    const float epsilon
)

Comparison of two floats using epsilon, useful for comparison to zero and to one.

Parameters:

  • lhs First value
  • rhs Second value
  • epsilon interval size - roughly defining the number of decimal places

Return: epsilon comparison

function eq

cpp
FORCE_INLINE bool eq(
    const float lhs,
    const float rhs,
    const int factor =FACTOR_SIMILAR
)
FORCE_INLINE bool eq(
    const float lhs,
    const float rhs,
    const int factor =FACTOR_SIMILAR
)

Comparison of two floats using factor * difference to nextafter() value, useful for comparison of two floats of unknown value.

Parameters:

  • lhs First value
  • rhs Second value
  • factor multiplies the distance to the nextafter() value used as a size of comparison interval

Return: factor based comparison

function eq

cpp
FORCE_INLINE bool eq(
    const glm::mat4 & lhs,
    const glm::mat4 & rhs,
    const float epsilon
)
FORCE_INLINE bool eq(
    const glm::mat4 & lhs,
    const glm::mat4 & rhs,
    const float epsilon
)

function eq

cpp
FORCE_INLINE bool eq(
    const glm::mat4 & lhs,
    const glm::mat4 & rhs,
    const int factor =FACTOR_SIMILAR
)
FORCE_INLINE bool eq(
    const glm::mat4 & lhs,
    const glm::mat4 & rhs,
    const int factor =FACTOR_SIMILAR
)

function eq

cpp
FORCE_INLINE bool eq(
    const glm::quat & lhs,
    const glm::quat & rhs,
    const int factor =FACTOR_SIMILAR
)
FORCE_INLINE bool eq(
    const glm::quat & lhs,
    const glm::quat & rhs,
    const int factor =FACTOR_SIMILAR
)

function eq

cpp
FORCE_INLINE bool eq(
    const glm::vec3 & lhs,
    const glm::vec3 & rhs,
    const int factor =FACTOR_SIMILAR
)
FORCE_INLINE bool eq(
    const glm::vec3 & lhs,
    const glm::vec3 & rhs,
    const int factor =FACTOR_SIMILAR
)

function eq

cpp
FORCE_INLINE bool eq(
    const glm::vec4 & lhs,
    const glm::vec4 & rhs,
    const int factor =FACTOR_SIMILAR
)
FORCE_INLINE bool eq(
    const glm::vec4 & lhs,
    const glm::vec4 & rhs,
    const int factor =FACTOR_SIMILAR
)

function eqToOne

cpp
FORCE_INLINE bool eqToOne(
    const float value,
    const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)
FORCE_INLINE bool eqToOne(
    const float value,
    const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)

function eqToZero

cpp
FORCE_INLINE bool eqToZero(
    const float value,
    const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)
FORCE_INLINE bool eqToZero(
    const float value,
    const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)

function isNormalized

cpp
template <typename T >
bool isNormalized(
    const T & val
)
template <typename T >
bool isNormalized(
    const T & val
)

function lerp

cpp
glm::mat4 lerp(
    const glm::mat4 & lhs,
    const glm::mat4 & rhs,
    float alpha,
    bool useQuat =false
)
glm::mat4 lerp(
    const glm::mat4 & lhs,
    const glm::mat4 & rhs,
    float alpha,
    bool useQuat =false
)

Linear interpolation between two 4x4 matrices lhs and rhs including translation columns.

Function depends on the parameter useQuat:

  • true - A correct interpolation of rotational matrices using quaternions
  • false - Incorrect interpolation, just for teaching purposes (how not to do it). lhsthe first matrix

rhsthe second matrix

alphainterpolation parameter - must be from interval (0..1) interpolation parameter - must be from interval (0..1)

useQuatuse quaternion interpolation, if true

linear interpolation of two matrices vectors [wrong for useQuat == false!]

function lerp

cpp
static glm::vec3 lerp(
    glm::vec3 a,
    glm::vec3 b,
    float alpha
)
static glm::vec3 lerp(
    glm::vec3 a,
    glm::vec3 b,
    float alpha
)

Linear interpolation between two vectors vec3 a and b.

Parameters:

  • a
  • b
  • alpha interpolation parameter - must be from interval (0..1)

Return: linear interpolation of two vec3 vectors

function lerp

cpp
static glm::vec4 lerp(
    glm::vec4 a,
    glm::vec4 b,
    float alpha
)
static glm::vec4 lerp(
    glm::vec4 a,
    glm::vec4 b,
    float alpha
)

Linear interpolation between two vectors vec4 a and b.

Parameters:

  • a the first vector
  • b the second vector
  • alpha interpolation parameter - must be from interval (0..1)

Return: linear interpolation of two vec4 vectors

function prefixSum

cpp
static void prefixSum(
    std::vector< int > & arr
)
static void prefixSum(
    std::vector< int > & arr
)

function randomf

cpp
static float randomf()
static float randomf()

Random float from interval 0 .

Return: random float

. 0.999

function randomfHalf

cpp
static float randomfHalf()
static float randomfHalf()

Random float from interval -0.5 .

Return: random float

. +0.499

function randomi

cpp
static int randomi(
    const int downIncluded,
    const int topNotInclude
)
static int randomi(
    const int downIncluded,
    const int topNotInclude
)

Random integer from interval downIncluded .

Parameters:

  • downIncluded [min generated value
  • topNotInclude max) generated value

Return: Random integer

. topNotInclude

function randomi

cpp
static int randomi(
    const int topNotInclude
)
static int randomi(
    const int topNotInclude
)

Random integer from interval 0..topNotInclude.

Parameters:

  • topNotInclude maximum value of the interval

Return: Random integer

function randomVec

cpp
static glm::vec3 randomVec()
static glm::vec3 randomVec()

function range

cpp
static float range(
    const float value,
    const float low1,
    const float high1,
    const float low2,
    const float high2
)
static float range(
    const float value,
    const float low1,
    const float high1,
    const float low2,
    const float high2
)

function smoothAlpha

cpp
static float smoothAlpha(
    const float a
)
static float smoothAlpha(
    const float a
)

Fifth order interpolation.

Parameters:

  • a alpha

Return: smoothed alpha

function withinInterval

cpp
FORCE_INLINE bool withinInterval(
    const float val,
    const float from,
    const float to
)
FORCE_INLINE bool withinInterval(
    const float val,
    const float from,
    const float to
)

Attributes Documentation

variable FACTOR_NEARLY_EQUAL

cpp
static constexpr int FACTOR_NEARLY_EQUAL = 0x01 << 8;
static constexpr int FACTOR_NEARLY_EQUAL = 0x01 << 8;

interval weight for comparison of nearly equal values

variable FACTOR_ROUGHLY_SIMILAR

cpp
static constexpr int FACTOR_ROUGHLY_SIMILAR = 0x01
                                              << 14;
static constexpr int FACTOR_ROUGHLY_SIMILAR = 0x01
                                              << 14;

interval weight for comparison of very roughly similar values

variable FACTOR_SIMILAR

cpp
static constexpr int FACTOR_SIMILAR = 0x01 << 12;
static constexpr int FACTOR_SIMILAR = 0x01 << 12;

interval weight for comparison of similar values

variable FLT_EPSILON_10

cpp
static constexpr float FLT_EPSILON_10 = 10.0f * FLT_EPSILON;
static constexpr float FLT_EPSILON_10 = 10.0f * FLT_EPSILON;

1.192093 E-6

variable FLT_EPSILON_100

cpp
static constexpr float FLT_EPSILON_100 = 100.0f * FLT_EPSILON;
static constexpr float FLT_EPSILON_100 = 100.0f * FLT_EPSILON;

1.192093 E-5

variable FLT_EPSILON_1000

cpp
static constexpr float FLT_EPSILON_1000 = 1000.0f * FLT_EPSILON;
static constexpr float FLT_EPSILON_1000 = 1000.0f * FLT_EPSILON;

1.192093 E-4

variable FLT_EPSILON_FIVE_DECIMALS

cpp
static constexpr float FLT_EPSILON_FIVE_DECIMALS = 0.00001f;
static constexpr float FLT_EPSILON_FIVE_DECIMALS = 0.00001f;

simple interval (1.0 +- epsilon)


Updated on 2024-03-16 at 19:15:01 +0000