TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class Maths in Tinman.Core.Math

Provides some commonly used math functions.

static class Maths  

Public / Attributes

NanD

Returns the 64-bit floating point value for: not-a-number.

public static property NanD { get }
type float64
value The NaN value.

NanF

Returns the 32-bit floating point value for: not-a-number.

public static property NanF { get }
type float32
value The NaN value.

NegInfD

Returns the 64-bit floating point value for: negative infinity.

public static property NegInfD { get }
type float64
value The -Inf value.

NegInfF

Returns the 32-bit floating point value for: negative infinity.

public static property NegInfF { get }
type float32
value The -Inf value.

PosInfD

Returns the 64-bit floating point value for: positive infinity.

public static property PosInfD { get }
type float64
value The +Inf value.

PosInfF

Returns the 32-bit floating point value for: positive infinity.

public static property PosInfF { get }
type float32
value The +Inf value.

Public / Constants

DegToRad

Factor for converting radians to degrees.

public constant DegToRad = 0.017453292519943295
type float64

Log10

The natural logarithm of 10.

public constant Log10 = 2.302585092994046
type float64

Log2

The natural logarithm of 2.

public constant Log2 = 0.6931471805599453
type float64

LogBase

Base of natural logarithm.

public constant LogBase = 2.71828182845905
type float64

See also:

Log

MaxDouble

Maximum value of a 64-bit floating-point.

public constant MaxDouble = 1.7976931348623157E+308
type float64

MaxFloat

Maximum value of a 32-bit floating-point.

public constant MaxFloat = 3.4028235E+38
type float32

MaxInt

Maximum value of a 32-bit signed integer.

public constant MaxInt = 2147483647
type int32

MaxLong

Maximum value of a 64-bit signed integer.

public constant MaxLong = 9223372036854775807
type int64

MinDouble

Minimum value of a 64-bit floating-point.

public constant MinDouble = -1.7976931348623157E+308
type float64

MinFloat

Minimum value of a 32-bit floating-point.

public constant MinFloat = -3.4028235E+38
type float32

MinInt

Minimum value of a 32-bit signed integer.

public constant MinInt = -2147483648
type int32

MinLong

Minimum value of a 64-bit signed integer.

public constant MinLong = -9223372036854775808
type int64

Pi

The value of PI (i.e. 180°).

public constant Pi = 3.141592653589793
type float64

PiHalf

The value of PI / 2 (i.e. 90°).

public constant PiHalf = 1.5707963267948966
type float64

PiQuarter

The value of PI / 4 (i.e. 45°).

public constant PiQuarter = 0.7853981633974483
type float64

PiTwo

The value of PI * 2 (i.e. 360°).

public constant PiTwo = 6.283185307179586
type float64

RadToDeg

Factor for converting radians to degrees.

public constant RadToDeg = 57.29577951308232
type float64

Sqrt05

The square root of 0.5.

public constant Sqrt05 = 0.7071067811865476
type float64

Sqrt2

The square root of 2.

public constant Sqrt2 = 1.4142135623730951
type float64

Sqrt3

The square root of 3.

public constant Sqrt3 = 1.7320508075688772
type float64

Public / Methods

Abs

Returns the absolute of the given value.

[Pure]
public static method Abs (float64 value)
type float64
params value The value.
returns [>=0] The absolute value.

Returns the absolute of the given value.

[Pure]
public static method Abs (float32 value)
type float32
params value The value.
returns [>=0] The absolute value.

Returns the absolute of the given value.

[Pure]
public static method Abs (int32 value)
type int32
params value The value.
returns [>=0] The absolute value.

Returns the absolute of the given value.

[Pure]
public static method Abs (int64 value)
type int64
params value The value.
returns [>=0] The absolute value.

Acos

Returns the angle whose cosine is the specified number.

[Pure]
public static method Acos (float64 v)
type float64
params v The number.
returns The angle in radians.

Acosh

Computes the inverse hyperbolic cosine for the given value.

[Pure]
public static method Acosh (float64 v)
type float64
params v The value.
returns The resulting value.

Asin

Returns the angle whose sine is the specified number.

[Pure]
public static method Asin (float64 v)
type float64
params v The number.
returns The angle in radians.

Asinh

Computes the inverse hyperbolic sine for the given value.

[Pure]
public static method Asinh (float64 v)
type float64
params v The value.
returns The resulting value.

Atan

Returns the angle whose tangent is the specified number.

[Pure]
public static method Atan (float64 v)
type float64
params v A number representing a tangent.
returns The angle, in radians.

