Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::Calc Struct Reference

#include <Calc.h>

Inheritance diagram for GrayLib::Calc:
GrayLib::CalcI Gray::cTypeFloat

Public Member Functions

 UNITTEST_FRIEND (Calc)
 

Static Public Member Functions

template<typename TYPE >
static bool IsSignDiff (TYPE a, TYPE b) noexcept
 
template<typename TYPE >
static TYPE WrapRadians (TYPE nRadians) noexcept
 
template<typename TYPE >
static TYPE WrapRadiansSigned (TYPE nRadians) noexcept
 
template<typename TYPE >
static TYPE GetDiffRadians (TYPE n1, TYPE n2) noexcept
 
template<typename TYPE >
static TYPE Degree2Radian (TYPE nDegree) noexcept
 
template<typename TYPE >
static TYPE Radian2Degree (TYPE nRadians) noexcept
 
template<typename TYPE >
static TYPE Lerp (TYPE nVal1, TYPE nVal2, TYPE fRatio) noexcept
 
template<typename TYPE >
static TYPE Round (TYPE a)
 
template<typename TYPE >
static bool IsInteger (TYPE a)
 
template<typename TYPE >
static TYPE Floor (TYPE a)
 get the closest whole integer. positive or negative values. More...
 
template<typename TYPE >
static TYPE Ceil (TYPE a)
 
template<typename TYPE >
static TYPE Sqrt (TYPE a)
 
template<typename TYPE >
static TYPE Sin (TYPE a)
 
template<typename TYPE >
static TYPE Cos (TYPE a)
 
template<typename TYPE >
static TYPE Tan (TYPE a)
 
template<typename TYPE >
static void SinCos (TYPE a, TYPE &s, TYPE &c)
 get both sin and cos at one time. a = Euler angle in radians More...
 
template<typename TYPE >
static TYPE ASin (TYPE a)
 
template<typename TYPE >
static TYPE ACos (TYPE a)
 
template<typename TYPE >
static TYPE ATan (TYPE a)
 
template<typename TYPE >
static TYPE ATan2 (TYPE y, TYPE x)
 
template<typename TYPE >
static TYPE Exp (TYPE a)
 
template<typename TYPE >
static TYPE Log (TYPE a)
 Natural (e) log. // negative will throw ? More...
 
template<typename TYPE >
static TYPE Pow (TYPE nBase, TYPE nExp)
 pow(nBase,nExp) = exp( log(nBase) * nExp ); More...
 
template<typename TYPE >
static TYPE Pow10 (TYPE x)
 
template<typename TYPE >
static TYPE Pow2 (TYPE x)
 
template<typename TYPE >
static TYPE Log10 (TYPE a)
 
template<typename TYPE >
static TYPE Log2 (TYPE a)
 
template<typename TYPE >
static TYPE LogN (TYPE x, TYPE b=10)
 
template<>
float Floor (float a)
 
template<>
float Ceil (float a)
 
template<>
float Sqrt (float a)
 
template<>
float Sin (float a)
 
template<>
float Cos (float a)
 
template<>
float Tan (float a)
 
template<>
void SinCos (float a, float &s, float &c)
 
template<>
float ASin (float a)
 
template<>
float ACos (float a)
 
template<>
float ATan (float a)
 
template<>
float ATan2 (float y, float x)
 
template<>
float Log (float a)
 
template<>
float Log10 (float a)
 
template<>
float Exp (float a)
 
template<>
float Pow (float a, float nExp)
 
template<>
double Floor (double a)
 
template<>
double Ceil (double a)
 
template<>
double Sqrt (double a)
 
template<>
double Sin (double a)
 
template<>
double Cos (double a)
 
template<>
double Tan (double a)
 
template<>
void SinCos (double a, double &s, double &c)
 
template<>
double ASin (double a)
 
template<>
double ACos (double a)
 
template<>
double ATan (double a)
 
template<>
double ATan2 (double y, double x)
 
template<>
double Log (double a)
 
template<>
double Log10 (double a)
 
template<>
double Exp (double a)
 
template<>
double Pow (double a, double nExp)
 
