v0.1.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Pages
CGUL::Math Namespace Reference

A namespace containing many common mathematical functions. More...

Functions

template<typename Type >
Type Abs (Type x)
 Calculates the absolute value of x. More...
 
template<typename Type >
Type Sign (Type x)
 Gets the sign of the value, returning -1, 0, or 1. More...
 
template<typename Type >
Type Cos (Type x)
 Calculates the cosine of x. More...
 
template<typename Type >
Type Sin (Type x)
 Calculates the sine of x. More...
 
template<typename Type >
Type Tan (Type x)
 Calculates the tangent of x. More...
 
template<typename Type >
Type Cosh (Type x)
 Calculates the hyperbolic cosine of x. More...
 
template<typename Type >
Type Sinh (Type x)
 Calculates the hyperbolic sine of x. More...
 
template<typename Type >
Type Tanh (Type x)
 Calculates the hyperbolic tangent of x. More...
 
template<typename Type >
Type ACos (Type x)
 Calculates the arc cosine of x. More...
 
template<typename Type >
Type ASin (Type x)
 Calculates the arc sine of x. More...
 
template<typename Type >
Type ATan (Type x)
 Calculates the arc tangent of x. More...
 
template<typename Type >
Type ATan2 (Type y, Type x)
 
template<typename Type >
Type DegToRad (Type deg)
 Converts degrees to radians. More...
 
template<typename Type >
Type RadToDeg (Type rad)
 Converts radians to degrees. More...
 
template<typename Type >
Type Ln (Type x)
 
template<typename Type >
Type Log (Type x, Type b=10)
 
template<typename Type >
Type Min (Type a, Type b)
 Finds the smaller of the two values. More...
 
template<typename Type >
Type Min (Type a, Type b, Type c)
 Finds the smaller of the three values. More...
 
template<typename Type >
Type Max (Type a, Type b)
 Finds the larger of the two values. More...
 
template<typename Type >
Type Max (Type a, Type b, Type c)
 Finds the larger of the three values. More...
 
template<typename Type >
Type Floor (Type x)
 Rounds the number down. More...
 
template<typename Type >
Type Round (Type x)
 Rounds the number. More...
 
template<typename Type >
Type Ceil (Type x)
 Rounds the number up. More...
 
template<typename Type >
Type Mod (Type x, Type div)
 A modulus function that works with floating point numbers. More...
 
template<typename Type >
Type Clamp (Type x, Type min, Type max)
 Clamps the value between a minimum and maximum range. More...
 
template<typename Type >
Type Sqr (Type x)
 Calculates the square of a number. More...
 
template<typename Type >
Type Sqrt (Type x)
 Calculates the square root of a number. More...
 
template<typename Type >
bool InEpsilon (Type value, Type compare, Type epsilon)
 Checks if two values are equal within a given epsilon. More...
 
template<typename Type >
Type Pow (Type x, Type y)
 Raises x to the power of y. More...
 
template<typename Type >
Type Exp (Type x)
 
bool IsPowerOfTwo (UInt32 x)
 Checks if the value is a power of two. More...
 
template<typename Type >
Type StandardDeviation (const FixedList< Type > &values, Type *mean=NULL)
 
template<typename Type >
Type Lerp (Type from, Type to, Type t)
 Performs linear interpolation.
 

Variables

const Float64 Zero = 0
 The constant Zero, defined as 0.
 
const Float64 One = 1
 The constant One, defined as 1.
 
const Float64 Unity = 1
 The constant Unity, defined as 1.
 
const Float64 E = 2.71828182845904523536028747135266249
 The constant E, Napier's constant, defined as 2.71828182845904523536028747135266249.
 
const Float64 Log2E = 1.44269504089
 The the log of E in base 2, defined as Log(E, 2)
 
const Float64 LogE = 0.4342944819
 The log of E in base 10, defined as Log(E)
 
const Float64 Ln2 = 0.69314718056
 The natural log of 2, defined as Log(2, E) = Ln(2)
 