Atan2

Returns the angle whose tangent is the quotient of two specified numbers.

[Pure]
public static method Atan2 (float64 y, float64 x)
type float64
params y The Y-coordinate of a point.
  x The X-coordinate of a point.
returns [-Pi..Pi] An angle, in radians.

Atanh

Computes the inverse hyperbolic tangent for the given value.

[Pure]
public static method Atanh (float64 v)
type float64
params v The value.
returns The resulting value.

Cbrt

Computes the cubic root of the given number.

[Pure]
public static method Cbrt (float64 x)
type float64
params x The number.
returns The cubic root.

Ceiling

Returns the smallest integer greater than or equal to the specified double-precision floating-point number.

[Pure]
public static method Ceiling (float64 number)
type float64
params number A double-precision floating-point number.
returns The smallest integer greater than or equal to number.

Returns the smallest integer greater than or equal to the specified single-precision floating-point number.

[Pure]
public static method Ceiling (float32 number)
type float32
params number A single-precision floating-point number.
returns The smallest integer greater than or equal to number.

Returns the smallest multiple of divisor that is greater than or equal to value.

[Pure]
public static method Ceiling (int32 value, int32 divisor)
type int32
params value The input value.
  divisor The divisor value (must be greater than 0).
returns The resulting value, divided by divisor.

Returns the smallest multiple of divisor that is greater than or equal to value.

[Pure]
public static method Ceiling (int64 value, int64 divisor)
type int64
params value The input value.
  divisor The divisor value (must be greater than 0).
returns The resulting value, divided by divisor.

Clamp

Clamps the given value.

[Pure]
public static method Clamp (float64 value, float64 lower, float64 upper)
type float64
params value The value.
  lower Lower boundary to clamp to.
  upper Upper boundary to clamp to.
returns The clamped value.

Clamps the given value.

[Pure]
public static method Clamp (float32 value, float32 lower, float32 upper)
type float32
params value The value.
  lower Lower boundary to clamp to.
  upper Upper boundary to clamp to.
returns The clamped value.

Clamps the given value.

[Pure]
public static method Clamp (int32 value, int32 lower, int32 upper)
type int32
params value The value.
  lower Lower boundary to clamp to.
  upper Upper boundary to clamp to.
returns The clamped value.

Clamps the given value.

[Pure]
public static method Clamp (int64 value, int64 lower, int64 upper)
type int64
params value The value.
  lower Lower boundary to clamp to.
  upper Upper boundary to clamp to.
returns The clamped value.

Cos

Returns the cosine of the specified angle.

[Pure]
public static method Cos (float64 radians)
type float64
params radians An angle, measured in radians.
returns The cosine of radians.

Cosh

Computes the hyperbolic cosine of the given value.

[Pure]
public static method Cosh (float64 v)
type float64
params v The value.
returns The hyperbolic cosine of v.

Cot

Returns the co-tangent of the specified angle.

[Pure]
public static method Cot (float64 radians)
type float64
params radians An angle, measured in radians.
returns The co-tangent of radians.

Digits10

Returns the number of decimal digits of the given number.

[Pure]
public static method Digits10 (int64 v)
type int32
params v The number.
returns [>=1] The number of decimal digits.

Div

Computes a / b if b is not 0, returns c otherwise.

[Pure]
public static method Div (int32 a, int32 b, int32 c = 0)
type int32
params a The dividend.
  b The divisor.
  c The value to return if b is 0.
returns The resulting value.

Computes a / b if b is not 0, returns c otherwise.

[Pure]
public static method Div (int64 a, int64 b, int64 c = 0)
type int64
params a The dividend.
  b The divisor.
  c The value to return if b is 0.
returns The resulting value.

EqualOrNan

Tests if the given numbers are equal or if both are 'not-a-number'.

[Pure]
public static method EqualOrNan (float64 a, float64 b)
type bool
params a First number.
  b Second number.
returns true if a and b are equal or both are 'not-a-number', false otherwise.

Exp

Returns e raised to the specified power.

[Pure]
public static method Exp (float64 power)
type float64
params power A number specifying a power.
returns The resulting value.

FastFloor

Computes the integer floor value of the given double value.

[Pure]
public static method FastFloor (float64 x)
type int64
params x The double value.
returns The integer floor value.

Computes the integer floor value of the given float value.

[Pure]
public static method FastFloor (float32 x)
type int32
params x The float value.
returns The integer floor value.

Floor

Computes the floor value of the given value.