- Static Public Member Functions inherited from GrayLib::CalcI
template<typename TYPE >
static int Sign (TYPE a)
 
template<typename TYPE >
static bool IsInRange (TYPE n, TYPE low, TYPE high) noexcept
 
template<typename TYPE >
static bool IsInBetween (TYPE n, TYPE a, TYPE b) noexcept
 
template<typename TYPE >
static TYPE Min (TYPE a, TYPE b) noexcept
 
template<typename TYPE >
static TYPE Max (TYPE a, TYPE b) noexcept
 
template<typename TYPE >
static TYPE Max3 (TYPE a, TYPE b, TYPE c) noexcept
 
template<typename TYPE >
static TYPE Clamp (TYPE value, TYPE low, TYPE high)
 
template<typename TYPE >
static void ClampRef (TYPE &rValue, TYPE low, TYPE high)
 
template<typename TYPE >
static bool IsNear (TYPE n1, TYPE n2, TYPE nDiff=(TYPE) k_FLT_MIN2) noexcept
 
template<typename TYPE >
static TYPE Sqr (TYPE a) noexcept
 
template<typename TYPE >
static TYPE Abs (TYPE a) noexcept
 similar to ABS(n) macro. Does nothing for unsigned types. More...
 
template<typename TYPE >
static TYPE Mod (TYPE a, TYPE b)
 a modulus b = remainder of a/b More...
 
template<typename TYPE >
static TYPE Wrap (TYPE nVal, TYPE nMod)
 
static bool IsSignDiff (int a, int b) noexcept
 
template<typename TYPE >
static TYPE GetGreatestCommonDivisor (TYPE x, TYPE y)
 
template<typename TYPE >
static TYPE MulDiv (TYPE a, TYPE b, TYPE c)
 
template<typename TYPE >
static TYPE DivideUp (TYPE a, TYPE b)
 
template<typename TYPE >
static TYPE AddC (TYPE a, TYPE b, bool &bCarry) noexcept
 
template<typename TYPE >
static TYPE SubC (TYPE a, TYPE b, bool &bBorrow) noexcept
 
template<typename TYPE >
static bool ToBool (TYPE nVal) noexcept
 
static int GRAYCALL Log2Est (UINT iVal)
 
static Percent10_t GRAYCALL GetSCurve (int iValDiff, int iValVarianceHalf)
 
static Percent10_t GRAYCALL GetBellCurve (int iValDiff, int iValVarianceHalf)
 
template<>
float Abs (float a) noexcept
 
template<>
float Mod (float a, float b)
 
template<>
double Abs (double a) noexcept
 
template<>
double Mod (double a, double b)
 
template<>
int Abs (int a) noexcept
 
template<>
int Mod (int a, int b)
 
template<>
UINT Abs (UINT a) noexcept
 
template<>
UINT Mod (UINT a, UINT b)
 
template<>
UINT16 MulDiv (UINT16 a, UINT16 b, UINT16 c)
 
- Static Public Member Functions inherited from Gray::cTypeFloat
template<typename TYPE >
static bool IsNaN (TYPE a) noexcept
 
template<typename TYPE >
static bool IsInfinite (TYPE a)
 
template<typename TYPE >
static bool IsFinite (TYPE a) noexcept
 

Detailed Description

math templates that only work for float/double types.

Note
use of template/namespace Math<> would conflict with System.Math in M$ CLR bool IsPostive() IsNegative() ?
see js_fdlibm for more source for math primitives. sin,cos,ln,etc.

Member Function Documentation

◆ ACos() [1/3]

template<>
double GrayLib::Calc::ACos ( double  a)
inlinestatic

◆ ACos() [2/3]

template<>
float GrayLib::Calc::ACos ( float  a)
inlinestatic

◆ ACos() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::ACos ( TYPE  a)
inlinestatic

◆ ASin() [1/3]

template<>
double GrayLib::Calc::ASin ( double  a)
inlinestatic

◆ ASin() [2/3]

template<>
float GrayLib::Calc::ASin ( float  a)
inlinestatic

