Core 1.0
Math Class Reference

Core class implementing some useful functions and constants. More...

#include <mathematics.h>

Static Public Member Functions

static double Clamp (const double &, const double &=0.0, const double &=1.0)
 Array of binomial coefficients.
 
static int Clamp (int, int=0, int=255)
 Clamp an integer value between two bounds.
 
static constexpr double Sqr (const double &)
 Squares a double value.
 
static constexpr double Cube (const double &)
 Cubes a double value.
 
static double Sqr4 (const double &)
 Fourth power of a double value.
 
static double SymmetricSqr (const double &)
 Symmetric of square function over unit interval.
 
static double Pow (const double &, const double &)
 Power.
 
static double Abs (const double &)
 Absolute value.
 
static double Sqrt32 (const double &)
 Compute x3/2 as the square root of x3.
 
static double Sqrt4 (const double &)
 Compute the fourth root of x3.
 
static void Powers (const double &, int, double *)
 Compute the powers series of a real value 1, x, ... , xn-1.
 
static void Powers (const double &, int, double *, double *)
 Compute the powers series of a real value 1, x, ... , xn-1 and 1, 1-x, ... , (1-x)n-1.
 
static constexpr double Mod (const double &, const double &)
 Modulus for reals with negative values handled properly.
 
static double Floor (const double &)
 Floor function.
 
static double Fract (const double &)
 Fractional part of a real.
 
static double FractFloor (const double &, double &)
 Fractional part of a real.
 
static double Ceil (const double &)
 Ceil function.
 
static double Min (const double &, const double &)
 Minimum of two reals.
 
static double Max (const double &, const double &)
 Maximum of two reals.
 
static double Min (const double &, const double &, const double &)
 Minimum of three reals.
 
static double Max (const double &, const double &, const double &)
 Maximum of three reals.
 
static double Min (const double &, const double &, const double &, const double &)
 Minimum of four reals.
 
static double Max (const double &, const double &, const double &, const double &)
 Maximum of four reals.
 
static constexpr double DegreeToRadian (const double &)
 Convert degrees to randians.
 
static constexpr double RadianToDegree (const double &)
 Convert radian to degrees.
 
static constexpr double Angle (int, int)
 Compute 2 k π / n.
 