[Pure]
public static method Floor (float64 v)
type float64
params v The value.
returns The floor value.

Computes the floor value of the given value.

[Pure]
public static method Floor (float32 v)
type float32
params v The value.
returns The floor value.

Returns the greatest multiple of divisor that is less than or equal to value.

[Pure]
public static method Floor (int32 value, int32 divisor)
type int32
params value The input value.
  divisor The divisor value (must be greater than 0).
returns The resulting value, divided by divisor.

Returns the greatest multiple of divisor that is less than or equal to value.

[Pure]
public static method Floor (int64 value, int64 divisor)
type int64
params value The input value.
  divisor The divisor value (must be greater than 0).
returns The resulting value, divided by divisor.

IsInf

Checks if the given floating point number is +/-Inf (infinity).

[Pure]
public static method IsInf (float64 number)
type bool
params number The number.
returns true if number is +/-Inf, false if not.

IsNan

Checks if the given floating point number is NaN (not-a-number).

[Pure]
public static method IsNan (float64 number)
type bool
params number The number.
returns true if number is NaN, false if not.

IsNegInf

Checks if the given floating point number is -Inf (negative infinity).

[Pure]
public static method IsNegInf (float64 number)
type bool
params number The number.
returns true if number is -Inf, false if not.

IsNumber

Checks if the given floating point number is a regular number (i.e. neither nan nor infinity).

[Pure]
public static method IsNumber (float64 number)
type bool
params number The floating point number.
returns true if number is neither nan nor infinity.

IsPosInf

Checks if the given floating point number is +Inf (positive infinity).

[Pure]
public static method IsPosInf (float64 number)
type bool
params number The number.
returns true if number is +Inf, false if not.

IsPowerOfTwo

Checks if the given value is a power of two.

[Pure]
public static method IsPowerOfTwo (int32 v)
type bool
params v An integer value.
returns true if v is a power of two, false if not.

Remarks:

A value v that satisfies the equation v = 2^n with 0 < n < 31 is said to be a power of two.


Checks if the given value is a power of two.

[Pure]
public static method IsPowerOfTwo (int64 v)
type bool
params v An integer value.
returns true if v is a power of two, false if not.

Remarks:

A value v that satisfies the equation v = 2^n with 0 < n < 31 is said to be a power of two.

IsPrime

Tests if the given number is prime.

[Pure]
public static method IsPrime (int32 value)
type bool
params value The number to test.
returns true if value is prime, false if it is not.

Linear

Returns a linear function that passes through the given points.

public static method Linear (float64 ax, float64 ay, float64 bx, float64 by)
type Vec2D
params ax X-coordinate of first point.
  ay Y-coordinate of first point.
  bx X-coordinate of second point.
  by Y-coordinate of second point.
returns The coefficients m and b, returned as X and Y, respectively.

Remarks:

This method computes the coefficients m and b of the linear function

f(x) = m * x + b
so that the following holds true:
f(ax) = ay
f(bx) = by

Log

Returns the natural (base e) logarithm of a specified number.

[Pure]
public static method Log (float64 number)
type float64
params number A number whose logarithm is to be found.
returns Positive The natural logarithm of number.

See also:

LogBase

Log2_Ceiling

Returns the discrete logarithm of base two of the given value.

[Pure]
public static method Log2_Ceiling (int64 v)
type int32
params v [>0] The value.
returns [0..63] The discrete logarithm of v.

Remarks:

The discrete logarithm of base two is computed as follows:

log2 := ceiling(log(v) / log(2))

Log2_Floor

Returns the discrete logarithm of base two of the given value.

[Pure]
public static method Log2_Floor (int64 v)
type int32
params v [>0] The value.
returns [0..62] The discrete logarithm of v.

Remarks:

The discrete logarithm of base two is computed as follows:

log2 := floor(log(v) / log(2))

Max

Returns the maximum of the given values.

[Pure]
public static method Max (float64 a, float64 b)
type float64
params a First value (can be NaN).
  b Second value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (float32 a, float32 b)
type float32
params a First value (can be NaN).
  b Second value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (int32 a, int32 b)
type int32
params a First value.
  b Second value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (int64 a, int64 b)
type int64
params a First value.
  b Second value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (float64 a, float64 b, float64 c)
type float64
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (float32 a, float32 b, float32 c)
type float32
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (int32 a, int32 b, int32 c)
type int32
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Returns the maximum of the given values.

[Pure]
public static method Max (int64 a, int64 b, int64 c)
type int64
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Min

