Maths

Description

static class Tinman.Core.Math.Maths

Provides some commonly used math functions.

Public / Constants

Deg​To​Rad


public constant DegToRad → (0.017453292519943295:float64)

Factor for converting radians to degrees.

Log10


public constant Log10 → (2.302585092994046:float64)

The natural logarithm of 10.

Log2


public constant Log2 → (0.6931471805599453:float64)

The natural logarithm of 2.

Log​Base


public constant LogBase → (2.718281828459045:float64)

Base of natural logarithm.

See also

Maths.Log

Max​Double


public constant MaxDouble → (1.7976931348623157E+308:float64)

Maximum value of a 64-bit floating-point.

Max​Float


public constant MaxFloat → (3.4028235E+38:float32)

Maximum value of a 32-bit floating-point.

Max​Int


public constant MaxInt → (2147483647:int32)

Maximum value of a 32-bit signed integer.

Max​Long


public constant MaxLong → (9223372036854775807:int64)

Maximum value of a 64-bit signed integer.

Min​Double


public constant MinDouble → (-1.7976931348623157E+308:float64)

Minimum value of a 64-bit floating-point.

Min​Float


public constant MinFloat → (-3.4028235E+38:float32)

Minimum value of a 32-bit floating-point.

Min​Int


public constant MinInt → (-2147483648:int32)

Minimum value of a 32-bit signed integer.

Min​Long


public constant MinLong → (-9223372036854775808:int64)

Minimum value of a 64-bit signed integer.

Pi


public constant Pi → (3.141592653589793:float64)

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

Pi​Half


public constant PiHalf → (1.5707963267948966:float64)

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

Pi​Quarter


public constant PiQuarter → (0.7853981633974483:float64)

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

Pi​Two


public constant PiTwo → (6.283185307179586:float64)

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

Rad​To​Deg


public constant RadToDeg → (57.29577951308232:float64)

Factor for converting radians to degrees.

Sqrt05


public constant Sqrt05 → (0.7071067811865476:float64)

The square root of 0.5.

Sqrt2


public constant Sqrt2 → (1.4142135623730951:float64)

The square root of 2.

Sqrt3


public constant Sqrt3 → (1.7320508075688772:float64)

The square root of 3.

Ulp​Double


public constant UlpDouble → (5E-324:float64)

The value of Ulp for 0.

Public / Methods

Abs

4 overloads


[Pure]
public static method Abs1 → (1)

value in : float64

The value.

returns → float64

The absolute value.

Returns the absolute of the given value.


[Pure]
public static method Abs2 → (1)

value in : float32

The value.

returns → float32

The absolute value.

Returns the absolute of the given value.


[Pure]
public static method Abs3 → (1)

value in : int32

The value.

returns → int32

The absolute value.

Returns the absolute of the given value.


[Pure]
public static method Abs4 → (1)

value in : int64

The value.

returns → int64

The absolute value.

Returns the absolute of the given value.

Acos


[Pure]
public static method Acos → (1)

in : float64

The number.

returns → float64

The angle in radians.

Returns the angle whose cosine is the specified number.

Acosh


[Pure]
public static method Acosh → (1)

in : float64

The value.

returns → float64

The resulting value.

Computes the inverse hyperbolic cosine for the given value.

Asin


[Pure]
public static method Asin → (1)

in : float64

The number.

returns → float64

The angle in radians.

Returns the angle whose sine is the specified number.

Asinh


[Pure]
public static method Asinh → (1)

in : float64

The value.

returns → float64

The resulting value.

Computes the inverse hyperbolic sine for the given value.

Atan


[Pure]
public static method Atan → (1)

in : float64

A number representing a tangent.

returns → float64

The angle, in radians.

Returns the angle whose tangent is the specified number.

Atan2


[Pure]
public static method Atan2 → (2)

in : float64

The Y-coordinate of a point.

in : float64

The X-coordinate of a point.

returns → float64

[-Pi..Pi] An angle, in radians.

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

Atanh


[Pure]
public static method Atanh → (1)

in : float64

The value.

returns → float64

The resulting value.

Computes the inverse hyperbolic tangent for the given value.

Cbrt


[Pure]
public static method Cbrt → (1)

in : float64

The number.

returns → float64

The cubic root.