const Float64 Ln10 = 2.30258509299
 The natural log of 10, defined as Log(10, E) = Ln(10)
 
const Float64 LnPi = 1.14472988585
 The natural log of Pi, defined as Log(10, Pi) = Ln(Pi)
 
const Float64 LnTauOver2 = 0.9189385332
 The natural log of Tau divided by 2, defined as Ln(Tau) / 2.
 
const Float64 Ln2PiOver2 = 0.9189385332
 The natural log of 2 * Pi divided by 2, defined as Ln(2 * Pi) / 2.
 
const Float64 InvE = 0.36787944117
 The inverse of E, defined as 1 / e.
 
const Float64 SqrtE = 1.6487212707
 The square root of E, defined as Sqrt(E)
 
const Float64 Sqrt2 = 1.41421356237309504880168872420969807
 Pythagoras' constant, defined as Sqrt(2);.
 
const Float64 Sqrt3 = 1.73205080756887729352744634150587236
 Theodorus' constant, defined as Sqrt(2)
 
const Float64 Sqrt5 = 2.23606797749978969640917366873127623
 The square root of 5, defined as Sqrt(5)
 
const Float64 SqrtOneHalf = 0.70710678118
 The square root of 1/2, defined as Sqrt(1/2)
 
const Float64 HalfSqrt3 = 0.86602540378
 Half the square root of 3, defined as Sqrt(3)/2.
 
const Float64 Pi = 3.14159265358979323846264338327950288
 The constant Pi, Archimedes' constant, defined as 3.14159265358979323846264338327950288.
 
const Float64 Tau = 6.2831853071795864
 The constant Tau, defined as 2 * Pi.
 
const Float64 Pi2 = 6.2831853071795864
 The constant Pi2, defined as 2 * Pi.
 
const Float64 OneOverPi = 0.31830988618
 One divided by Pi, defined as 1 / Pi.
 
const Float64 HalfPi = 1.57079632679
 Half of Pi, defined as Pi / 2.
 
const Float64 QuarterPi = 0.78539816339
 Quarter of Pi, defined as Pi / 4.
 
const Float64 SqrtPi = 1.77245385091
 The square root of Pi, defined as Sqrt(Pi)
 
const Float64 SqrtTau = 2.50662827463
 The square root of Tau, defined as Sqrt(Tau)
 
const Float64 Sqrt2Pi = 2.50662827463
 The square root of 2 * Pi, defined as Sqrt(Pi * 2)
 
const Float64 SqrtTauE = 4.13273135412
 The square root of Tau * E, defined as Sqrt(Tau * E)
 
const Float64 Sqrt2PiE = 4.13273135412
 The square root of 2 * Pi * E, defined as Sqrt(Pi * 2 * E)
 
const Float64 LogSqrtTau = 0.39908993417
 The log of the square root of Tau in base 10, defined as Log(Sqrt(Tau))
 
const Float64 LogSqrt2Pi = 0.39908993417
 The log of the square root of 2 * Pi in base 10, defined as Log(Sqrt(Pi * 2))
 
const Float64 LogSqrtTauE = 0.61623717513
 The log of the square root of Tau * E in base 10, defined as Log(Sqrt(Tau * E))
 
const Float64 LogSqrt2PiE = 0.61623717513
 The log of the square root of 2 * Pi * E in base 10, defined as Log(Sqrt(Pi * 2 * E))
 
const Float64 Log2SqrtEOverPi = 0.26960230026
 The log of 2 times the square root of E divied by Pi in base 10, defined as Log(2 * Sqrt(E / Pi))
 
const Float64 InvPi = 0.31830988618
 Inverse of Pi, defined as 1 / Pi.
 
const Float64 TwoInvPi = 0.63661977236
 The inverse of Pi times 2, defined as 2 / Pi.
 
const Float64 InvSqrtPi = 0.56418958354
 The inverse of the square root of Pi, defined as 1 / Sqrt(Pi)
 