Returns the minimum of the given values.

[Pure]
public static method Min (float64 a, float64 b)
type float64
params a First value (can be NaN).
  b Second value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (float32 a, float32 b)
type float32
params a First value (can be NaN).
  b Second value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (int32 a, int32 b)
type int32
params a First value.
  b Second value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (int64 a, int64 b)
type int64
params a First value.
  b Second value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (float64 a, float64 b, float64 c)
type float64
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (float32 a, float32 b, float32 c)
type float32
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (int32 a, int32 b, int32 c)
type int32
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Returns the minimum of the given values.

[Pure]
public static method Min (int64 a, int64 b, int64 c)
type int64
params a First value.
  b Second value.
  c Third value.
returns The maximum value.

Mod

Computes the remainder of x / y.

[Pure]
public static method Mod (float64 x, float64 y)
type float64
params x The dividend.
  y The divisor.
returns The value of x-(y*R), where R is equal to x/y, rounded towards zero.

Computes the remainder of x / y.

[Pure]
public static method Mod (float32 x, float32 y)
type float32
params x The dividend.
  y The divisor.
returns The value of x-(y*R), where R is equal to x/y, rounded towards zero.

NextPowerOfTwo

Returns the smallest power of two that is greater than or equal to the given value.

[Pure]
public static method NextPowerOfTwo (int32 v)
type int64
params v The value.
returns [>=1] The next power of two.

Pack3

Packs the given 8-bit integer values into a 32-bit floating-point value.

[Pure]
public static method Pack3 (int32 a, int32 b, int32 c)
type float32
params a [0..255] First integer value to pack.
  b [0..255] Second integer value to pack.
  c [0..255] Third integer value to pack.
returns The packed floating-point value.

See also:

Unpack3

Pack4

Packs the given 6-bit integer values into a 32-bit floating-point value.

[Pure]
public static method Pack4 (int32 a, int32 b, int32 c, int32 d)
type float32
params a [0..63] First integer value to pack.
  b [0..63] Second integer value to pack.
  c [0..63] Third integer value to pack.
  d [0..63] Third integer value to pack.
returns The packed floating-point value.

See also:

Unpack4

Pow

Raises the given value by the specified power.

[Pure]
public static method Pow (float64 value, float64 power)
type float64
params value The value.
  power The power.
returns The resulting value.

Pow10

Returns a discrete power of 10.

[Pure]
public static method Pow10 (int32 v)
type int64
params v The power.
returns The discrete power of 10 or 0 if v is outside of the range [0..18].

Round

Rounds the given number.

[Pure]
public static method Round (float64 value, int32 digits = 0)
type float64
params value The number value to round.
  digits [>=0] The number of fractional digits to keep. Defaults to 0.
returns The resulting number.

Sign

Returns the sign of the given value.

[Pure]
public static method Sign (int64 v)
type int32
params v The value.
returns -1 if v is less than zero. 1 if v is greater than zero or 0 if v is equal to zero.

Returns the sign of the given value.

[Pure]
public static method Sign (float64 v)
type int32
params v The value.
returns -1 if v is less than zero. 1 if v is greater than zero or 0 if v is equal to zero.

Similar

Checks if the given floating-point values are similar.

[Pure]
public static method Similar (float32 a, float32 b)
type bool
params a First value.
  b Second value.
returns true if both values are similar but not necessarily equal, false if they are different.

Checks if the given floating-point values are similar.

[Pure]
public static method Similar (float64 a, float64 b)
type bool
params a First value.
  b Second value.
returns true if both values are similar but not necessarily equal, false if they are different.

Sin

Returns the sine of the specified angle.

[Pure]
public static method Sin (float64 radians)
type float64
params radians An angle, measured in radians.
returns The sine of radians.

Sinh

Computes the hyperbolic sine of the given value.

[Pure]
public static method Sinh (float64 v)
type float64
params v The value.
returns The hyperbolic sine of v.

SmootherStep

Applies a smoothstep function to the given value.

[Pure]
public static method SmootherStep (float64 x)
type float64
params x Interpolation factor in the range [0..1].
returns The smoother interpolation factor f(x).

Remarks:

This method uses the following polynomial:

f(x) = 6 * x^5 - 15 * x^4 + 10 * x^3
f(0) = 0
f(1) = 1
f'(0) = f''(0) = f'(1) = f''(1) = 0
F(0.5) - F(0) = 0.5


Applies a smoothstep function to the given value.