Computes the cubic root of the given number.

Ceiling

4 overloads


[Pure]
public static method Ceiling1 → (1)

number in : float64

A double-precision floating-point number.

returns → float64

The smallest integer greater than or equal to number in.

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


[Pure]
public static method Ceiling2 → (1)

number in : float32

A single-precision floating-point number.

returns → float32

The smallest integer greater than or equal to number in.

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


[Pure]
public static method Ceiling3 → (2)

value in : int32

The input value.

divisor in : int32

The divisor value (must be greater than 0).

returns → int32

The resulting value, divided by divisor in.

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


[Pure]
public static method Ceiling4 → (2)

value in : int64

The input value.

divisor in : int64

The divisor value (must be greater than 0).

returns → int64

The resulting value, divided by divisor in.

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

Clamp

4 overloads


[Pure]
public static method Clamp1 → (3)

value in : float64

The value.

lower in : float64

Lower boundary to clamp to.

upper in : float64

Upper boundary to clamp to.

returns → float64

The clamped value.

Clamps the given value.


[Pure]
public static method Clamp2 → (3)

value in : float32

The value.

lower in : float32

Lower boundary to clamp to.

upper in : float32

Upper boundary to clamp to.

returns → float32

The clamped value.

Clamps the given value.


[Pure]
public static method Clamp3 → (3)

value in : int32

The value.

lower in : int32

Lower boundary to clamp to.

upper in : int32

Upper boundary to clamp to.

returns → int32

The clamped value.

Clamps the given value.


[Pure]
public static method Clamp4 → (3)

value in : int64

The value.

lower in : int64

Lower boundary to clamp to.

upper in : int64

Upper boundary to clamp to.

returns → int64

The clamped value.

Clamps the given value.

Cos


[Pure]
public static method Cos → (1)

radians in : float64

An angle, measured in radians.

returns → float64

The cosine of radians in.

Returns the cosine of the specified angle.

Cosh


[Pure]
public static method Cosh → (1)

in : float64

The value.

returns → float64

The hyperbolic cosine of in.

Computes the hyperbolic cosine of the given value.

Cot


[Pure]
public static method Cot → (1)

radians in : float64

An angle, measured in radians.

returns → float64

The co-tangent of radians in.

Returns the co-tangent of the specified angle.

Digits10


[Pure]
public static method Digits10 → (1)

in : int64

The number.

returns → int32

The number of decimal digits.

Returns the number of decimal digits of the given number.

Div

2 overloads


[Pure]
public static method Div1 → (3)

in : int32

The dividend.

in : int32

The divisor.

opt : int32 = 0

The value to return if in is 0.

returns → int32

The resulting value.

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


[Pure]
public static method Div2 → (3)

in : int64

The dividend.

in : int64

The divisor.

opt : int64 = 0

The value to return if in is 0.

returns → int64

The resulting value.

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

Equal​Or​Nan


[Pure]
public static method EqualOrNan → (2)

in : float64

First number.

in : float64

Second number.

returns → bool

true if in and in are equal or both are 'not-a-number', false otherwise.

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

Exp


[Pure]
public static method Exp → (1)

power in : float64

A number specifying a power.

returns → float64

The resulting value.

Returns e raised to the specified power.

Fast​Floor

2 overloads


[Pure]
public static method FastFloor1 → (1)

in : float64

The double value.

returns → int64

The integer floor value.

Computes the integer floor value of the given double value.


[Pure]
public static method FastFloor2 → (1)

in : float32

The float value.

returns → int32

The integer floor value.

Computes the integer floor value of the given float value.

Floor

4 overloads


[Pure]
public static method Floor1 → (1)

in : float64

The value.

returns → float64

The floor value.

Computes the floor value of the given value.


[Pure]
public static method Floor2 → (1)

in : float32

The value.

returns → float32

The floor value.

Computes the floor value of the given value.


[Pure]
public static method Floor3 → (2)

value in : int32

The input value.

divisor in : int32

The divisor value (must be greater than 0).

returns → int32

The resulting value, divided by divisor in.

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


[Pure]
public static method Floor4 → (2)

value in : int64

The input value.

divisor in : int64

The divisor value (must be greater than 0).

returns → int64

The resulting value, divided by divisor in.

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

Is​Inf