const Float64 InvSqrtTau = 0.3989422804
 The inverse of the square root of Tau, defined as 1 / Sqrt(Tau)
 
const Float64 InvSqrt2Pi = 0.3989422804
 The inverse of the square root of 2 * Pi, defined as 1 / Sqrt(Pi * 2)
 
const Float64 TwoInvSqrtPi = 1.1283791671
 The the inverse of the square root of Pi times 2, defined as 2 / Sqrt(Pi)
 
const Float64 TwoSqrtEOverPi = 1.86038273421
 The square root of E divided by Pi times 2, defined as 2 / Sqrt(E/Pi)
 
const Float64 Degree = 0.01745329251
 The factor to convert from Degree (deg) to Radians (rad), defined as Pi / 180.
 
const Float64 Grad = 0.01570796326
 The factor to convert from NewGrad (grad) to Radians (rad), defined as Pi / 200.
 
const Float64 EulerMascheroni = 0.57721566490153286060651209008240243
 The Euler-Masceroni constant, defined as 0.57721 56649 01532 86060 65120 90082 40243.
 
const Float64 GoldenRatio = 1.61803398834989484820458683436563811
 The Golden Ratio, defined as 1.61803 39887 49894 84820 45868 34365 63811.
 
const Float64 Plastic = 1.32471795724474602596090885447809734
 The Plastic constant, defined as 1.32471 79572 44746 02596 09088 54478 09734.
 
const Float64 EmbreeTrefethen = 0.70258
 The Embree-Trefethen constant, defined as 0.70258.
 
const Float64 Feigenbaum = 2.50290787509589282228390287321821578
 The Feigenbaum constant, defined as 2.50290 78750 95892 82228 39028 73218 21578.
 
const Float64 Feigenbaum2 = 4.66920160910299067185320382046620161
 The Feigenbaum constant, defined as 2.50290 78750 95892 82228 39028 73218 21578.
 
const Float64 TwinPrime = 0.66016181584686957392781211001455577
 The Twin prime constant, defined as 0.66016 18158 46869 57392 78121 10014 55577.
 
const Float64 MeisselMertens = 0.26149721284764278375542683860869585
 The Miessel-Mertens constant, defined as 0.26149 72128 47642 78375 54268 38608 69585.
 
const Float64 BrunsTwinPrimes = 1.9021605823
 Brun's constant for twin primes, defined as 1.90216 05823.
 
const Float64 BrunsPrimeQuadruplets = 0.8705883800
 Brun's constant for prime quadruplets, defined as 0.87058 83800.
 
const Float64 Catalans = 0.91596559417721901505460351493238411
 Catalan's constant, defined as 0.91596 55941 77219 01505 46035 14932 38411.
 
const Float64 LandauRamanujan = 0.76422365358922066299069833125009232
 The Landau-Ramanujan constant, defined as 0.76422 36535 89220 66299 06987 31250 09232.
 
const Float64 Viswanaths = 1.13198824
 Viswanath's constant, defined as 1.13198 824.
 
const Float64 Legendre = 1
 Legendre's constant, defined as 1.
 
const Float64 RamanujanSoldner = 1.45136923488338105028396848589202744
 The Ramanujan-Soldner constant, defined as 1.45136 92348 83381 05028 39684 85892 02744.
 
const Float64 ErdosBorwein = 1.60669515241529176378330152319092458
 The Erdos-Borwein constant, defined as 1.60669 51524 15291 76378 33015 23190 92458.
 
const Float64 Bernsteins = 0.28016949902386913303
 Bernstein's constant, defined as 0.28016 94990 23869 13303.
 
const Float64 GaussKuzminWirsing = 0.30366300289873265859744812190155623
 The Gauss-Kuzmin-Wirsing constant, defined as 0.30366 30028 98732 65859 74481 21901 55623.
 
const Float64 HafnerSarnakMcCurley = 0.35323637185499598454
 The Hafner-Sarnak-McMurley constant, defined as 0.35323 63718 54995 98454.
 