[Pure]
public static method SmootherStep (float64 a, float64 b, float64 f)
type float64
params a First value.
  b Second value.
  f Interpolation factor in the range [0..1].
returns The interpolated value.

Remarks:

This method uses the following polynomial:

f(x) = 6 * x^5 - 15 * x^4 + 10 * x^3
f(0) = 0
f(1) = 1
f'(0) = f''(0) = f'(1) = f''(1) = 0
F(0.5) - F(0) = 0.5

SplineCatmullRom

Mixes the first and second value using a Catmull-Rom spline.

[Pure]
public static method SplineCatmullRom (float64 a, float64 b, float64 c, float64 d, float64 f)
type float64
params a Zeroth value.
  b First value.
  c Second value.
  d Third value.
  f Mix factor.
returns The mixed value.

SplineUniformB

Mixes the first and second value using an Uniform-B spline.

[Pure]
public static method SplineUniformB (float64 a, float64 b, float64 c, float64 d, float64 f)
type float64
params a Zeroth value.
  b First value.
  c Second value.
  d Third value.
  f Mix factor.
returns The mixed value.

Sqr

Returns the square of the given number.

[Pure]
public static method Sqr (float64 number)
type float64
params number The number.
returns The square value.

Returns the square of the given number.

[Pure]
public static method Sqr (float32 number)
type float32
params number The number.
returns The square value.

Sqrt

Returns the square root of a specified number.

[Pure]
public static method Sqrt (float64 number)
type float64
params number A number.
returns The positive square root of number.

Returns the square root of a specified number.

[Pure]
public static method Sqrt (float32 number)
type float32
params number A number.
returns The positive square root of number.

Sqrt_Int

Computes the integer square root of the given value.

[Pure]
public static method Sqrt_Int (int32 value)
type int32
params value The input value.
returns The integer square root of value.

Remarks:

The integer square root is defined as floor(sqrt(v)).


Computes the integer square root of the given value.

[Pure]
public static method Sqrt_Int (int64 value)
type int64
params value The input value.
returns The integer square root of value.

Remarks:

The integer square root is defined as floor(sqrt(v)).

Tan

Returns the tangent of the specified angle.

[Pure]
public static method Tan (float64 radians)
type float64
params radians An angle, measured in radians.
returns The tangent of radians.

Tanh

Computes the hyperbolic tangent of the given value.

[Pure]
public static method Tanh (float64 v)
type float64
params v The value.
returns The hyperbolic tangent of v.

Truncate

Removes all fractional digits from the given number.

[Pure]
public static method Truncate (float64 number)
type float64
params number The number.
returns The truncated number.

Removes all fractional digits from the given number.

[Pure]
public static method Truncate (float32 number)
type float32
params number The number.
returns The truncated number.

Ulp

Returns the value that represents the unit in the last place (ULP) of the given value.

[Pure]
public static method Ulp (float64 v)
type float64
params v The value.
returns The ULP of v.

Remarks:

The ULP is defined as the regular number (see IsNumber) with the smallest possible absolute value (see Abs) for which the following holds true:

v < v + ULP(v)
v > v - ULP(v)
Special cases are treated as follows:
v == NaN <=> ULP(v) == NaN
v == +Inf <=> ULP(v) == +Inf
v == -Inf <=> ULP(v) == -Inf

Unpack3

Unpacks the given 32-bit floating-point value to three 8-bit integer values.

[Pure]
public static method Unpack3 (float32 v)
type Vec3I
params v The packed floating-point value.
returns The unpacked integer values.

See also:

Pack3

Unpack4

Unpacks the given 32-bit floating-point value to four 6-bit integer values.

[Pure]
public static method Unpack4 (float32 v)
type Vec4I
params v The packed floating-point value.
returns The unpacked integer values.

See also:

Pack4

UnsignedCompare

Compares the given values, treating them as unsigned integers.

[Pure]
public static method UnsignedCompare (int64 first, int64 second)
type int32
params first The first value.
  second The second value.
returns -1 if first is less than second
0 if first is equal to second
1 if first is greater than second

UnsignedDivide

Divides the given integers while treating them as unsigned: dividend / divisor.

[Pure]
public static method UnsignedDivide (int64 dividend, int64 divisor)
type int64
params dividend The dividend value.
  divisor The divisor value.
returns The quotient.

UnsignedModulo

Divides the given integers while treating them as unsigned: dividend % divisor.

[Pure]
public static method UnsignedModulo (int64 dividend, int64 divisor)
type int64
params dividend The dividend value.
  divisor The divisor value.
returns The remainder.