[Pure]
public static method IsInf → (1)

number in : float64

The number.

returns → bool

true if number in is +/-Inf, false if not.

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

Is​Nan


[Pure]
public static method IsNan → (1)

number in : float64

The number.

returns → bool

true if number in is NaN, false if not.

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

Is​Neg​Inf


[Pure]
public static method IsNegInf → (1)

number in : float64

The number.

returns → bool

true if number in is -Inf, false if not.

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

Is​Number


[Pure]
public static method IsNumber → (1)

number in : float64

The floating point number.

returns → bool

true if number in is neither nan nor infinity.

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

Is​Pos​Inf


[Pure]
public static method IsPosInf → (1)

number in : float64

The number.

returns → bool

true if number in is +Inf, false if not.

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

Is​Power​Of​Two

2 overloads


[Pure]
public static method IsPowerOfTwo1 → (1)

in : int32

An integer value.

returns → bool

true if in is a power of two, false if not.

Checks if the given value is a power of two.

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


[Pure]
public static method IsPowerOfTwo2 → (1)

in : int64

An integer value.

returns → bool

true if in is a power of two, false if not.

Checks if the given value is a power of two.

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

Is​Prime


[Pure]
public static method IsPrime → (1)

value in : int32

The number to test.

returns → bool

true if value in is prime, false if it is not.

Tests if the given number is prime.

Linear


public static method Linear → (4)

ax in : float64

X-coordinate of first point.

ay in : float64

Y-coordinate of first point.

bx in : float64

X-coordinate of second point.

by in : float64

Y-coordinate of second point.

returns → Vec2D

The coefficients m and b, returned as Vec2D.X and Vec2D.Y, respectively.

Returns a linear function that passes through the given points.

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


[Pure]
public static method Log → (1)

number in : float64

A number whose logarithm is to be found.

returns → float64

Positive The natural logarithm of number in.

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

See also

Maths.LogBase

Log2_​Ceiling


[Pure]
public static method Log2_Ceiling → (1)

in : int64

[>0]
The value.

returns → int32

The discrete logarithm of in.

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

The discrete logarithm of base two is computed as follows:

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

Log2_​Floor


[Pure]
public static method Log2_Floor → (1)

in : int64

[>0]
The value.

returns → int32

The discrete logarithm of in.

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

The discrete logarithm of base two is computed as follows:

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

Max

8 overloads


[Pure]
public static method Max1 → (2)

in : float64

First value (can be NaN).

in : float64

Second value.

returns → float64

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max2 → (3)

in : float64

First value.

in : float64

Second value.

in : float64

Third value.

returns → float64

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max3 → (2)

in : float32

First value (can be NaN).

in : float32

Second value.

returns → float32

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max4 → (3)

in : float32

First value.

in : float32

Second value.

in : float32

Third value.

returns → float32

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max5 → (2)

in : int32

First value.

in : int32

Second value.

returns → int32

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max6 → (3)

in : int32

First value.

in : int32

Second value.

in : int32

Third value.

returns → int32

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max7 → (2)

in : int64

First value.

in : int64

Second value.

returns → int64

The maximum value.

Returns the maximum of the given values.


[Pure]
public static method Max8 → (3)

in : int64

First value.

in : int64

Second value.

in : int64

Third value.

returns → int64

The maximum value.

Returns the maximum of the given values.

Min

8 overloads


[Pure]
public static method Min1 → (2)

in : float64

First value (can be NaN).

in : float64

Second value.

returns → float64

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min2 → (3)

in : float64

First value.

in : float64

Second value.

in : float64

Third value.

returns → float64

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min3 → (2)

in : float32

First value (can be NaN).

in : float32

Second value.

returns → float32

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min4 → (3)

in : float32

First value.

in : float32

Second value.

in : float32

Third value.

returns → float32

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min5 → (2)

in : int32

First value.

in : int32

Second value.

returns → int32

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min6 → (3)

in : int32

First value.

in : int32

Second value.

in : int32

Third value.

returns → int32

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min7 → (2)

in : int64

First value.

in : int64

Second value.

returns → int64

The maximum value.

Returns the minimum of the given values.


[Pure]
public static method Min8 → (3)

in : int64

First value.

in : int64

Second value.

in : int64

Third value.

returns → int64