const Float64 GolombDickman = 0.62432998854355087099293638310083724
 The Golomb-Dickman constant, defined as 0.62432 99885 43550 87099 29363 83100 83724.
 
const Float64 Cahens = 0.6434105463
 Cahen's constant, defined as 0.64341 05463.
 
const Float64 LaplaceLimit = 0.66274341934918158093474209710925290
 The Laplace limit, defined as 0.66274 34193 49181 58097 47420 97109 25290.
 
const Float64 AlladiGrinstead = 0.8093940205
 The Alladi-Grinstead constant, defined as 0.80939 40205.
 
const Float64 Lengyels = 1.0986858055
 Lengyel's constant, defined as 1.09868 58055.
 
const Float64 Levys = 3.27582291832181115978768188245384386
 Levy's constant, defined as 3.27582 29187 21811 15978 76818 82453 84386.
 
const Float64 Aperys = 1.20205690315959428539973816151144999
 Apery's constant, defined as 1.20205 69031 59594 28539 97381 61511 44999.
 
const Float64 Mills = 1.30633788386308069046861449260260571
 Mills' constant, defined as 1.30637 78838 63080 69046 86144 92602 60571.
 
const Float64 Backhouses = 1.45603494858268967139959535111654356
 Backhouse's constant, defined as 1.45607 49485 82689 67139 95953 51116 54356.
 
const Float64 Porters = 1.4670380794
 Porter's constant, defined as 1.46707 80794.
 
const Float64 LiebsSquareIce = 1.5396007178
 Lieb's square ice constant, defined as 1.53960 07178.
 
const Float64 Nivens = 1.70521114010536376428855145343450816
 Niven's constant, defined as 1.70521 11401 05367 76428 85514 53434 50816.
 
const Float64 Sierpinskis = 2.58498175957925321706589358738317116
 Sierpinski's constant, defined as 2.58498 17595 79253 21706 58935 87383 17116.
 
const Float64 Khinchins = 2.68545200106530644530971483548179569
 Khinchin's constant, defined as 2.68545 20010 65306 44530 97148 35481 79569.
 
const Float64 FransenRobinson = 2.80773024202851936522150118655377293
 The Fransen-Robinson constant, defined as 2.80777 02420 28519 36522 15011 86557 77293.
 
const Float64 Landaus = 0.5
 Landau's constant, defined as 0.5.
 
const Float64 UniversalParabolic = 2.29558714939263807403429804918949039
 The Universal parabolic constant, defined as 2.29558 71493 92638 07403 42980 49189 49039.
 
const Float64 Omega = 0.56714329040978387299996866221035555
 The Omega constant, defined as 0.56714 32904 09783 87299 99686 62210 35555.
 
const Float64 MRB = 0.187859
 The MRB constant, defined as 0.187859.
 
const Float64 ReciprocalFibonacci = 3.359885666243173553132011302918
 The Reciprocal Fibonacci constant, defined as 3.35988 56662 43177 55317 20113 02918 ....
 
const Float64 PowerDecibel = 0.11512925465
 The factor to convert from Power Decibel (dB) to Neper(Np), defined as ln(10) / 20.
 
const Float64 NeutralDecibel = 0.23025850929
 The factor to convert from Neutral Decibel (dB) to Neper(Np), defined as ln(10) / 10.
 
const UInt32 SizeOfDouble32 = 4
 The size of a 32-bit double, defined as 4.
 
const UInt32 SizeOfDouble64 = 8
 The size of a 64-bit double, defined as 8.
 
const UInt32 SizeOfInt32 = 4
 The size of a 32-bit integer, defined as 4.
 
const UInt32 SizeOfInt64 = 8
 The size of a 64-bit integer, defined as 8.
 
const UInt32 SizeOfFloat32 = 4
 The size of a 32-bit float, defined as 4.
 
const UInt32 SizeOfFloat64 = 8
 The size of a 64-bit float, defined as 8.
 