◆ ASin() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::ASin ( TYPE  a)
inlinestatic

◆ ATan() [1/3]

template<>
double GrayLib::Calc::ATan ( double  a)
inlinestatic

◆ ATan() [2/3]

template<>
float GrayLib::Calc::ATan ( float  a)
inlinestatic

◆ ATan() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::ATan ( TYPE  a)
inlinestatic

◆ ATan2() [1/3]

template<>
double GrayLib::Calc::ATan2 ( double  y,
double  x 
)
inlinestatic

◆ ATan2() [2/3]

template<>
float GrayLib::Calc::ATan2 ( float  y,
float  x 
)
inlinestatic

◆ ATan2() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::ATan2 ( TYPE  y,
TYPE  x 
)
inlinestatic

◆ Ceil() [1/3]

template<>
double GrayLib::Calc::Ceil ( double  a)
inlinestatic

◆ Ceil() [2/3]

template<>
float GrayLib::Calc::Ceil ( float  a)
inlinestatic

◆ Ceil() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Ceil ( TYPE  a)
inlinestatic

◆ Cos() [1/3]

template<>
double GrayLib::Calc::Cos ( double  a)
inlinestatic

◆ Cos() [2/3]

template<>
float GrayLib::Calc::Cos ( float  a)
inlinestatic

◆ Cos() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Cos ( TYPE  a)
inlinestatic

◆ Degree2Radian()

template<typename TYPE >
static TYPE GrayLib::Calc::Degree2Radian ( TYPE  nDegree)
inlinestaticnoexcept

Convert Euler degrees to radians. RADIANf_t

◆ Exp() [1/3]

template<>
double GrayLib::Calc::Exp ( double  a)
inlinestatic

◆ Exp() [2/3]

template<>
float GrayLib::Calc::Exp ( float  a)
inlinestatic

◆ Exp() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Exp ( TYPE  a)
inlinestatic

◆ Floor() [1/3]

template<>
double GrayLib::Calc::Floor ( double  a)
inlinestatic

◆ Floor() [2/3]

template<>
float GrayLib::Calc::Floor ( float  a)
inlinestatic

◆ Floor() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Floor ( TYPE  a)
inlinestatic

get the closest whole integer. positive or negative values.

◆ GetDiffRadians()

template<typename TYPE >
static TYPE GrayLib::Calc::GetDiffRadians ( TYPE  n1,
TYPE  n2 
)
inlinestaticnoexcept

get the diff between 2 angles. allow wrapping. return smaller Abs value. -PI..+PI range. usual TYPE = RADIANf_t

◆ IsInteger()

template<typename TYPE >
static bool GrayLib::Calc::IsInteger ( TYPE  a)
inlinestatic

Is this a whole number/Integer?

◆ IsSignDiff()

template<typename TYPE >
static bool GrayLib::Calc::IsSignDiff ( TYPE  a,
TYPE  b 
)
inlinestaticnoexcept

is the sign diff ? override the CalcI version above.

◆ Lerp()

template<typename TYPE >
static TYPE GrayLib::Calc::Lerp ( TYPE  nVal1,
TYPE  nVal2,
TYPE  fRatio 
)
inlinestaticnoexcept

linear interpolation from nVal1 to nVal2 fRatio = 0 to 1

◆ Log() [1/3]

template<>
double GrayLib::Calc::Log ( double  a)
inlinestatic

◆ Log() [2/3]

template<>
float GrayLib::Calc::Log ( float  a)
inlinestatic

◆ Log() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Log ( TYPE  a)
inlinestatic

Natural (e) log. // negative will throw ?

◆ Log10() [1/3]

template<>
double GrayLib::Calc::Log10 ( double  a)
inlinestatic

◆ Log10() [2/3]

template<>
float GrayLib::Calc::Log10 ( float  a)
inlinestatic

◆ Log10() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Log10 ( TYPE  a)
inlinestatic
Note
log10(x) = Log(x) / Log(10) = Log(x) * k_Log10e = Log(x) / k_Ln10

◆ Log2()