The maximum value.

Returns the minimum of the given values.

Mod

2 overloads


[Pure]
public static method Mod1 → (2)

in : float64

The dividend.

in : float64

The divisor.

returns → float64

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 Mod2 → (2)

in : float32

The dividend.

in : float32

The divisor.

returns → float32

The value of x-(y*R), where R is equal to x/y, rounded towards zero.

Computes the remainder of x / y.

Next​Power​Of​Two


[Pure]
public static method NextPowerOfTwo → (1)

in : int32

The value.

returns → int64

The next power of two.

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

Pack3


[Pure]
public static method Pack3 → (3)

in : int32

[0..255]
First integer value to pack.

in : int32

[0..255]
Second integer value to pack.

in : int32

[0..255]
Third integer value to pack.

returns → float32

The packed floating-point value.

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

See also

Maths.Unpack3

Pack4


[Pure]
public static method Pack4 → (4)

in : int32

[0..63]
First integer value to pack.

in : int32

[0..63]
Second integer value to pack.

in : int32

[0..63]
Third integer value to pack.

in : int32

[0..63]
Third integer value to pack.

returns → float32

The packed floating-point value.

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

See also

Maths.Unpack4

Pow


[Pure]
public static method Pow → (2)

value in : float64

The value.

power in : float64

The power.

returns → float64

The resulting value.

Raises the given value by the specified power.

Pow10


[Pure]
public static method Pow10 → (1)

in : int32

The power.

returns → int64

The discrete power of 10 or 0 if in is outside of the range [0..18].

Returns a discrete power of 10.

Round


[Pure]
public static method Round → (2)

value in : float64

The number value to round.

digits opt : int32 = 0

[>=0]
The number of fractional digits to keep.

returns → float64

The resulting number.

Rounds the given number.

The given value in is round to the nearest integral value, breaking ties in favour of the integral value that has the greater value:

  -3    -2    -1     0    +1    +2    +3      input value