static constexpr double Angle (const double &)
 Angle strictly in [0,2 π[.
 
static double AngleNorm (const double &, const double &)
 Compute the (positive) angle distance between two angles.
 
static double AngleSigned (const double &, const double &)
 Compute the signed angle norm between two angles.
 
static double AngleLerp (const double &, const double &, const double &)
 Compute the interpolation between two angles, using the smallest angle rotation.
 
static double ArcTan (const double &, const double &)
 Inline version of the atan2() function.
 
static double FoldAngle (const double &, bool=true)
 Fold the argument angle to [0,2 π[ or [- π;pi[.
 
static double SinAtan (const double &)
 Trigonometric simplification of sin(atan(x)).
 
static double CosAtan (const double &)
 Trigonometric simplification of cos(atan(x)).
 
static double Step (double, double)
 Step function.
 
static double Cycloidal (const double &)
 Sine wave over unit interval.
 
static double Triangle (const double &)
 Triangle wave over unit interval.
 
static double Lerp (const double &, const double &, const double &)
 Linear interpolation.
 
static double Bilinear (const double &, const double &, const double &, const double &, const double &, const double &)
 Bi-linear interpolation between four values.
 
static double Trilinear (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &)
 Trilinear interpolation between eight values.
 
static double Cubic (const double &, const double &, const double &, const double &, const double &)
 Cubic Hermite interpolation.
 
static double CubicPoints (const double &, const double &, const double &, const double &, const double &)
 Cubic point interpolation.
 
static double BiCubic (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &=0.0, const double &=0.0, const double &=0.0, const double &=0.0)
 Bi-cubic interpolation between four values, given partial derivatives.
 
static double BiCubic (const double &, const double &, const double &, const double &, const double &, const double &)
 Bi-cubic interpolation between four values, partial derivatives are implicitly defined as null.
 
static double Sigmoid (const double &, const double &=1.0)
 Sigmoid-like function.
 
static double SigmoidQuadric (const double &)
 Compactly supported sigmoid-like function implemented using a C1 piecewise symmetric quadric.
 
static double Impulse (const double &, const double &=1.0)
 Impulse function.
 
static double Warp (const double &)
 Unit interval warping function.
 
static double Warp (const double &, const double &)
 Unit interval gain function.
 
static bool InRange (const double &, const double &, const double &, const double &)
 Check if a values lies within a prescribed range.
 
static void SetMinMax (const double &, double &, double &)
 Update the minimum and maximum values given a double value.
 
static int Integer (const double &)
 Compute the integer part of a real.
 
static void Sort (int &, int &)
 Sort two integers.
 
static void Sort (double &, double &)
 Sort two reals.
 
static void Sort (double &, double &, double &)
 Sort three reals.
 
static void Sort (double &, double &, double &, double &)
 Sort four reals, with a maximum of 5 comparisons.
 
static void Sort5 (double *)
 
static void Swap (int &, int &)
 Swap two integers.
 
static void Swap (double &, double &)
 Swap two reals.
 
static bool IsNumber (double)
 Check if a real number is not NaN.
 
static bool IsFinite (double)
 Check if a real is not infinite.
 
static int IntegerSign (const double &, const double &=0.0)
 Compute the integer sign of a real.
 
static bool SameSign (const double &, const double &)
 Check if two reals have the same signs.
 
static bool SameSign (const double &, const double &, const double &)
 Check if three reals have the same signs.
 
static double CopySign (const double &, const double &)
 Composes a real with the magnitude of x and the sign of y.
 
static double Sign (const double &)
 Returns +1 or -1 depending on the sign of argument.
 
static long Binomial (int, int)
 Calculate the Binomial coefficent.
 
static constexpr double Unit (int, int)
 Unit real value in [0,1] from two integers.
 
static double Gaussian (const double &, const double &)
 Gaussian.
 
static double GaussianProbability (const double &, const double &)
 Gaussian probability density function.
 
static double CompactGaussian (const double &, const double &)
 Compact support Gaussian approximation.
 
static double Fract (const double &, double &)
 Compute integer and fractionnal parts.
 
static double Fract (const double &, const double &, double &)
 Compute integer and fractionnal parts.
 
static double Fract (const double &, const double &, const double &, double &)
 Compute integer and fractionnal parts given an interval.
 
static double Geometric (double, int)
 Compute the sum of the terms of a geometric series.
 
static void Swap (double *&, double *&)
 Swap two reals.
 
static void Swap (int *&, int *&)
 Swap two integers.
 
static void BernsteinSeries (const double &, int, double *)
 Compute the Bernstein terms.
 
static double Bernstein (const double &, int, int)
 Compute the i-th Bernstein term.
 
static double SmoothingCubic (double, double, double)
 Generalized C2 polynomial smoothing function between two distances.
 
static double SmoothingQuadric (double, double, double)
 Generalized C1 polynomial smoothing function between two distances.
 

Static Public Attributes

static constexpr double Pi = 3.14159265358979323846
 π.
 
static constexpr double HalfPi = Math::Pi / 2.0
 2π.
 
static constexpr double e = 2.7182818284590452354
 Half of π.
 
static constexpr double TwoPiOverThree = 2.0943951023931954923084
 Exponential.
 
static constexpr double Sqrt5 = 2.23606797749978969640917366873127623
 4/3 π.
 
static constexpr double Sqrt3 = 1.73205080756887729352744634150587236
 Constant √3.
 
static constexpr double Sqrt2 = 1.41421356237309504880168872420969807
 Constant √2.
 
static constexpr double Sqrt12 = 1.0 / Math::Sqrt2
 Constant 1/√2.
 
static constexpr double Large = 1.0e20
 Constant (√5+1)/2.
 
static constexpr double Infinity = DBL_MAX
 Large constant 1020.
 

Detailed Description

Core class implementing some useful functions and constants.

How can I use the constant Pi?
Simply use the static constant Math::Pi as follows:

double v = 4.0*Math::Pi*r*r*r/3.0; // Volume of a sphere.
static constexpr double Pi
π.
Definition mathematics.h:178

Note that in this case, you could also have used:

double v = Sphere::Volume(r);
double Volume() const
Compute the volume of the sphere.
Definition sphere.h:147

How many min/max functions have been implemented?
Up to four arguments are supported; for a larger number of arguments, a specific routine operating on an array should be written.

Is there a function to compute the square of a real sumber?
Use the following:

double s = Math::Sqr((1.0-sqrt(5.0))/2.0); // Square of golden ratio
static constexpr double Sqr(const double &)
Squares a double value.
Definition mathematics.h:381

For a Vector, use SquaredNorm(const Vector&);

Are there predefined square roots constants?
The sqrt function used not te be constexpr, so square roots of reals are not computed at compilation time. Some constants are provided, such as the following one:

double s = Math::Sqrt3; // Square root of 3
static constexpr double Sqrt3
Constant √3.
Definition mathematics.h:185

What is the relative performance of mathematical functions such as square root or cosine?
The relative cost of commonly used mathematical functions is summarized in the following table.

Cost
FunctionCost
+ - * fabs1
/ sqrt modf ~4.8
/ sin cos ~8.9
/ exp log ~10.5

Math provides some functions such as Math::Sqrt32 or Math::Sqrt4 to avoid computationally intensive standard functions like pow:

double y = Math::Sqrt32(x); // Faster than double y = pow(x,1.5);
static double Sqrt32(const double &)
Compute x3/2 as the square root of x3.
Definition mathematics.h:404

How are implemented the step and smooth-step functions that are often used in procedural modeling? Different smoothing kernels, such as Cubic::Smooth(), are implented in odd-degree polynomials Cubic, Quintic and Septic. The corresponding step functions, such as Cubic::SmoothStep(), are also implemented.

See also
Linear::Step, Cubic::Smooth, Quintic::Smooth, Cubic::SmoothStep, Quintic::SmoothStep, Septic::SmoothStep.

Member Function Documentation

◆ Abs()

double Math::Abs ( const double & x)
inlinestatic

Absolute value.

Parameters
xReal.

◆ Angle() [1/2]

double Math::Angle ( const double & a)
inlinestaticconstexpr

Angle strictly in [0,2 π[.

Parameters
aAngle.

◆ Angle() [2/2]

double Math::Angle ( int k,
int n )
inlinestaticconstexpr

Compute 2 k π / n.

Parameters
k,nIntegers.

◆ AngleLerp()

double Math::AngleLerp ( const double & a,
const double & b,
const double & t )
inlinestatic

Compute the interpolation between two angles, using the smallest angle rotation.

See also
Math::AngleSigned
Parameters
a,bAngles.
tInterpolant.

◆ AngleNorm()

double Math::AngleNorm ( const double & a,
const double & b )
inlinestatic

Compute the (positive) angle distance between two angles.

Parameters
a,bAngles.

◆ AngleSigned()

double Math::AngleSigned ( const double & a,
const double & b )
inlinestatic

Compute the signed angle norm between two angles.

See also
Math::AngleNorm
Parameters
a,bAngles.

◆ BiCubic() [1/2]

double Math::BiCubic ( const double & u,
const double & v,
const double & a00,
const double & a10,
const double & a11,
const double & a01 )
static

Bi-cubic interpolation between four values, partial derivatives are implicitly defined as null.

This is an optimized implementation.

Parameters
u,vInterpolation coefficients.
a00,a10,a11,a01Interpolated values.

◆ BiCubic() [2/2]

double Math::BiCubic ( const double & u,
const double & v,
const double & a00,
const double & a10,
const double & a11,
const double & a01,
const double & u00,
const double & u10,
const double & u11,
const double & u01,
const double & v00,
const double & v10,
const double & v11,
const double & v01,
const double & x00 = 0.0,
const double & x10 = 0.0,
const double & x11 = 0.0,
const double & x01 = 0.0 )
static

Bi-cubic interpolation between four values, given partial derivatives.

The values are given in trigonometric order.

Parameters
u,vInterpolation coefficients.
a00,a10,a11,a01Interpolated values.
u00,u10,u11,u01,v00,v10,v11,v01Partial derivatives with respect to u and v.
x00,x10,x11,x01Cross derivatives.

◆ Bilinear()

double Math::Bilinear ( const double & a00,
const double & a10,
const double & a11,
const double & a01,
const double & u,
const double & v )
inlinestatic

Bi-linear interpolation between four values.

The values are given in trigonometric order.

Parameters
a00,a10,a11,a01Interpolated values.
u,vInterpolation coefficients.

◆ Binomial()

long Math::Binomial ( int n,
int r )
static

Calculate the Binomial coefficent.

Parameters
n,rBinomial coefficient parameters.

◆ Ceil()

double Math::Ceil ( const double & x)
inlinestatic

Ceil function.

See also
Floor
Parameters
xReal.

◆ Clamp() [1/2]

double Math::Clamp ( const double & x,
const double & a = 0.0,
const double & b = 1.0 )
inlinestatic

Array of binomial coefficients.

Clamp a double value between two bounds.

Parameters
xInput value.
a,bLower and upper bounds.

◆ Clamp() [2/2]

int Math::Clamp ( int x,
int a = 0,
int b = 255 )
inlinestatic

Clamp an integer value between two bounds.

Parameters
xInput value.
a,bLower and upper bounds.

◆ CompactGaussian()

double Math::CompactGaussian ( const double & x,
const double & s )
inlinestatic

Compact support Gaussian approximation.

The compact support has a radius r = 3 sigma.

Parameters
xReal.
sSigma.

◆ CopySign()

double Math::CopySign ( const double & x,
const double & y )
inlinestatic

Composes a real with the magnitude of x and the sign of y.

Parameters
xReal.
yReal whose sign will be copied.

◆ CosAtan()

double Math::CosAtan ( const double & x)
static

Trigonometric simplification of cos(atan(x)).

Parameters
xReal value.

◆ Cube()

double Math::Cube ( const double & x)
inlinestaticconstexpr

Cubes a double value.

Parameters
xReal value.

◆ Cubic()

double Math::Cubic ( const double & u,
const double & a,
const double & b,
const double & ta,
const double & tb )
static

Cubic Hermite interpolation.

Parameters
uInterpolation coefficient.
a,bValues for t=0 and t=1.
ta,tbDerivatives for t=0 and t=1.
See also
Cubic::Hermite()

◆ CubicPoints()

double Math::CubicPoints ( const double & u,
const double & a,
const double & b,
const double & c,
const double & d )
static

Cubic point interpolation.

Parameters
uInterpolation coefficient.
a,b,c,dValues for t=-1, t=0, t=1 and t=2. The derivatives at t=0 and t=1 will be derived from those
See also
Math::Cubic()

◆ Cycloidal()

double Math::Cycloidal ( const double & x)
static

Sine wave over unit interval.

Parameters
xReal value.

◆ DegreeToRadian()

double Math::DegreeToRadian ( const double & a)
inlinestaticconstexpr

Convert degrees to randians.

Parameters
aAngle in degrees.

◆ Floor()

double Math::Floor ( const double & x)
inlinestatic

Floor function.

While it is easier to use the C++ function, this has been implemented to be consistent with Fract().

Parameters
xReal.

◆ FoldAngle()

double Math::FoldAngle ( const double & a,
bool s = true )
static

Fold the argument angle to [0,2 π[ or [- π;pi[.

Parameters
aAngle.
sStrategy, map to [0,2 π[ if true, [- π;pi[ otherwise.

◆ Fract() [1/4]

double Math::Fract ( const double & x)
inlinestatic

Fractional part of a real.

Implemented as:

double y=x-Math::Floor(x);
static double Floor(const double &)
Floor function.
Definition mathematics.h:799
Parameters
xReal.

◆ Fract() [2/4]

double Math::Fract ( const double & x,
const double & a,
const double & b,
double & i )
inlinestatic

Compute integer and fractionnal parts given an interval.

Parameters
xReal.
a,bInterval.
iReturned integer part.
Returns
Fractional part.

◆ Fract() [3/4]

double Math::Fract ( const double & x,
const double & a,
double & i )
inlinestatic

Compute integer and fractionnal parts.

Parameters
xReal.
aModulus.
iReturned integer part.
Returns
Fractional part.

◆ Fract() [4/4]

double Math::Fract ( const double & x,
double & i )
inlinestatic

Compute integer and fractionnal parts.

Parameters
xReal.
iReturned integer part.
Returns
Fractional part.

◆ FractFloor()

double Math::FractFloor ( const double & x,
double & y )
inlinestatic

Fractional part of a real.

Implemented as:

double y = x - Math::Floor(x);
Parameters
xReal.
yReturn floor.

◆ Gaussian()

double Math::Gaussian ( const double & x,
const double & s )
inlinestatic

Gaussian.

Parameters
xReal.
sSigma.

◆ GaussianProbability()

double Math::GaussianProbability ( const double & x,
const double & s )
inlinestatic

Gaussian probability density function.

Parameters
xReal.
sSigma.

◆ Geometric()

double Math::Geometric ( double x,
int n )
static

Compute the sum of the terms of a geometric series.

Compute 1+x+x2+...+xn-1=(1-xn)/(1-x). If x=1.0, return n.

◆ Impulse()

double Math::Impulse ( const double & x,
const double & k = 1.0 )
inlinestatic

Impulse function.

An impulse function that doesn't use exponentials, k controls the falloff of the function.

Derivative is 2*sqrt(k)*(1-k*x*x)/(k*x*x+1), maximum is reached x = sqrt(1/k), value at maximum is 1.

Parameters
kControl parameter.
xReal.

◆ InRange()

bool Math::InRange ( const double & x,
const double & a,
const double & b,
const double & epsilon )
inlinestatic

Check if a values lies within a prescribed range.

Parameters
xValue.
a,bInterval.
epsilonEpsilon tolerance.

◆ Integer()

int Math::Integer ( const double & x)
inlinestatic

Compute the integer part of a real.

This function handles negative values differently by subtracting 1 from the result.

Parameters
xReal.

◆ IntegerSign()

int Math::IntegerSign ( const double & x,
const double & t = 0.0 )
inlinestatic

Compute the integer sign of a real.

Parameters
xReal.
tThreshold.

◆ IsFinite()

bool Math::IsFinite ( double x)
static

Check if a real is not infinite.

Parameters
xReal value.

◆ IsNumber()

bool Math::IsNumber ( double x)
static

Check if a real number is not NaN.

The code is simply:

return (x == x);

This looks like it should always be true, but it's false if x is a NaN.

Parameters
xReal value.

◆ Lerp()

double Math::Lerp ( const double & a,
const double & b,
const double & t )
inlinestatic

Linear interpolation.

Returns (1-t)a+tb.

Parameters
a,bInterpolated values.
tInterpolant.

◆ Max() [1/3]

double Math::Max ( const double & a,
const double & b )
inlinestatic

Maximum of two reals.

Parameters
a,bReal values.

◆ Max() [2/3]

double Math::Max ( const double & a,
const double & b,
const double & c )
inlinestatic

Maximum of three reals.

Parameters
a,b,cReal values.

◆ Max() [3/3]

double Math::Max ( const double & a,
const double & b,
const double & c,
const double & d )
inlinestatic

Maximum of four reals.

Parameters
a,b,c,dReal values.

◆ Min() [1/3]

double Math::Min ( const double & a,
const double & b )
inlinestatic

Minimum of two reals.

Parameters
a,bReal values.

◆ Min() [2/3]

double Math::Min ( const double & a,
const double & b,
const double & c )
inlinestatic

Minimum of three reals.

Parameters
a,b,cReal values.

◆ Min() [3/3]

double Math::Min ( const double & a,
const double & b,
const double & c,
const double & d )
inlinestatic

Minimum of four reals.

Parameters
a,b,c,dReal values.

◆ Mod()

double Math::Mod ( const double & x,
const double & a )
inlinestaticconstexpr

Modulus for reals with negative values handled properly.

Parameters
xReal.
aModulo.

◆ Pow()

double Math::Pow ( const double & x,
const double & e )
inlinestatic

Power.

Returns base x raised to the power exponent e if x>0, and -x raised to the power exponent e otherwise.

Parameters
xBase.
eExponent.

◆ Powers() [1/2]

void Math::Powers ( const double & x,
int n,
double * a )
inlinestatic

Compute the powers series of a real value 1, x, ... , xn-1.

Parameters
xReal.
nMaximum power.
aArray of real, should be at least of size n.

◆ Powers() [2/2]

void Math::Powers ( const double & x,
int n,
double * a,
double * b )
inlinestatic

Compute the powers series of a real value 1, x, ... , xn-1 and 1, 1-x, ... , (1-x)n-1.

Parameters
xReal.
nMaximum power.
a,bArray of real, should be at least of size n.

◆ RadianToDegree()

double Math::RadianToDegree ( const double & a)
inlinestaticconstexpr

Convert radian to degrees.

Parameters
aAngle in radian.

◆ SameSign() [1/2]

bool Math::SameSign ( const double & a,
const double & b )
inlinestatic

Check if two reals have the same signs.

Parameters
a,bReals.

◆ SameSign() [2/2]

bool Math::SameSign ( const double & a,
const double & b,
const double & c )
inlinestatic

Check if three reals have the same signs.

Parameters
a,b,cReals.

◆ SetMinMax()

void Math::SetMinMax ( const double & x,
double & a,
double & b )
inlinestatic

Update the minimum and maximum values given a double value.

Parameters
xInput value.
a,bLower and upper bounds that will be updated according to x.

◆ Sigmoid()

double Math::Sigmoid ( const double & x,
const double & s = 1.0 )
inlinestatic

Sigmoid-like function.

This function is more efficient than the real sigmoid function which requires the computation of the exponential.

Parameters
sSigma.
xReal.

◆ SigmoidQuadric()

double Math::SigmoidQuadric ( const double & x)
inlinestatic

Compactly supported sigmoid-like function implemented using a C1 piecewise symmetric quadric.

The compact support is [-2,2] and the range [-1,1].

The quadric was obtaied by solving the Hermite Cubic contraints:

Cubic c=2.0*Cubic::Compose(Cubic::Hermite(0, 0.5, 1.0, 0.0), Linear(0.5, 0.0)) <<std::endl;
static Cubic Hermite(const double &, const double &, const double &, const double &)
Creates an Hermite cubic polynomial.
Definition cubic.cpp:177
static Cubic Compose(const Cubic &, const Linear &)
Compose the cubic by a linear.
Definition cubic.cpp:380
Linear polynomials.
Definition linear.h:7
static double Cubic(const double &, const double &, const double &, const double &, const double &)
Cubic Hermite interpolation.
Definition mathematics.cpp:171
See also
Math::Sigmoid
Parameters
xReal.

◆ Sign()

double Math::Sign ( const double & x)
inlinestatic

Returns +1 or -1 depending on the sign of argument.

Parameters
xReal.

◆ SinAtan()

double Math::SinAtan ( const double & x)
static

Trigonometric simplification of sin(atan(x)).

Parameters
xReal value.

◆ SmoothingCubic()

double Math::SmoothingCubic ( double a,
double b,
double sr )
inlinestatic

Generalized C2 polynomial smoothing function between two distances.

The function is not associative.

Parameters
a,bDistances.
srSmoothing radius.

◆ SmoothingQuadric()

double Math::SmoothingQuadric ( double a,
double b,
double sr )
inlinestatic

Generalized C1 polynomial smoothing function between two distances.

This is a general version of the union, intersection and difference function of Media Molecule using in the Dreams video game.

The function is not associative.

Parameters
a,bDistances.
srSmoothing radius.

◆ Sort() [1/4]

void Math::Sort ( double & a,
double & b )
inlinestatic

Sort two reals.

See also
Math::Swap(double&,double&)
Parameters
a,bReal arguments, which will be swapped so that a<=b.

◆ Sort() [2/4]

void Math::Sort ( double & a,
double & b,
double & c )
inlinestatic

Sort three reals.

See also
Math::Sort(double&,double&)
Parameters
a,b,cReal arguments, which will be swapped so that a<=b<=c.

◆ Sort() [3/4]

void Math::Sort ( double & a,
double & b,
double & c,
double & d )
inlinestatic

Sort four reals, with a maximum of 5 comparisons.

See also
Math::Sort(double&,double&)
Parameters
a,b,c,dReal arguments, which will be swapped into ascending order.

◆ Sort() [4/4]

void Math::Sort ( int & a,
int & b )
inlinestatic

Sort two integers.

See also
Math::Swap(int&,int&)
Parameters
a,bReal arguments, which will be swapped so that a<=b.

◆ Sort5()

void Math::Sort5 ( double * A)
static

Sort five reals with only seven comparisons.

Parameters
AArray of five reals.

◆ Sqr()

double Math::Sqr ( const double & x)
inlinestaticconstexpr

Squares a double value.

See also
Math::SymmetricSqr
Parameters
xReal value.

◆ Sqr4()

double Math::Sqr4 ( const double & x)
inlinestatic

Fourth power of a double value.

Parameters
xReal value.

◆ Sqrt32()

double Math::Sqrt32 ( const double & x)
inlinestatic

Compute x3/2 as the square root of x3.

This function is more efficient than pow() which is extremely slow.

double y=Math::Sqrt32(7.0); // Equivalent but faster than y=pow(7.0,1.5);
Parameters
xReal value.

◆ Sqrt4()

double Math::Sqrt4 ( const double & x)
inlinestatic

Compute the fourth root of x3.

This function is more efficient than pow() which is extremely slow.

double y=Math::Sqrt4(7.0); // Equivalent to y=sqrt(sqrt(7.0));
static double Sqrt4(const double &)
Compute the fourth root of x3.
Definition mathematics.h:418
Parameters
xReal value.

◆ Step()

double Math::Step ( double e,
double x )
inlinestatic

Step function.

Parameters
eStep position.
xVariable.

◆ Swap() [1/4]

void Math::Swap ( double & a,
double & b )
inlinestatic

Swap two reals.

See also
Sort(double&,double&)
Parameters
a,bArguments.

◆ Swap() [2/4]

void Math::Swap ( double *& a,
double *& b )
inlinestatic

Swap two reals.

Parameters
a,bArguments.

◆ Swap() [3/4]

void Math::Swap ( int & a,
int & b )
inlinestatic

Swap two integers.

See also
Sort(int&,int&)
Parameters
a,bArguments.

◆ Swap() [4/4]

void Math::Swap ( int *& a,
int *& b )
inlinestatic

Swap two integers.

Parameters
a,bArguments.

◆ SymmetricSqr()

double Math::SymmetricSqr ( const double & x)
inlinestatic

Symmetric of square function over unit interval.

Simply compute 1-(1-x)2.

See also
Math::Sqr
Parameters
xReal value.

◆ Triangle()

double Math::Triangle ( const double & x)
static

Triangle wave over unit interval.

Parameters
xReal value.

◆ Trilinear()

double Math::Trilinear ( const double & a,
const double & b,
const double & c,
const double & d,
const double & e,
const double & f,
const double & g,
const double & h,
const double & u,
const double & v,
const double & w )
inlinestatic

Trilinear interpolation between eight values.

See also
Math::Bilinear()
Parameters
a,b,c,d,e,f,g,hInterpolated values.
u,v,wInterpolation coefficients.

◆ Unit()

double Math::Unit ( int i,
int n )
inlinestaticconstexpr

Unit real value in [0,1] from two integers.

Usefull for loops, same as:

for (int i=0;i<n;i++)
{
double t=double(i)/double(n-1); // t=Math::Unit(i,n);
}
Parameters
i,nIntegers.

◆ Warp() [1/2]

double Math::Warp ( const double & x)
inlinestatic

Unit interval warping function.

Remaps the unit interval into the unit interval by expanding the sides and compressing the center, keeping 1/2 mapped to 1/2.

Parameters
xReal in [0,1].

◆ Warp() [2/2]

double Math::Warp ( const double & x,
const double & k )
inlinestatic

Unit interval gain function.

Remaps the unit interval into the unit interval by expanding the sides and compressing the center, keeping 1/2 mapped to 1/2.

This function uses calls to pow and is computationally intensive.

See also
Quadric::Warp(const double&)
Parameters
xReal in [0,1].
kExponent.

Member Data Documentation

◆ Infinity

double Math::Infinity = DBL_MAX
staticconstexpr

Large constant 1020.

Infinity.

◆ Sqrt5

double Math::Sqrt5 = 2.23606797749978969640917366873127623
staticconstexpr

4/3 π.

Constant √5.

◆ TwoPiOverThree

double Math::TwoPiOverThree = 2.0943951023931954923084
staticconstexpr

Exponential.

2/3 π.