const Float64 SpeedOfLight = 299792458
 The speed of light in a vacuum, defined as 2.99792458e8 [m/s].
 
const Float64 MagneticPermeability = 0.00000125663706
 The magnetic permeability in a vacuum, defined as (4 * Pi)e-7 [N/A^2].
 
const Float64 ElectricPermittivity = 0.0000000000088541878
 The electric permittivity in a vacuum, defined as 1 / (MagneticPermeability * SpeedOfLight^2) [F/m].
 
const Float64 CharacteristicImpedanceVacuum = 376.730313031
 The characteristic impedance of vacuum, defined as MagneticPermeability * SpeedOfLight [Ohm].
 
const Float64 GravitationalConstant = 0.0000000000667429
 The Newtonian Constant of Gravitation, defined as 6.67429e-11 [m^3/(kg*s^2)].
 
const Float64 Exa = 1000000000000000000.0
 The SI prefix factor corresponding to 1000000000000000000.
 
const Float64 Peta = 1000000000000000.0
 The SI prefix factor corresponding to 1000000000000000.
 
const Float64 Tera = 1000000000000.0
 The SI prefix factor corresponding to 1000000000000.
 
const Float64 Giga = 1000000000.0
 The SI prefix factor corresponding to 1000000000.
 
const Float64 Mega = 1000000.0
 The SI prefix factor corresponding to 1000000.
 
const Float64 Kilo = 1000.0
 The SI prefix factor corresponding to 1000.
 
const Float64 Hecto = 100.0
 The SI prefix factor corresponding to 100.
 
const Float64 Deca = 10.0
 The SI prefix factor corresponding to 10.
 
const Float64 Deci = 0.1
 The SI prefix factor corresponding to 0.1.
 
const Float64 Centi = 0.01
 The SI prefix factor corresponding to 0.01.
 
const Float64 Milli = 0.001
 The SI prefix factor corresponding to 0.001.
 
const Float64 Micro = 0.000001
 The SI prefix factor corresponding to 0.000001.
 
const Float64 Nano = 0.000000001
 The SI prefix factor corresponding to 0.000000001.
 
const Float64 Pico = 0.000000000001
 The SI prefix factor corresponding to 0.000000000001.
 
const Float64 Femto = 0.000000000000001
 The SI prefix factor corresponding to 0.000000000000001.
 
const Float64 Atto = 0.000000000000000001
 The SI prefix factor corresponding to 0.000000000000000001.
 
const Float64 Nan = std::numeric_limits<double>::quiet_NaN()
 Not a number.
 

Detailed Description

A namespace containing many common mathematical functions.

Some mathematical concepts were ruthlessly stolen from MathGeoLib. Be sure to check it out as an awesome standalone math library! http://clb.demon.fi/MathGeoLib/nightly/reference.html

Function Documentation

template<typename Type >
Type CGUL::Math::Abs ( Type  x)
inline

Calculates the absolute value of x.

The absolute value is defined as the one dimensional distance of a value from 0. In other words, the value is always positive. A value of 5 results in 5, while a value of -4 results in 4.

Parameters
xThe number to get the absolute value of.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::ACos ( Type  x)
inline

Calculates the arc cosine of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::ASin ( Type  x)
inline

Calculates the arc sine of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::ATan ( Type  x)
inline

Calculates the arc tangent of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Ceil ( Type  x)
inline

Rounds the number up.

Parameters
xThe number to round.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Clamp ( Type  x,
Type  min,
Type  max 
)

Clamps the value between a minimum and maximum range.

Parameters
xValue to clamp.
minMinimum value for x.
maxMaximum value for x.
Returns
x or the clamped value.
template<typename Type >
Type CGUL::Math::Cos ( Type  x)
inline

Calculates the cosine of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Cosh ( Type  x)
inline

Calculates the hyperbolic cosine of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::DegToRad ( Type  deg)
inline

Converts degrees to radians.