template<typename TYPE >
static TYPE GrayLib::Calc::Log2 ( TYPE  a)
inlinestatic

◆ LogN()

template<typename TYPE >
static TYPE GrayLib::Calc::LogN ( TYPE  x,
TYPE  b = 10 
)
inlinestatic

Get an arbitrary log base. e.g. log2(x)

◆ Pow() [1/3]

template<>
double GrayLib::Calc::Pow ( double  a,
double  nExp 
)
inlinestatic

◆ Pow() [2/3]

template<>
float GrayLib::Calc::Pow ( float  a,
float  nExp 
)
inlinestatic

◆ Pow() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Pow ( TYPE  nBase,
TYPE  nExp 
)
inlinestatic

pow(nBase,nExp) = exp( log(nBase) * nExp );

nBase raises to the power of nExp

◆ Pow10()

template<typename TYPE >
static TYPE GrayLib::Calc::Pow10 ( TYPE  x)
inlinestatic

Get a 10 to the power of x = Pow(10,x)

◆ Pow2()

template<typename TYPE >
static TYPE GrayLib::Calc::Pow2 ( TYPE  x)
inlinestatic

Get a 2 to the power of x = Pow(2,x)

◆ Radian2Degree()

template<typename TYPE >
static TYPE GrayLib::Calc::Radian2Degree ( TYPE  nRadians)
inlinestaticnoexcept

Convert Euler radians to degrees. RADIANf_t

◆ Round()

template<typename TYPE >
static TYPE GrayLib::Calc::Round ( TYPE  a)
inlinestatic

round a TYPE to nearest whole number/Integer.

◆ Sin() [1/3]

template<>
double GrayLib::Calc::Sin ( double  a)
inlinestatic

◆ Sin() [2/3]

template<>
float GrayLib::Calc::Sin ( float  a)
inlinestatic

◆ Sin() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Sin ( TYPE  a)
inlinestatic

◆ SinCos() [1/3]

template<>
void GrayLib::Calc::SinCos ( double  a,
double &  s,
double &  c 
)
inlinestatic

Get both Sin and Cos for an angle.

  • a = Euler angle in radians

◆ SinCos() [2/3]

template<>
void GrayLib::Calc::SinCos ( float  a,
float &  s,
float &  c 
)
inlinestatic

Get both Sin and Cos for an angle.

  • a = Euler angle in radians. RADIANf_t

◆ SinCos() [3/3]

template<typename TYPE >
static void GrayLib::Calc::SinCos ( TYPE  a,
TYPE s,
TYPE c 
)
inlinestatic

get both sin and cos at one time. a = Euler angle in radians

◆ Sqrt() [1/3]

template<>
double GrayLib::Calc::Sqrt ( double  a)
inlinestatic

◆ Sqrt() [2/3]

template<>
float GrayLib::Calc::Sqrt ( float  a)
inlinestatic

◆ Sqrt() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Sqrt ( TYPE  a)
inlinestatic

◆ Tan() [1/3]

template<>
double GrayLib::Calc::Tan ( double  a)
inlinestatic

◆ Tan() [2/3]

template<>
float GrayLib::Calc::Tan ( float  a)
inlinestatic

◆ Tan() [3/3]

template<typename TYPE >
static TYPE GrayLib::Calc::Tan ( TYPE  a)
inlinestatic

◆ UNITTEST_FRIEND()

GrayLib::Calc::UNITTEST_FRIEND ( Calc  )

◆ WrapRadians()

template<typename TYPE >
static TYPE GrayLib::Calc::WrapRadians ( TYPE  nRadians)
inlinestaticnoexcept

Convert Euler radians to positive/unsigned range < PI2. usual TYPE = RADIANf_t

Returns
positive value from 0 to < PI2

converts to 0..PI2 range

◆ WrapRadiansSigned()

template<typename TYPE >
static TYPE GrayLib::Calc::WrapRadiansSigned ( TYPE  nRadians)
inlinestaticnoexcept

converts to signed -PI..+PI range, good for delta angles. NOT fmod() for negative values ! usual TYPE = RADIANf_t


The documentation for this struct was generated from the following file: