Murl::Math Functions

Mathematic functions (Trigonometric, exponential, rounding, etc.). More...

Collaboration diagram for Murl::Math Functions:


This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.

## Functions

template<class DataType >
DataType Murl::Math::Abs (DataType value)
Get the absolute value. More...

template<class DataType >
DataType Murl::Math::Sgn (DataType value)
Get the sign of a value. More...

template<class DataType >
const DataType & Murl::Math::Min (const DataType &x, const DataType &y)
Get the minimum of two values. More...

template<class DataType >
const DataType & Murl::Math::Min (const DataType &x, const DataType &y, const DataType &z)
Get the minimum of three values. More...

template<class DataType >
const DataType & Murl::Math::Min (const DataType &x, const DataType &y, const DataType &z, const DataType &w)
Get the minimum of four values. More...

template<class DataType >
const DataType & Murl::Math::Max (const DataType &x, const DataType &y)
Get the maximum of two values. More...

template<class DataType >
const DataType & Murl::Math::Max (const DataType &x, const DataType &y, const DataType &z)
Get the maximum of three values. More...

template<class DataType >
const DataType & Murl::Math::Max (const DataType &x, const DataType &y, const DataType &z, const DataType &w)
Get the maximum of four values. More...

template<class DataType >
const DataType & Murl::Math::Clamp (const DataType &val, const DataType &min, const DataType &max)
Clamp a value. More...

template<class DataType >
Bool Murl::Math::IsNaN (DataType value)
Check if a value is not a number (NaN). More...

template<class DataType >
Bool Murl::Math::IsInfinite (DataType value)
Check if a value is infinite (either positive infinity or negative infinity). More...

template<class DataType >
Bool Murl::Math::IsFinite (DataType value)
Check if a value is finite. More...

template<class DataType >
DataType Murl::Math::Exp (DataType value)
Get the the e number raised to the power of a value. More...

template<class DataType >
DataType Murl::Math::Log (DataType value)
Get the natural logarithm of a value. More...

template<class DataType >
DataType Murl::Math::Log2 (DataType value)
Get the base 2 logarithm of a value. More...

template<class DataType >
DataType Murl::Math::Log10 (DataType value)
Get the base 10 logarithm of a value. More...

template<class DataType >
DataType Murl::Math::Sqrt (DataType value)
Get the square root of a value. More...

template<class DataType >
DataType Murl::Math::Pow (DataType base, DataType exponent)
Get a base raised to the power of an exponent. More...

template<class DataType >
DataType Murl::Math::Fmod (DataType numerator, DataType denominator)
Get the remainder of a numerator divided by a denominator. More...

template<class DataType >
DataType Murl::Math::ModF (DataType value, DataType &intPart)
Get the integer part and the fractional part of a value. More...

template<class DataType >
DataType Murl::Math::Remainder (DataType numerator, DataType denominator)
Get the IEEE remainder of a numerator divided by a denominator. More...

template<class DataType >
Get the sine of an angle value. More...

template<class DataType >
Get the cosine of an angle value. More...

template<class DataType >
Get the tangent of an angle value. More...

template<class DataType >
DataType Murl::Math::ArcSin (DataType value)
Get the arc sine of a value. More...

template<class DataType >
DataType Murl::Math::ArcCos (DataType value)
Get the arc cosine of a value. More...

template<class DataType >
DataType Murl::Math::ArcTan (DataType value)
Get the arc tangent of a value. More...

template<class DataType >
DataType Murl::Math::ArcTan2 (DataType y, DataType x)
Get the arc tangent of y divided by x. More...

template<class DataType >
DataType Murl::Math::SinHyp (DataType value)
Get the hyperbolic sine of an value. More...

template<class DataType >
DataType Murl::Math::CosHyp (DataType value)
Get the hyperbolic cosine of an value. More...

template<class DataType >
DataType Murl::Math::TanHyp (DataType value)
Get the hyperbolic tangent of an value. More...

template<class DataType >
DataType Murl::Math::ArcSinHyp (DataType value)
Get the hyperbolic arc sine of an value. More...

template<class DataType >
DataType Murl::Math::ArcCosHyp (DataType value)
Get the hyperbolic arc cosine of an value. More...

template<class DataType >
DataType Murl::Math::ArcTanHyp (DataType value)
Get the hyperbolic arc tangent of an value. More...

template<class DataType >
DataType Murl::Math::Floor (DataType value)
Round down to an integral value. More...

template<class DataType >
DataType Murl::Math::Ceil (DataType value)
Round up to an integral value. More...

template<class DataType >
DataType Murl::Math::Round (DataType value)
Round to an integral value, regardless of the rounding direction. More...

template<class DataType >
Bool Murl::Math::IsEqual (const DataType &a, const DataType &b, const DataType &epsilon=Limits< DataType >::Epsilon())
Check if two values are equal within an epsilon range. More...

template<class DataType >

template<class DataType >

template<class DataType >
DataType Murl::Math::MapAngle (DataType angle)
Map an angle into range [-PI . More...

template<class DataType >
DataType Murl::Math::AddAngle (DataType angle1, DataType angle2)
Calculate the sum of two angles. More...

template<class DataType >
DataType Murl::Math::SubAngle (DataType angle1, DataType angle2)
Calculate the difference between two angles. More...

UInt16 Murl::Math::FloatToHalfFloat (Float value)
Convert a given 32bit float value to 16bit ("half float"), represented by a UInt16 integer. More...

UInt16 Murl::Math::IntToHalfFloat (UInt8 value)
Convert a given 8bit unsigned integer value to a 16bit floating point value ("half float"), represented by a UInt16 integer. More...

Float Murl::Math::HalfFloatToFloat (UInt16 value)
Convert a given 16bit half float value stored in a UInt16 to a 32bit float value. More...

UInt8 Murl::Math::HalfFloatToInt (UInt16 value)
Convert a given 16bit half float value stored in a UInt16 to a 8bit unsigned integer value. More...

template<class DataTypeV , class DataTypeT >
DataTypeV Murl::Math::Lerp (const DataTypeV &startValue, const DataTypeV &endValue, DataTypeT t)
The linear interpolation template function. More...

template<class DataTypeT >
Double Murl::Math::Lerp (Double startValue, Double endValue, DataTypeT t)
The linear interpolation template function for Double. More...

template<class DataType >
Easing< DataType >::Interpolate Murl::Math::GetEasingFunction (IEnums::Interpolation interpolation)
Get the Easing::Interpolate function for a specified interpolation. More...

template<class DataType >
DataType Murl::Math::Interpolation (IEnums::Interpolation interpolation, DataType x)
The interpolation template function calculates the IEnums::Interpolation curve (easing function). More...

## Detailed Description

Mathematic functions (Trigonometric, exponential, rounding, etc.).

Basic mathematic functions available for Float and Double data type.

## ◆ Abs()

template<class DataType >
 DataType Murl::Math::Abs ( DataType value )

## ◆ Sgn()

template<class DataType >
 DataType Murl::Math::Sgn ( DataType value )

Get the sign of a value.

Parameters
 value The input value.
Returns
1 if the value is positive, -1 if the value is negative or zero if the value is zero.

## ◆ Min() [1/3]

template<class DataType >
 const DataType& Murl::Math::Min ( const DataType & x, const DataType & y )

Get the minimum of two values.

If both are equivalent, x is returned.

Parameters
 x The 1st value. y The 2nd value.
Returns
The lesser value of x and y.

## ◆ Min() [2/3]

template<class DataType >
 const DataType& Murl::Math::Min ( const DataType & x, const DataType & y, const DataType & z )

Get the minimum of three values.

If all are equivalent, x is returned.

Parameters
 x The 1st value. y The 2nd value. z The 3rd value.
Returns
The lowest value of x, y and z.

References Murl::Math::Min().

## ◆ Min() [3/3]

template<class DataType >
 const DataType& Murl::Math::Min ( const DataType & x, const DataType & y, const DataType & z, const DataType & w )

Get the minimum of four values.

If all are equivalent, x is returned.

Parameters
 x The 1st value. y The 2nd value. z The 3rd value. w The 4th value.
Returns
The lowest value of x, y, z and w.

References Murl::Math::Min().

## ◆ Max() [1/3]

template<class DataType >
 const DataType& Murl::Math::Max ( const DataType & x, const DataType & y )

Get the maximum of two values.

If both are equivalent, x is returned.

Parameters
 x The 1st value. y The 2nd value.
Returns
The greater value of x and y.

## ◆ Max() [2/3]

template<class DataType >
 const DataType& Murl::Math::Max ( const DataType & x, const DataType & y, const DataType & z )

Get the maximum of three values.

If all are equivalent, x is returned.

Parameters
 x The 1st value. y The 2nd value. z The 3rd value.
Returns
The highest value of x, y and z.

References Murl::Math::Max().

## ◆ Max() [3/3]

template<class DataType >
 const DataType& Murl::Math::Max ( const DataType & x, const DataType & y, const DataType & z, const DataType & w )

Get the maximum of four values.

If all are equivalent, x is returned.

Parameters
 x The 1st value. y The 2nd value. z The 3rd value. w The 4th value.
Returns
The highest value of x, y, z and w.

References Murl::Math::Max().

## ◆ Clamp()

template<class DataType >
 const DataType& Murl::Math::Clamp ( const DataType & val, const DataType & min, const DataType & max )

Clamp a value.

Parameters
 val The value to clamp. min The minimum value. max The maximum value.
Returns
The value clamped in range [min .. max].

## ◆ IsNaN()

template<class DataType >
 Bool Murl::Math::IsNaN ( DataType value )

Check if a value is not a number (NaN).

The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the result of 0/0.

Parameters
 value The value to check.
Returns
true if the value is not a number (NaN).

Referenced by Murl::Math::Clamp().

## ◆ IsInfinite()

template<class DataType >
 Bool Murl::Math::IsInfinite ( DataType value )

Check if a value is infinite (either positive infinity or negative infinity).

Parameters
 value The value to check.
Returns
true if the value is an infinity value.

Referenced by Murl::Math::Clamp().

## ◆ IsFinite()

template<class DataType >
 Bool Murl::Math::IsFinite ( DataType value )

Check if a value is finite.

A finite value is any floating-point value that is neither infinite nor NaN.

Parameters
 value The value to check.
Returns
true if the value is finite.

Referenced by Murl::Math::Clamp().

## ◆ Exp()

template<class DataType >
 DataType Murl::Math::Exp ( DataType value )

Get the the e number raised to the power of a value.

Parameters
 value The input value.
Returns
The the e number raised to the power of the value.

Referenced by Murl::Util::GaussianFilter::Apply(), and Murl::Math::Clamp().

## ◆ Log()

template<class DataType >
 DataType Murl::Math::Log ( DataType value )

Get the natural logarithm of a value.

Parameters
 value The input value.
Returns
The natural logarithm of the value.

Referenced by Murl::Math::Clamp().

## ◆ Log2()

template<class DataType >
 DataType Murl::Math::Log2 ( DataType value )

Get the base 2 logarithm of a value.

Parameters
 value The input value.
Returns
The base 2 logarithm of the value.

Referenced by Murl::Math::Clamp().

## ◆ Log10()

template<class DataType >
 DataType Murl::Math::Log10 ( DataType value )

Get the base 10 logarithm of a value.

Parameters
 value The input value.
Returns
The base 10 logarithm of the value.

Referenced by Murl::Math::Clamp().

## ◆ Sqrt()

template<class DataType >
 DataType Murl::Math::Sqrt ( DataType value )

## ◆ Pow()

template<class DataType >
 DataType Murl::Math::Pow ( DataType base, DataType exponent )

Get a base raised to the power of an exponent.

Parameters
 base The base input value. exponent The exponent input value.
Returns
The base raised to the power of the exponent.

## ◆ Fmod()

template<class DataType >
 DataType Murl::Math::Fmod ( DataType numerator, DataType denominator )

Get the remainder of a numerator divided by a denominator.

Parameters
 numerator The numerator input value. denominator The denominator input value.
Returns
The remainder of the numerator divided by the denominator.

## ◆ ModF()

template<class DataType >
 DataType Murl::Math::ModF ( DataType value, DataType & intPart )

Get the integer part and the fractional part of a value.

Parameters
 value The input value. intPart The integer part return value.
Returns
The fractional part of the value.

Referenced by Murl::Math::Clamp().

## ◆ Remainder()

template<class DataType >
 DataType Murl::Math::Remainder ( DataType numerator, DataType denominator )

Get the IEEE remainder of a numerator divided by a denominator.

Parameters
 numerator The numerator input value. denominator The denominator input value.
Returns
The IEEE remainder of the numerator divided by the denominator.

Referenced by Murl::Math::Clamp().

## ◆ Sin()

template<class DataType >
 DataType Murl::Math::Sin ( DataType radAngle )

Get the sine of an angle value.

Parameters
Returns
The sine of the angle value.

## ◆ Cos()

template<class DataType >
 DataType Murl::Math::Cos ( DataType radAngle )

Get the cosine of an angle value.

Parameters
Returns
The cosine of the angle value.

## ◆ Tan()

template<class DataType >
 DataType Murl::Math::Tan ( DataType radAngle )

Get the tangent of an angle value.

Parameters
Returns
The tangent of the angle value.

Referenced by Murl::Math::Clamp(), and Murl::Math::Cone< Real >::Cone().

## ◆ ArcSin()

template<class DataType >
 DataType Murl::Math::ArcSin ( DataType value )

Get the arc sine of a value.

Parameters
 value The input value.
Returns
The arc sine of the value in radiants.

Referenced by Murl::Math::Clamp().

## ◆ ArcCos()

template<class DataType >
 DataType Murl::Math::ArcCos ( DataType value )

Get the arc cosine of a value.

Parameters
 value The input value.
Returns
The arc cosine of the value in radiants.

## ◆ ArcTan()

template<class DataType >
 DataType Murl::Math::ArcTan ( DataType value )

Get the arc tangent of a value.

Parameters
 value The input value.
Returns
The arc tangent of the value in radiants.

Referenced by Murl::Math::Clamp(), and Murl::Math::Cone< Real >::Set().

## ◆ ArcTan2()

template<class DataType >
 DataType Murl::Math::ArcTan2 ( DataType y, DataType x )

Get the arc tangent of y divided by x.

The function uses the sign of both arguments to determine the quadrant.

Parameters
 y The y input value. x The x input value.
Returns
The arc tangent of y divided by x in radiants.

Referenced by Murl::Math::Clamp(), and Murl::Math::Matrix< Real >::GetEulerRotation().

## ◆ SinHyp()

template<class DataType >
 DataType Murl::Math::SinHyp ( DataType value )

Get the hyperbolic sine of an value.

Parameters
 value The input value.
Returns
The hyperbolic sine of the value.

Referenced by Murl::Math::Clamp().

## ◆ CosHyp()

template<class DataType >
 DataType Murl::Math::CosHyp ( DataType value )

Get the hyperbolic cosine of an value.

Parameters
 value The input value.
Returns
The hyperbolic cosine of the value.

Referenced by Murl::Math::Clamp().

## ◆ TanHyp()

template<class DataType >
 DataType Murl::Math::TanHyp ( DataType value )

Get the hyperbolic tangent of an value.

Parameters
 value The input value.
Returns
The hyperbolic tangent of the value.

Referenced by Murl::Math::Clamp().

## ◆ ArcSinHyp()

template<class DataType >
 DataType Murl::Math::ArcSinHyp ( DataType value )

Get the hyperbolic arc sine of an value.

Parameters
 value The input value.
Returns
The hyperbolic arc sine of the value.

Referenced by Murl::Math::Clamp().

## ◆ ArcCosHyp()

template<class DataType >
 DataType Murl::Math::ArcCosHyp ( DataType value )

Get the hyperbolic arc cosine of an value.

Parameters
 value The input value.
Returns
The hyperbolic arc cosine of the value.

Referenced by Murl::Math::Clamp().

## ◆ ArcTanHyp()

template<class DataType >
 DataType Murl::Math::ArcTanHyp ( DataType value )

Get the hyperbolic arc tangent of an value.

Parameters
 value The input value.
Returns
The hyperbolic arc tangent of the value.

Referenced by Murl::Math::Clamp().

## ◆ Floor()

template<class DataType >
 DataType Murl::Math::Floor ( DataType value )

Round down to an integral value.

Parameters
 value The input value.
Returns
The round down integral value.

Referenced by Murl::Math::Clamp(), and Murl::Math::Round().

## ◆ Ceil()

template<class DataType >
 DataType Murl::Math::Ceil ( DataType value )

Round up to an integral value.

Parameters
 value The input value.
Returns
The round up integral value.

Referenced by Murl::Math::Clamp(), and Murl::Math::Round().

## ◆ Round()

template<class DataType >
 DataType Murl::Math::Round ( DataType value )

Round to an integral value, regardless of the rounding direction.

Rounding half-way cases away from zero.

Parameters
 value The input value.
Returns
The rounded integral value.

References Murl::Math::Ceil(), and Murl::Math::Floor().

## ◆ IsEqual()

template<class DataType >
 Bool Murl::Math::IsEqual ( const DataType & a, const DataType & b, const DataType & epsilon = Limits::Epsilon() )

Check if two values are equal within an epsilon range.

Parameters
 a The 1st value. b The 2nd value. epsilon The epsilon value.
Returns
true if Abs(a - b) is within epsilon range.

References Murl::Math::Abs().

template<class DataType >
 DataType Murl::Math::DegToRad ( DataType degrees )

Parameters
 degrees The degrees to convert.
Returns

template<class DataType >

Parameters
Returns
The degrees.

## ◆ MapAngle()

template<class DataType >
 DataType Murl::Math::MapAngle ( DataType angle )

Map an angle into range [-PI .

. PI).

Parameters
 angle The angle value in radiants.
Returns
The mapped angle in range [-PI .. PI).

References Murl::Math::Fmod(), Murl::Math::PI, and Murl::Math::TWO_PI.

template<class DataType >
 DataType Murl::Math::AddAngle ( DataType angle1, DataType angle2 )

Calculate the sum of two angles.

Parameters
 angle1 The first angle value in radiants. angle2 The second angle value in radiants.
Returns
The result of (angle1 + angle2) in range [-PI .. PI).

References Murl::Math::MapAngle().

## ◆ SubAngle()

template<class DataType >
 DataType Murl::Math::SubAngle ( DataType angle1, DataType angle2 )

Calculate the difference between two angles.

Parameters
 angle1 The first angle value in radiants. angle2 The second angle value in radiants.
Returns
The result of (angle1 - angle2) in range [-PI .. PI).

References Murl::Math::MapAngle().

## ◆ FloatToHalfFloat()

 UInt16 Murl::Math::FloatToHalfFloat ( Float value )
inline

Convert a given 32bit float value to 16bit ("half float"), represented by a UInt16 integer.

Parameters
 value The 32bit float value to convert
Returns
The half float value as an UInt16.

References Murl::Math::Clamp().

Referenced by Murl::Math::IntToHalfFloat().

## ◆ IntToHalfFloat()

 UInt16 Murl::Math::IntToHalfFloat ( UInt8 value )
inline

Convert a given 8bit unsigned integer value to a 16bit floating point value ("half float"), represented by a UInt16 integer.

The input value is divided by 255.

Parameters
 value The 8bit unsigned integer value to convert
Returns
The half float value as an UInt16.

References Murl::Math::FloatToHalfFloat().

## ◆ HalfFloatToFloat()

 Float Murl::Math::HalfFloatToFloat ( UInt16 value )
inline

Convert a given 16bit half float value stored in a UInt16 to a 32bit float value.

Parameters
 value The 16bit float value to convert
Returns
The converted 32bit float value

References Murl::Math::Clamp().

Referenced by Murl::Math::HalfFloatToInt().

## ◆ HalfFloatToInt()

 UInt8 Murl::Math::HalfFloatToInt ( UInt16 value )
inline

Convert a given 16bit half float value stored in a UInt16 to a 8bit unsigned integer value.

The output value is multiplied by 255.

Parameters
 value The 16bit float value to convert
Returns
The converted 8bit unsigned integer value

References Murl::Math::Clamp(), and Murl::Math::HalfFloatToFloat().

## ◆ Lerp() [1/2]

template<class DataTypeV , class DataTypeT >
 DataTypeV Murl::Math::Lerp ( const DataTypeV & startValue, const DataTypeV & endValue, DataTypeT t )

The linear interpolation template function.

Parameters
 startValue The start value to interpolate. endValue The end value to interpolate. t The parameter to interpolate in range [0 .. 1].
Returns
The interpolation between the inputs startValue and endValue for a parameter t in the closed unit interval [0 .. 1].

Referenced by Murl::Logic::Animation< Vector >::OnEvaluate().

## ◆ Lerp() [2/2]

template<class DataTypeT >
 Double Murl::Math::Lerp ( Double startValue, Double endValue, DataTypeT t )

The linear interpolation template function for Double.

Parameters
 startValue The start value to interpolate. endValue The end value to interpolate. t The parameter to interpolate in range [0 .. 1].
Returns
The interpolation between the inputs startValue and endValue for a parameter t in the closed unit interval [0 .. 1].

## ◆ Interpolation()

template<class DataType >
 DataType Murl::Math::Interpolation ( IEnums::Interpolation interpolation, DataType x )

The interpolation template function calculates the IEnums::Interpolation curve (easing function).

Parameters
 interpolation The interpolation. x The value to interpolate in range [0 .. 1].
Returns
The easing function result.