Parameters
degA value in degrees.
Returns
The resulting value in radians.
template<typename Type >
Type CGUL::Math::Exp ( Type  x)
inline
Parameters
xThe exponent value
Returns
e raised to the power of x.
template<typename Type >
Type CGUL::Math::Floor ( Type  x)
inline

Rounds the number down.

Parameters
xThe number to round.
Returns
The resulting value.
template<typename Type >
bool CGUL::Math::InEpsilon ( Type  value,
Type  compare,
Type  epsilon 
)
inline

Checks if two values are equal within a given epsilon.

Due to floating point inprecision, it is often difficult to determine when two values should be exactly equal. A common technique used is to check if, within a given epsilon (some really small number), the two numbers are nearly equal.

Parameters
valueThe first value.
compareA value to compare.
epsilonThe maximum difference between the values. Usually something really small like 0.00001f.
Returns
True if the two values are within the given epsilon, false otherwise.
bool CGUL::Math::IsPowerOfTwo ( UInt32  x)
inline

Checks if the value is a power of two.

The zero case is handled correctly. Passing in zero for x will result in false.

Parameters
xValue to check.
Returns
True if x is a power of 2, false otherwise.
template<typename Type >
Type CGUL::Math::Max ( Type  a,
Type  b 
)
inline

Finds the larger of the two values.

Parameters
aThe first value.
bThe second value.
Returns
The larger of the two values.
template<typename Type >
Type CGUL::Math::Max ( Type  a,
Type  b,
Type  c 
)
inline

Finds the larger of the three values.

Parameters
aThe first value.
bThe second value.
cThe third value.
Returns
The larger of the three values.
template<typename Type >
Type CGUL::Math::Min ( Type  a,
Type  b 
)
inline

Finds the smaller of the two values.

Parameters
aThe first value.
bThe second value.
Returns
The smaller of the two values.
template<typename Type >
Type CGUL::Math::Min ( Type  a,
Type  b,
Type  c 
)
inline

Finds the smaller of the three values.

Parameters
aThe first value.
bThe second value.
cThe third value.
Returns
The smaller of the three values.
template<typename Type >
Type CGUL::Math::Mod ( Type  x,
Type  div 
)
inline

A modulus function that works with floating point numbers.

The modulus is the remainder of long division, but can be useful for floating point numbers as well. The resulting value maintains the signage of the dividend. See Sign.

Parameters
xThe dividend.
divThe divisor.
Returns
The resulting value.
See Also
Sign
template<typename Type >
Type CGUL::Math::Pow ( Type  x,
Type  y 
)
inline

Raises x to the power of y.

Parameters
xThe base value.
yThe exponent value.
Returns
x raised to the power of y.
template<typename Type >
Type CGUL::Math::RadToDeg ( Type  rad)
inline

Converts radians to degrees.

Parameters
degA value in radians.
Returns
The resulting value in degrees.
template<typename Type >
Type CGUL::Math::Round ( Type  x)
inline

Rounds the number.

Parameters
xThe number to round.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Sign ( Type  x)
inline

Gets the sign of the value, returning -1, 0, or 1.

The sign is determined based on if the number is positive, negative, or zero. A positive value has a sign of 1, a negative value has a sign of -1, and zero has a sign of 0.

Parameters
xThe number to get the sign of.
Returns
-1, 0, or 1
template<typename Type >
Type CGUL::Math::Sin ( Type  x)
inline

Calculates the sine of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Sinh ( Type  x)
inline

Calculates the hyperbolic sine of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Sqr ( Type  x)
inline

Calculates the square of a number.

The square of a number is simply that number multiplied by itself.

Parameters
xThe number to square.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Sqrt ( Type  x)
inline

Calculates the square root of a number.

Warning
The square root function can be slow!
Parameters
xThe number to find the square root of.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Tan ( Type  x)
inline

Calculates the tangent of x.

Parameters
xThe input value.
Returns
The resulting value.
template<typename Type >
Type CGUL::Math::Tanh ( Type  x)
inline

Calculates the hyperbolic tangent of x.

Parameters
xThe input value.
Returns
The resulting value.