.  |  .  |  .  |  .  |  .  |  .  |  .  |  .
-------------------------------------------
[ -3  [ -2  [ -1  [  0  [ +1  [ +2  [ +3  [   round value

Sign

2 overloads


[Pure]
public static method Sign1 → (1)

in : int64

The value.

returns → int32

-1 if in is less than zero. 1 if in is greater than zero or 0 if in is equal to zero.

Returns the sign of the given value.


[Pure]
public static method Sign2 → (1)

in : float64

The value.

returns → int32

-1 if in is less than zero. 1 if in is greater than zero or 0 if in is equal to zero.

Returns the sign of the given value.

Similar

2 overloads


[Pure]
public static method Similar1 → (2)

in : float32

First value.

in : float32

Second value.

returns → bool

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 Similar2 → (2)

in : float64

First value.

in : float64

Second value.

returns → bool

true if both values are similar but not necessarily equal, false if they are different.

Checks if the given floating-point values are similar.

Sin


[Pure]
public static method Sin → (1)

radians in : float64

An angle, measured in radians.

returns → float64

The sine of radians in.

Returns the sine of the specified angle.

Sinh


[Pure]
public static method Sinh → (1)

in : float64

The value.

returns → float64

The hyperbolic sine of in.

Computes the hyperbolic sine of the given value.

Smoother​Step

2 overloads


[Pure]
public static method SmootherStep1 → (1)

in : float64

Interpolation factor in the range [0..1].

returns → float64

The smoother interpolation factor f(x).

Applies a smoothstep function to the given value.

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

[Pure]
public static method SmootherStep2 → (3)

in : float64

First value.

in : float64

Second value.

in : float64

Interpolation factor in the range [0..1].

returns → float64

The interpolated value.

Applies a smoothstep function to the given value.

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

Spline​Catmull​Rom

2 overloads


[Pure]
public static method SplineCatmullRom1 → (1)

in : float64

Mix factor.

returns → Vec4D

The interpolation weights.

Computes the interpolation weights for a Catmull-Rom spline.


[Pure]
public static method SplineCatmullRom2 → (5)

in : float64

Zeroth value.

in : float64

First value.

in : float64

Second value.

in : float64

Third value.

in : float64

Mix factor.

returns → float64

The mixed value.

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

Spline​Hermite


[Pure]
public static method SplineHermite → (5)

p0 in : float64

First position value.

t0 in : float64

First tangent value.

p1 in : float64

Second position value.

t1 in : float64

Second tangent value.

in : float64

Mix factor.

returns → float64

The mixed value.

Mixes the first and second value using a Hermite spline.

Spline​Uniform​B

2 overloads


[Pure]
public static method SplineUniformB1 → (1)

in : float64

Mix factor.

returns → Vec4D

The interpolation weights.

Computes the interpolation weights for an Uniform-B spline.


[Pure]
public static method SplineUniformB2 → (5)

in : float64

Zeroth value.

in : float64

First value.

in : float64

Second value.

in : float64

Third value.

in : float64

Mix factor.

returns → float64

The mixed value.

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

Sqr

2 overloads


[Pure]
public static method Sqr1 → (1)

number in : float64

The number.

returns → float64

The square value.

Returns the square of the given number.


[Pure]
public static method Sqr2 → (1)

number in : float32

The number.

returns → float32

The square value.

Returns the square of the given number.

Sqrt

2 overloads


[Pure]
public static method Sqrt1 → (1)

number in : float64

A number.

returns → float64

The positive square root of number in.

Returns the square root of a specified number.


[Pure]
public static method Sqrt2 → (1)

number in : float32

A number.

returns → float32

The positive square root of number in.

Returns the square root of a specified number.

Sqrt_​Int

2 overloads


[Pure]
public static method Sqrt_Int1 → (1)

value in : int32

The input value.

returns → int32

The integer square root of value in.

Computes the integer square root of the given value.

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


[Pure]
public static method Sqrt_Int2 → (1)

value in : int64

The input value.

returns → int64

The integer square root of value in.

Computes the integer square root of the given value.

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

Tan


[Pure]
public static method Tan → (1)

radians in : float64

An angle, measured in radians.

returns → float64

The tangent of radians in.

Returns the tangent of the specified angle.

Tanh


[Pure]
public static method Tanh → (1)

in : float64

The value.

returns → float64

The hyperbolic tangent of in.

Computes the hyperbolic tangent of the given value.

Truncate

2 overloads


[Pure]
public static method Truncate1 → (1)

number in : float64

The number.

returns → float64

The truncated number.

Removes all fractional digits from the given number.


[Pure]
public static method Truncate2 → (1)

number in : float32

The number.

returns → float32

The truncated number.

Removes all fractional digits from the given number.

Ulp


[Pure]
public static method Ulp → (1)

in : float64

The value.

returns → float64

The ULP of in.

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

The ULP is defined as the regular number (see IsNumber) with the smallest possible absolute value (see Abs1) 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


[Pure]
public static method Unpack3 → (1)

in : float32

The packed floating-point value.

returns → Vec3I

The unpacked integer values.

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

See also

Maths.Pack3

Unpack4


[Pure]
public static method Unpack4 → (1)

in : float32

The packed floating-point value.

returns → Vec4I

The unpacked integer values.

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

See also

Maths.Pack4

Unsigned​Compare


[Pure]
public static method UnsignedCompare → (2)

first in : int64

The first value.

second in : int64

The second value.

returns → int32

-1 if first in is less than second in
0 if first in is equal to second in
1 if first in is greater than second in

Compares the given values, treating them as unsigned integers.

Unsigned​Divide


[Pure]
public static method UnsignedDivide → (2)

dividend in : int64

The dividend value.

divisor in : int64

The divisor value.

returns → int64

The quotient.

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

Unsigned​Modulo


[Pure]
public static method UnsignedModulo → (2)

dividend in : int64

The dividend value.

divisor in : int64

The divisor value.

returns → int64

The remainder.

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

Public / Attributes

Nan​D


public static attribute NanD → (get)

value : float64

The NaN value.

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

Nan​F


public static attribute NanF → (get)

value : float32

The NaN value.

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

Neg​Inf​D


public static attribute NegInfD → (get)

value : float64

The -Inf value.

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

Neg​Inf​F


public static attribute NegInfF → (get)

value : float32

The -Inf value.

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

Pos​Inf​D


public static attribute PosInfD → (get)

value : float64

The +Inf value.

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

Pos​Inf​F


public static attribute PosInfF → (get)

value : float32

The +Inf value.

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