3. Math library

Math module contains basic floating point math functions and constants. Floating point math in general is not bit-precise. Compiler can optimize permutations, replace divisions with multiplications, and some of functions are not bit-exact. If you need precise math use double precision type. All functions and symbols are in “math” module, use require to get access to it.

require math

3.1. Constants

PI = 3.1415927f

The ratio of a circle’s circumference to its diameter. π

DBL_PI = 3.141592653589793lf

The ratio of a circle’s circumference to its diameter. π

FLT_EPSILON = 1.1920929e-07f

the difference between 1 and the smallest floating point number of type float that is greater than 1.

DBL_EPSILON = 2.220446049250313e-16lf

the difference between 1 and the smallest double precision floating point number of type double that is greater than 1.

3.2. Handled structures

float4x4

floating point matrix with 4 rows and 4 columns

Fields:
  • x : float4 - 0th row

  • y : float4 - 1st row

  • z : float4 - 2nd row

  • w : float4 - 3rd row

float3x4

floating point matrix with 4 rows and 3 columns

Fields:
  • x : float3 - 0th row

  • y : float3 - 1st row

  • z : float3 - 2nd row

  • w : float3 - 3rd row

float3x3

floating point matrix with 3 rows and 3 columns

Fields:
  • x : float3 - 0th row

  • y : float3 - 1st row

  • z : float3 - 2nd row

3.3. all numerics (uint*, int*, float*, double)

min(x: int; y: int): int

returns the minimum of x and y

Arguments:
  • x : int

  • y : int

max(x: int; y: int): int

returns the maximum of x and y

Arguments:
  • x : int

  • y : int

min(x: int2; y: int2): int2

returns the minimum of x and y

Arguments:
  • x : int2

  • y : int2

max(x: int2; y: int2): int2

returns the maximum of x and y

Arguments:
  • x : int2

  • y : int2

min(x: int3; y: int3): int3

returns the minimum of x and y

Arguments:
  • x : int3

  • y : int3

max(x: int3; y: int3): int3

returns the maximum of x and y

Arguments:
  • x : int3

  • y : int3

min(x: int4; y: int4): int4

returns the minimum of x and y

Arguments:
  • x : int4

  • y : int4

max(x: int4; y: int4): int4

returns the maximum of x and y

Arguments:
  • x : int4

  • y : int4

min(x: uint; y: uint): uint

returns the minimum of x and y

Arguments:
  • x : uint

  • y : uint

max(x: uint; y: uint): uint

returns the maximum of x and y

Arguments:
  • x : uint

  • y : uint

min(x: uint2; y: uint2): uint2

returns the minimum of x and y

Arguments:
  • x : uint2

  • y : uint2

max(x: uint2; y: uint2): uint2

returns the maximum of x and y

Arguments:
  • x : uint2

  • y : uint2

min(x: uint3; y: uint3): uint3

returns the minimum of x and y

Arguments:
  • x : uint3

  • y : uint3

max(x: uint3; y: uint3): uint3

returns the maximum of x and y

Arguments:
  • x : uint3

  • y : uint3

min(x: uint4; y: uint4): uint4

returns the minimum of x and y

Arguments:
  • x : uint4

  • y : uint4

max(x: uint4; y: uint4): uint4

returns the maximum of x and y

Arguments:
  • x : uint4

  • y : uint4

min(x: float; y: float): float

returns the minimum of x and y

Arguments:
  • x : float

  • y : float

max(x: float; y: float): float

returns the maximum of x and y

Arguments:
  • x : float

  • y : float

min(x: float2; y: float2): float2

returns the minimum of x and y

Arguments:
  • x : float2

  • y : float2

max(x: float2; y: float2): float2

returns the maximum of x and y

Arguments:
  • x : float2

  • y : float2

min(x: float3; y: float3): float3

returns the minimum of x and y

Arguments:
  • x : float3

  • y : float3

max(x: float3; y: float3): float3

returns the maximum of x and y

Arguments:
  • x : float3

  • y : float3

min(x: float4; y: float4): float4

returns the minimum of x and y

Arguments:
  • x : float4

  • y : float4

max(x: float4; y: float4): float4

returns the maximum of x and y

Arguments:
  • x : float4

  • y : float4

min(x: double; y: double): double

returns the minimum of x and y

Arguments:
  • x : double

  • y : double

max(x: double; y: double): double

returns the maximum of x and y

Arguments:
  • x : double

  • y : double

min(x: int64; y: int64): int64

returns the minimum of x and y

Arguments:
  • x : int64

  • y : int64

max(x: int64; y: int64): int64

returns the maximum of x and y

Arguments:
  • x : int64

  • y : int64

min(x: uint64; y: uint64): uint64

returns the minimum of x and y

Arguments:
  • x : uint64

  • y : uint64

max(x: uint64; y: uint64): uint64

returns the maximum of x and y

Arguments:
  • x : uint64

  • y : uint64

3.4. float* and double

sin(x: float): float

returns the sine of x

Arguments:
  • x : float

cos(x: float): float

returns the cosine of x

Arguments:
  • x : float

tan(x: float): float

returns the tangent of x

Arguments:
  • x : float

sin(x: float2): float2

returns the sine of x

Arguments:
  • x : float2

cos(x: float2): float2

returns the cosine of x

Arguments:
  • x : float2

tan(x: float2): float2

returns the tangent of x

Arguments:
  • x : float2

sin(x: float3): float3

returns the sine of x

Arguments:
  • x : float3

cos(x: float3): float3

returns the cosine of x

Arguments:
  • x : float3

tan(x: float3): float3

returns the tangent of x

Arguments:
  • x : float3

sin(x: float4): float4

returns the sine of x

Arguments:
  • x : float4

cos(x: float4): float4

returns the cosine of x

Arguments:
  • x : float4

tan(x: float4): float4

returns the tangent of x

Arguments:
  • x : float4

exp(x: float): float

returns the e^x value of x

Arguments:
  • x : float

log(x: float): float

returns the natural logarithm of x

Arguments:
  • x : float

exp2(x: float): float

returns the 2^x value of x

Arguments:
  • x : float

log2(x: float): float

returns the logarithm base-2 of x

Arguments:
  • x : float

rcp(x: float): float

returns the 1/x

Arguments:
  • x : float

pow(x: float; y: float): float

returns x raised to the power of y

Arguments:
  • x : float

  • y : float

exp(x: float2): float2

returns the e^x value of x

Arguments:
  • x : float2

log(x: float2): float2

returns the natural logarithm of x

Arguments:
  • x : float2

exp2(x: float2): float2

returns the 2^x value of x

Arguments:
  • x : float2

log2(x: float2): float2

returns the logarithm base-2 of x

Arguments:
  • x : float2

rcp(x: float2): float2

returns the 1/x

Arguments:
  • x : float2

pow(x: float2; y: float2): float2

returns x raised to the power of y

Arguments:
  • x : float2

  • y : float2

exp(x: float3): float3

returns the e^x value of x

Arguments:
  • x : float3

log(x: float3): float3

returns the natural logarithm of x

Arguments:
  • x : float3

exp2(x: float3): float3

returns the 2^x value of x

Arguments:
  • x : float3

log2(x: float3): float3

returns the logarithm base-2 of x

Arguments:
  • x : float3

rcp(x: float3): float3

returns the 1/x

Arguments:
  • x : float3

pow(x: float3; y: float3): float3

returns x raised to the power of y

Arguments:
  • x : float3

  • y : float3

exp(x: float4): float4

returns the e^x value of x

Arguments:
  • x : float4

log(x: float4): float4

returns the natural logarithm of x

Arguments:
  • x : float4

exp2(x: float4): float4

returns the 2^x value of x

Arguments:
  • x : float4

log2(x: float4): float4

returns the logarithm base-2 of x

Arguments:
  • x : float4

rcp(x: float4): float4

returns the 1/x

Arguments:
  • x : float4

pow(x: float4; y: float4): float4

returns x raised to the power of y

Arguments:
  • x : float4

  • y : float4

floor(x: float): float

returns a float value representing the largest integer that is less than or equal to x

Arguments:
  • x : float

ceil(x: float): float

returns a float value representing the smallest integer (type is still float) that is greater than or equal to arg0

Arguments:
  • x : float

sqrt(x: float): float

returns the square root of x

Arguments:
  • x : float

saturate(x: float): float

returns a clamped to [0..1] inclusive range x

Arguments:
  • x : float

floor(x: float2): float2

returns a float value representing the largest integer that is less than or equal to x

Arguments:
  • x : float2

ceil(x: float2): float2

returns a float value representing the smallest integer (type is still float) that is greater than or equal to arg0

Arguments:
  • x : float2

sqrt(x: float2): float2

returns the square root of x

Arguments:
  • x : float2

saturate(x: float2): float2

returns a clamped to [0..1] inclusive range x

Arguments:
  • x : float2

floor(x: float3): float3

returns a float value representing the largest integer that is less than or equal to x

Arguments:
  • x : float3

ceil(x: float3): float3

returns a float value representing the smallest integer (type is still float) that is greater than or equal to arg0

Arguments:
  • x : float3

sqrt(x: float3): float3

returns the square root of x

Arguments:
  • x : float3

saturate(x: float3): float3

returns a clamped to [0..1] inclusive range x

Arguments:
  • x : float3

floor(x: float4): float4

returns a float value representing the largest integer that is less than or equal to x

Arguments:
  • x : float4

ceil(x: float4): float4

returns a float value representing the smallest integer (type is still float) that is greater than or equal to arg0

Arguments:
  • x : float4

sqrt(x: float4): float4

returns the square root of x

Arguments:
  • x : float4

saturate(x: float4): float4

returns a clamped to [0..1] inclusive range x

Arguments:
  • x : float4

abs(x: int): int

returns the absolute value of x

Arguments:
  • x : int

sign(x: int): int

returns sign of x, or 0 if x == 0

Arguments:
  • x : int

abs(x: int2): int2

returns the absolute value of x

Arguments:
  • x : int2

sign(x: int2): int2

returns sign of x, or 0 if x == 0

Arguments:
  • x : int2

abs(x: int3): int3

returns the absolute value of x

Arguments:
  • x : int3

sign(x: int3): int3

returns sign of x, or 0 if x == 0

Arguments:
  • x : int3

abs(x: int4): int4

returns the absolute value of x

Arguments:
  • x : int4

sign(x: int4): int4

returns sign of x, or 0 if x == 0

Arguments:
  • x : int4

abs(x: uint): uint

returns the absolute value of x

Arguments:
  • x : uint

sign(x: uint): uint

returns sign of x, or 0 if x == 0

Arguments:
  • x : uint

abs(x: uint2): uint2

returns the absolute value of x

Arguments:
  • x : uint2

sign(x: uint2): uint2

returns sign of x, or 0 if x == 0

Arguments:
  • x : uint2

abs(x: uint3): uint3

returns the absolute value of x

Arguments:
  • x : uint3

sign(x: uint3): uint3

returns sign of x, or 0 if x == 0

Arguments:
  • x : uint3

abs(x: uint4): uint4

returns the absolute value of x

Arguments:
  • x : uint4

sign(x: uint4): uint4

returns sign of x, or 0 if x == 0

Arguments:
  • x : uint4

abs(x: float): float

returns the absolute value of x

Arguments:
  • x : float

sign(x: float): float

returns sign of x, or 0 if x == 0

Arguments:
  • x : float

abs(x: float2): float2

returns the absolute value of x

Arguments:
  • x : float2

sign(x: float2): float2

returns sign of x, or 0 if x == 0

Arguments:
  • x : float2

abs(x: float3): float3

returns the absolute value of x

Arguments:
  • x : float3

sign(x: float3): float3

returns sign of x, or 0 if x == 0

Arguments:
  • x : float3

abs(x: float4): float4

returns the absolute value of x

Arguments:
  • x : float4

sign(x: float4): float4

returns sign of x, or 0 if x == 0

Arguments:
  • x : float4

abs(x: double): double

returns the absolute value of x

Arguments:
  • x : double

sign(x: double): double

returns sign of x, or 0 if x == 0

Arguments:
  • x : double

abs(x: int64): int64

returns the absolute value of x

Arguments:
  • x : int64

sign(x: int64): int64

returns sign of x, or 0 if x == 0

Arguments:
  • x : int64

abs(x: uint64): uint64

returns the absolute value of x

Arguments:
  • x : uint64

sign(x: uint64): uint64

returns sign of x, or 0 if x == 0

Arguments:
  • x : uint64

is_nan(x: float): bool

Returns true if x is NaN (not a number)

Arguments:
  • x : float

is_finite(x: float): bool

Returns true if x is not a negative or positive infinity

Arguments:
  • x : float

is_nan(x: double): bool

Returns true if x is NaN (not a number)

Arguments:
  • x : double

is_finite(x: double): bool

Returns true if x is not a negative or positive infinity

Arguments:
  • x : double

sqrt(x: double): double

returns the square root of x

Arguments:
  • x : double

exp(x: double): double

returns the e^x value of x

Arguments:
  • x : double

rcp(x: double): double

returns the 1/x

Arguments:
  • x : double

log(x: double): double

returns the natural logarithm of x

Arguments:
  • x : double

pow(x: double; y: double): double

returns x raised to the power of y

Arguments:
  • x : double

  • y : double

exp2(x: double): double

returns the 2^x value of x

Arguments:
  • x : double

log2(x: double): double

returns the logarithm base-2 of x

Arguments:
  • x : double

sin(x: double): double

returns the sine of x

Arguments:
  • x : double

cos(x: double): double

returns the cosine of x

Arguments:
  • x : double

asin(x: double): double

returns the arcsine of x

Arguments:
  • x : double

acos(x: double): double

returns the arccosine of x

Arguments:
  • x : double

safe_asin(x: double): double

Returns the arcsine of x, clamping x to the [-1..1] range to avoid NaN results.

Arguments:
  • x : double

safe_acos(x: double): double

Returns the arc cosine of x, clamped to the range [-1, 1].

Arguments:
  • x : double

tan(x: double): double

returns the tangent of x

Arguments:
  • x : double

atan(x: double): double

returns the arctangent of x

Arguments:
  • x : double

atan2(y: double; x: double): double

returns the arctangent of y/x

Arguments:
  • y : double

  • x : double

sincos(x: float; s: float& implicit; c: float& implicit)

returns oth sine and cosine of x

Arguments:
  • x : float

  • s : float& implicit

  • c : float& implicit

sincos(x: double; s: double& implicit; c: double& implicit)

returns oth sine and cosine of x

Arguments:
  • x : double

  • s : double& implicit

  • c : double& implicit

asin(x: float): float

returns the arcsine of x

Arguments:
  • x : float

acos(x: float): float

returns the arccosine of x

Arguments:
  • x : float

safe_asin(x: float): float

Returns the arcsine of x, clamping x to the [-1..1] range to avoid NaN results.

Arguments:
  • x : float

safe_acos(x: float): float

Returns the arc cosine of x, clamped to the range [-1, 1].

Arguments:
  • x : float

atan(x: float): float

returns the arctangent of x

Arguments:
  • x : float

atan2(y: float; x: float): float

returns the arctangent of y/x

Arguments:
  • y : float

  • x : float

asin(x: float2): float2

returns the arcsine of x

Arguments:
  • x : float2

asin(x: float3): float3

returns the arcsine of x

Arguments:
  • x : float3

asin(x: float4): float4

returns the arcsine of x

Arguments:
  • x : float4

acos(x: float2): float2

returns the arccosine of x

Arguments:
  • x : float2

acos(x: float3): float3

returns the arccosine of x

Arguments:
  • x : float3

acos(x: float4): float4

returns the arccosine of x

Arguments:
  • x : float4

safe_asin(x: float2): float2

Returns the arcsine of x, clamping x to the [-1..1] range to avoid NaN results.

Arguments:
  • x : float2

safe_asin(x: float3): float3

Returns the arcsine of x, clamping x to the [-1..1] range to avoid NaN results.

Arguments:
  • x : float3

safe_asin(x: float4): float4

Returns the arcsine of x, clamping x to the [-1..1] range to avoid NaN results.

Arguments:
  • x : float4

safe_acos(x: float2): float2

returns the arc cosine of x, clamped to the range [-1, 1].

Arguments:
  • x : float2

safe_acos(x: float3): float3

Returns the arc cosine of x, clamped to the range [-1, 1].

Arguments:
  • x : float3

safe_acos(x: float4): float4

Returns the arc cosine of x, clamped to the range [-1, 1].

Arguments:
  • x : float4

atan(x: float2): float2

returns the arctangent of x

Arguments:
  • x : float2

atan(x: float3): float3

returns the arctangent of x

Arguments:
  • x : float3

atan(x: float4): float4

returns the arctangent of x

Arguments:
  • x : float4

atan2(y: float2; x: float2): float2

returns the arctangent of y/x

Arguments:
  • y : float2

  • x : float2

atan2(y: float3; x: float3): float3

returns the arctangent of y/x

Arguments:
  • y : float3

  • x : float3

atan2(y: float4; x: float4): float4

returns the arctangent of y/x

Arguments:
  • y : float4

  • x : float4

3.5. float* only

rcp_est(x: float): float

returns the fast approximation 1/x

Arguments:
  • x : float

rcp_est(x: float2): float2

returns the fast approximation 1/x

Arguments:
  • x : float2

rcp_est(x: float3): float3

returns the fast approximation 1/x

Arguments:
  • x : float3

rcp_est(x: float4): float4

returns the fast approximation 1/x

Arguments:
  • x : float4

fract(x: float): float

returns a fraction part of x

Arguments:
  • x : float

round(x: float): float

Returns the nearest integer to x.

Arguments:
  • x : float

rsqrt(x: float): float

returns 1/sqrt(x)

Arguments:
  • x : float

rsqrt_est(x: float): float

returns the fast approximation 1/sqrt(x)

Arguments:
  • x : float

fract(x: float2): float2

returns a fraction part of x

Arguments:
  • x : float2

round(x: float2): float2

Returns the nearest integer to x.

Arguments:
  • x : float2

rsqrt(x: float2): float2

returns 1/sqrt(x)

Arguments:
  • x : float2

rsqrt_est(x: float2): float2

returns the fast approximation 1/sqrt(x)

Arguments:
  • x : float2

fract(x: float3): float3

returns a fraction part of x

Arguments:
  • x : float3

round(x: float3): float3

Returns the nearest integer to x.

Arguments:
  • x : float3

rsqrt(x: float3): float3

returns 1/sqrt(x)

Arguments:
  • x : float3

rsqrt_est(x: float3): float3

returns the fast approximation 1/sqrt(x)

Arguments:
  • x : float3

fract(x: float4): float4

returns a fraction part of x

Arguments:
  • x : float4

round(x: float4): float4

Returns the nearest integer to x.

Arguments:
  • x : float4

rsqrt(x: float4): float4

returns 1/sqrt(x)

Arguments:
  • x : float4

rsqrt_est(x: float4): float4

returns the fast approximation 1/sqrt(x)

Arguments:
  • x : float4

atan_est(x: float): float

Fast estimation for the atan.

Arguments:
  • x : float

atan2_est(y: float; x: float): float

returns the fast approximation of arctangent of y/x

Arguments:
  • y : float

  • x : float

atan_est(x: float2): float2

Fast estimation for the atan.

Arguments:
  • x : float2

atan_est(x: float3): float3

Fast estimation for the atan.

Arguments:
  • x : float3

atan_est(x: float4): float4

Fast estimation for the atan.

Arguments:
  • x : float4

atan2_est(y: float2; x: float2): float2

returns the fast approximation of arctangent of y/x

Arguments:
  • y : float2

  • x : float2

atan2_est(y: float3; x: float3): float3

returns the fast approximation of arctangent of y/x

Arguments:
  • y : float3

  • x : float3

atan2_est(y: float4; x: float4): float4

returns the fast approximation of arctangent of y/x

Arguments:
  • y : float4

  • x : float4

floori(x: float): int

returns a integer value representing the largest integer that is less than or equal to x

Arguments:
  • x : float

ceili(x: float): int

returns a value representing the smallest integer (integer type!) that is greater than or equal to arg0

Arguments:
  • x : float

roundi(x: float): int

returns a integer value representing the integer that is closest to x

Arguments:
  • x : float

trunci(x: float): int

returns a integer value representing the float without fraction part of x

Arguments:
  • x : float

floori(x: double): int

returns a integer value representing the largest integer that is less than or equal to x

Arguments:
  • x : double

ceili(x: double): int

returns a value representing the smallest integer (integer type!) that is greater than or equal to arg0

Arguments:
  • x : double

roundi(x: double): int

returns a integer value representing the integer that is closest to x

Arguments:
  • x : double

trunci(x: double): int

returns a integer value representing the float without fraction part of x

Arguments:
  • x : double

floori(x: float2): int2

returns a integer value representing the largest integer that is less than or equal to x

Arguments:
  • x : float2

ceili(x: float2): int2

returns a value representing the smallest integer (integer type!) that is greater than or equal to arg0

Arguments:
  • x : float2

roundi(x: float2): int2

returns a integer value representing the integer that is closest to x

Arguments:
  • x : float2

trunci(x: float2): int2

returns a integer value representing the float without fraction part of x

Arguments:
  • x : float2

floori(x: float3): int3

returns a integer value representing the largest integer that is less than or equal to x

Arguments:
  • x : float3

ceili(x: float3): int3

returns a value representing the smallest integer (integer type!) that is greater than or equal to arg0

Arguments:
  • x : float3

roundi(x: float3): int3

returns a integer value representing the integer that is closest to x

Arguments:
  • x : float3

trunci(x: float3): int3

returns a integer value representing the float without fraction part of x

Arguments:
  • x : float3

floori(x: float4): int4

returns a integer value representing the largest integer that is less than or equal to x

Arguments:
  • x : float4

ceili(x: float4): int4

returns a value representing the smallest integer (integer type!) that is greater than or equal to arg0

Arguments:
  • x : float4

roundi(x: float4): int4

returns a integer value representing the integer that is closest to x

Arguments:
  • x : float4

trunci(x: float4): int4

returns a integer value representing the float without fraction part of x

Arguments:
  • x : float4

float4x4 implicit-(x: float4x4 implicit): float4x4

returns -x

Arguments:
float3x4 implicit-(x: float3x4 implicit): float3x4

returns -x

Arguments:
float3x3 implicit-(x: float3x3 implicit): float3x3

returns -x

Arguments:

3.6. float3 only

cross(x: float3; y: float3): float3

returns vector representing cross product between x and y

Arguments:
  • x : float3

  • y : float3

distance(x: float2; y: float2): float

returns a non-negative value representing distance between x and y

Arguments:
  • x : float2

  • y : float2

distance_sq(x: float2; y: float2): float

returns a non-negative value representing squared distance between x and y

Arguments:
  • x : float2

  • y : float2

inv_distance(x: float2; y: float2): float

returns a non-negative value representing 1/distance between x and y

Arguments:
  • x : float2

  • y : float2

inv_distance_sq(x: float2; y: float2): float

returns a non-negative value representing 1/squared distance between x and y

Arguments:
  • x : float2

  • y : float2

distance(x: float3; y: float3): float

returns a non-negative value representing distance between x and y

Arguments:
  • x : float3

  • y : float3

distance_sq(x: float3; y: float3): float

returns a non-negative value representing squared distance between x and y

Arguments:
  • x : float3

  • y : float3

inv_distance(x: float3; y: float3): float

returns a non-negative value representing 1/distance between x and y

Arguments:
  • x : float3

  • y : float3

inv_distance_sq(x: float3; y: float3): float

returns a non-negative value representing 1/squared distance between x and y

Arguments:
  • x : float3

  • y : float3

distance(x: float4; y: float4): float

returns a non-negative value representing distance between x and y

Arguments:
  • x : float4

  • y : float4

distance_sq(x: float4; y: float4): float

returns a non-negative value representing squared distance between x and y

Arguments:
  • x : float4

  • y : float4

inv_distance(x: float4; y: float4): float

returns a non-negative value representing 1/distance between x and y

Arguments:
  • x : float4

  • y : float4

inv_distance_sq(x: float4; y: float4): float

returns a non-negative value representing 1/squared distance between x and y

Arguments:
  • x : float4

  • y : float4

reflect(v: float3; n: float3): float3

see function-math-reflect.rst for details

Arguments:
  • v : float3

  • n : float3

reflect(v: float2; n: float2): float2

see function-math-reflect.rst for details

Arguments:
  • v : float2

  • n : float2

refract(v: float3; n: float3; nint: float): float3

see function-math-refract.rst for details

Arguments:
  • v : float3

  • n : float3

  • nint : float

refract(v: float2; n: float2; nint: float): float2

see function-math-refract.rst for details

Arguments:
  • v : float2

  • n : float2

  • nint : float

3.7. float2, float3, float4

dot(x: float2; y: float2): float

returns scalar representing dot product between x and y

Arguments:
  • x : float2

  • y : float2

dot(x: float3; y: float3): float

returns scalar representing dot product between x and y

Arguments:
  • x : float3

  • y : float3

dot(x: float4; y: float4): float

returns scalar representing dot product between x and y

Arguments:
  • x : float4

  • y : float4

fast_normalize(x: float2): float2

returns the fast approximation of normalized x, or nan if length(x) is 0

Arguments:
  • x : float2

fast_normalize(x: float3): float3

returns the fast approximation of normalized x, or nan if length(x) is 0

Arguments:
  • x : float3

fast_normalize(x: float4): float4

returns the fast approximation of normalized x, or nan if length(x) is 0

Arguments:
  • x : float4

normalize(x: float2): float2

returns normalized x, or nan if length(x) is 0

Arguments:
  • x : float2

normalize(x: float3): float3

returns normalized x, or nan if length(x) is 0

Arguments:
  • x : float3

normalize(x: float4): float4

returns normalized x, or nan if length(x) is 0

Arguments:
  • x : float4

length(x: float2): float

returns a non-negative value representing magnitude of x

Arguments:
  • x : float2

length(x: float3): float

returns a non-negative value representing magnitude of x

Arguments:
  • x : float3

length(x: float4): float

returns a non-negative value representing magnitude of x

Arguments:
  • x : float4

inv_length(x: float2): float

returns a non-negative value representing 1/magnitude of x

Arguments:
  • x : float2

inv_length(x: float3): float

returns a non-negative value representing 1/magnitude of x

Arguments:
  • x : float3

inv_length(x: float4): float

returns a non-negative value representing 1/magnitude of x

Arguments:
  • x : float4

inv_length_sq(x: float2): float

returns a non-negative value representing 1/squared magnitude of x

Arguments:
  • x : float2

inv_length_sq(x: float3): float

returns a non-negative value representing 1/squared magnitude of x

Arguments:
  • x : float3

inv_length_sq(x: float4): float

returns a non-negative value representing 1/squared magnitude of x

Arguments:
  • x : float4

length_sq(x: float2): float

returns a non-negative value representing squared magnitude of x

Arguments:
  • x : float2

length_sq(x: float3): float

returns a non-negative value representing squared magnitude of x

Arguments:
  • x : float3

length_sq(x: float4): float

returns a non-negative value representing squared magnitude of x

Arguments:
  • x : float4

3.8. Noise functions

uint32_hash(seed: uint): uint

returns hashed value of seed

Arguments:
  • seed : uint

uint_noise_1D(position: int; seed: uint): uint

returns noise value of position in the seeded sequence

Arguments:
  • position : int

  • seed : uint

uint_noise_2D(position: int2; seed: uint): uint

returns noise value of position in the seeded sequence

Arguments:
  • position : int2

  • seed : uint

uint_noise_3D(position: int3; seed: uint): uint

returns noise value of position in the seeded sequence

Arguments:
  • position : int3

  • seed : uint

3.9. lerp/mad/clamp

mad(a: float; b: float; c: float): float

returns vector or scalar representing a * b + c

Arguments:
  • a : float

  • b : float

  • c : float

lerp(a: float; b: float; t: float): float

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float

  • b : float

  • t : float

mad(a: float2; b: float2; c: float2): float2

returns vector or scalar representing a * b + c

Arguments:
  • a : float2

  • b : float2

  • c : float2

lerp(a: float2; b: float2; t: float2): float2

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float2

  • b : float2

  • t : float2

mad(a: float3; b: float3; c: float3): float3

returns vector or scalar representing a * b + c

Arguments:
  • a : float3

  • b : float3

  • c : float3

lerp(a: float3; b: float3; t: float3): float3

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float3

  • b : float3

  • t : float3

mad(a: float4; b: float4; c: float4): float4

returns vector or scalar representing a * b + c

Arguments:
  • a : float4

  • b : float4

  • c : float4

lerp(a: float4; b: float4; t: float4): float4

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float4

  • b : float4

  • t : float4

mad(a: float2; b: float; c: float2): float2

returns vector or scalar representing a * b + c

Arguments:
  • a : float2

  • b : float

  • c : float2

mad(a: float3; b: float; c: float3): float3

returns vector or scalar representing a * b + c

Arguments:
  • a : float3

  • b : float

  • c : float3

mad(a: float4; b: float; c: float4): float4

returns vector or scalar representing a * b + c

Arguments:
  • a : float4

  • b : float

  • c : float4

mad(a: int; b: int; c: int): int

returns vector or scalar representing a * b + c

Arguments:
  • a : int

  • b : int

  • c : int

mad(a: int2; b: int2; c: int2): int2

returns vector or scalar representing a * b + c

Arguments:
  • a : int2

  • b : int2

  • c : int2

mad(a: int3; b: int3; c: int3): int3

returns vector or scalar representing a * b + c

Arguments:
  • a : int3

  • b : int3

  • c : int3

mad(a: int4; b: int4; c: int4): int4

returns vector or scalar representing a * b + c

Arguments:
  • a : int4

  • b : int4

  • c : int4

mad(a: int2; b: int; c: int2): int2

returns vector or scalar representing a * b + c

Arguments:
  • a : int2

  • b : int

  • c : int2

mad(a: int3; b: int; c: int3): int3

returns vector or scalar representing a * b + c

Arguments:
  • a : int3

  • b : int

  • c : int3

mad(a: int4; b: int; c: int4): int4

returns vector or scalar representing a * b + c

Arguments:
  • a : int4

  • b : int

  • c : int4

mad(a: uint; b: uint; c: uint): uint

returns vector or scalar representing a * b + c

Arguments:
  • a : uint

  • b : uint

  • c : uint

mad(a: uint2; b: uint2; c: uint2): uint2

returns vector or scalar representing a * b + c

Arguments:
  • a : uint2

  • b : uint2

  • c : uint2

mad(a: uint3; b: uint3; c: uint3): uint3

returns vector or scalar representing a * b + c

Arguments:
  • a : uint3

  • b : uint3

  • c : uint3

mad(a: uint4; b: uint4; c: uint4): uint4

returns vector or scalar representing a * b + c

Arguments:
  • a : uint4

  • b : uint4

  • c : uint4

mad(a: uint2; b: uint; c: uint2): uint2

returns vector or scalar representing a * b + c

Arguments:
  • a : uint2

  • b : uint

  • c : uint2

mad(a: uint3; b: uint; c: uint3): uint3

returns vector or scalar representing a * b + c

Arguments:
  • a : uint3

  • b : uint

  • c : uint3

mad(a: uint4; b: uint; c: uint4): uint4

returns vector or scalar representing a * b + c

Arguments:
  • a : uint4

  • b : uint

  • c : uint4

mad(a: double; b: double; c: double): double

returns vector or scalar representing a * b + c

Arguments:
  • a : double

  • b : double

  • c : double

lerp(a: double; b: double; t: double): double

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : double

  • b : double

  • t : double

clamp(t: int; a: int; b: int): int

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : int

  • a : int

  • b : int

clamp(t: int2; a: int2; b: int2): int2

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : int2

  • a : int2

  • b : int2

clamp(t: int3; a: int3; b: int3): int3

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : int3

  • a : int3

  • b : int3

clamp(t: int4; a: int4; b: int4): int4

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : int4

  • a : int4

  • b : int4

clamp(t: uint; a: uint; b: uint): uint

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : uint

  • a : uint

  • b : uint

clamp(t: uint2; a: uint2; b: uint2): uint2

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : uint2

  • a : uint2

  • b : uint2

clamp(t: uint3; a: uint3; b: uint3): uint3

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : uint3

  • a : uint3

  • b : uint3

clamp(t: uint4; a: uint4; b: uint4): uint4

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : uint4

  • a : uint4

  • b : uint4

clamp(t: float; a: float; b: float): float

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : float

  • a : float

  • b : float

clamp(t: float2; a: float2; b: float2): float2

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : float2

  • a : float2

  • b : float2

clamp(t: float3; a: float3; b: float3): float3

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : float3

  • a : float3

  • b : float3

clamp(t: float4; a: float4; b: float4): float4

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : float4

  • a : float4

  • b : float4

clamp(t: double; a: double; b: double): double

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : double

  • a : double

  • b : double

clamp(t: int64; a: int64; b: int64): int64

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : int64

  • a : int64

  • b : int64

clamp(t: uint64; a: uint64; b: uint64): uint64

returns vector or scalar representing min(max(t, a), b)

Arguments:
  • t : uint64

  • a : uint64

  • b : uint64

lerp(a: float2; b: float2; t: float): float2

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float2

  • b : float2

  • t : float

lerp(a: float3; b: float3; t: float): float3

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float3

  • b : float3

  • t : float

lerp(a: float4; b: float4; t: float): float4

returns vector or scalar representing a + (b - a) * t

Arguments:
  • a : float4

  • b : float4

  • t : float

3.10. Matrix operations

float4x4 implicit*(x: float4x4 implicit; y: float4x4 implicit): float4x4

Multiplies a float4x4 matrix by a float4x4 matrix.

Arguments:
float4x4 implicit==(x: float4x4 implicit; y: float4x4 implicit): bool

Compares two float4x4 matrices for equality.

Arguments:
float4x4 implicit!=(x: float4x4 implicit; y: float4x4 implicit): bool

Compares two float4x4 matrices for inequality.

Arguments:
float3x4 implicit*(x: float3x4 implicit; y: float3x4 implicit): float3x4

Multiplies a float3x4 matrix by a float3x4 matrix.

Arguments:
float3x4 implicit*(x: float3x4 implicit; y: float3): float3

Multiplies a float3x3 matrix by a float3 vector.

Arguments:
float4x4 implicit*(x: float4x4 implicit; y: float4): float4

Multiplies a float4x4 matrix by a float4 vector.

Arguments:
float3x4 implicit==(x: float3x4 implicit; y: float3x4 implicit): bool

Compares two float3x4 matrices for equality.

Arguments:
float3x4 implicit!=(x: float3x4 implicit; y: float3x4 implicit): bool

Compares two float3x4 matrices for inequality.

Arguments:
float3x3 implicit*(x: float3x3 implicit; y: float3x3 implicit): float3x3

Multiplies a float3x3 matrix by a float3x3 matrix.

Arguments:
float3x3 implicit*(x: float3x3 implicit; y: float3): float3

Multiplies a float3x3 matrix by a float3 vector.

Arguments:
float3x3 implicit==(x: float3x3 implicit; y: float3x3 implicit): bool

Compares two float3x3 matrices for equality.

Arguments:
float3x3 implicit!=(x: float3x3 implicit; y: float3x3 implicit): bool

Compares two float3x3 matrices for inequality.

Arguments:

3.11. Matrix initializers

float3x3(): float3x3

Returns empty matrix, where each component is 0.

float3x4(): float3x4

Returns empty matrix, where each component is 0.

float4x4(): float4x4

Returns empty matrix, where each component is 0.

float4x4(arg0: float3x4 implicit): float4x4

Returns empty matrix, where each component is 0.

Arguments:
identity4x4(): float4x4

Returns identity matrix, where diagonal is 1 and every other component is 0.

float3x4(arg0: float4x4 implicit): float3x4

Returns empty matrix, where each component is 0.

Arguments:
identity3x4(): float3x4

Returns identity matrix, where diagonal is 1 and every other component is 0.

float3x3(arg0: float4x4 implicit): float3x3

Returns empty matrix, where each component is 0.

Arguments:
float3x3(arg0: float3x4 implicit): float3x3

Returns empty matrix, where each component is 0.

Arguments:
identity3x3(): float3x3

Returns identity matrix, where diagonal is 1 and every other component is 0.

3.12. Matrix manipulation

identity(x: float4x4 implicit)

Returns identity matrix, where diagonal is 1 and every other component is 0.

Arguments:
translation(xyz: float3): float4x4

Returns the arc cosine of x, clamped to the range [-1, 1].

Arguments:
  • xyz : float3

transpose(x: float4x4 implicit): float4x4

Transposes the specified input matrix x.

Arguments:
persp_forward(wk: float; hk: float; zn: float; zf: float): float4x4

Perspective matrix, zn - 0, zf - 1

Arguments:
  • wk : float

  • hk : float

  • zn : float

  • zf : float

persp_reverse(wk: float; hk: float; zn: float; zf: float): float4x4

Perspective matrix, zn - 1, zf - 0

Arguments:
  • wk : float

  • hk : float

  • zn : float

  • zf : float

look_at(eye: float3; at: float3; up: float3): float4x4

Look-at matrix with the origin at eye, looking at at, with up as up direction.

Arguments:
  • eye : float3

  • at : float3

  • up : float3

compose(pos: float3; rot: float4; scale: float3): float4x4

Compose transformation out of translation, rotation and scale.

Arguments:
  • pos : float3

  • rot : float4

  • scale : float3

decompose(mat: float4x4 implicit; pos: float3& implicit; rot: float4& implicit; scale: float3& implicit)

Decompose transformation into translation, rotation and scale.

Arguments:
  • mat : float4x4 implicit

  • pos : float3& implicit

  • rot : float4& implicit

  • scale : float3& implicit

identity(x: float3x4 implicit)

Returns identity matrix, where diagonal is 1 and every other component is 0.

Arguments:
inverse(x: float3x4 implicit): float3x4

Returns the inverse of the matrix x.

Arguments:
inverse(m: float4x4 implicit): float4x4

Returns the inverse of the matrix x.

Arguments:
orthonormal_inverse(m: float3x3 implicit): float3x3

Fast inverse for the orthonormal matrix.

Arguments:
orthonormal_inverse(m: float3x4 implicit): float3x4

Fast inverse for the orthonormal matrix.

Arguments:
rotate(x: float3x4 implicit; y: float3): float3

Rotates vector y by 3x4 matrix x. Only 3x3 portion of x is multiplied by y.

Arguments:
identity(x: float3x3 implicit)

Returns identity matrix, where diagonal is 1 and every other component is 0.

Arguments:

3.13. Quaternion operations

quat_from_unit_arc(v0: float3; v1: float3): float4

Quaternion which represents rotation from v0 to v1, both arguments need to be normalized

Arguments:
  • v0 : float3

  • v1 : float3

quat_from_unit_vec_ang(v: float3; ang: float): float4

Quaternion which represents rotation for ang radians around vector v. v needs to be normalized

Arguments:
  • v : float3

  • ang : float

quat_mul(q1: float4; q2: float4): float4

Quaternion which is multiplication of q1 and q2

Arguments:
  • q1 : float4

  • q2 : float4

quat_mul_vec(q: float4; v: float3): float3

Transform vector v by quaternion q

Arguments:
  • q : float4

  • v : float3

quat_conjugate(q: float4): float4

Quaternion which is conjugate of q

Arguments:
  • q : float4

3.14. Packing and unpacking

pack_float_to_byte(x: float4): uint

Packs float4 vector v to byte4 vector and returns it as uint. Each component is clamped to [0..255] range.

Arguments:
  • x : float4

unpack_byte_to_float(x: uint): float4

Unpacks byte4 vector to float4 vector.

Arguments:
  • x : uint

3.15. Uncategorized

float4x4 implicit ==const[](m: float4x4 implicit ==const; i: int): float4&

Returns the i-th row of a float4x4 matrix.

Arguments:
float4x4 const implicit ==const[](m: float4x4 const implicit ==const; i: int): float4

Returns the i-th row of a float4x4 matrix.

Arguments:
float4x4 implicit ==const[](m: float4x4 implicit ==const; i: uint): float4&

Returns the i-th row of a float4x4 matrix.

Arguments:
float4x4 const implicit ==const[](m: float4x4 const implicit ==const; i: uint): float4

Returns the i-th row of a float4x4 matrix.

Arguments:
determinant(x: float4x4 implicit): float

Returns the determinant of the matrix m.

Arguments:
determinant(x: float3x4 implicit): float

Returns the determinant of the matrix m.

Arguments:
float3x4 implicit ==const[](m: float3x4 implicit ==const; i: int): float3&

Returns the i-th row of a float3x4 matrix.

Arguments:
float3x4 const implicit ==const[](m: float3x4 const implicit ==const; i: int): float3

Returns the i-th row of a float3x4 matrix.

Arguments:
float3x4 implicit ==const[](m: float3x4 implicit ==const; i: uint): float3&

Returns the i-th row of a float3x4 matrix.

Arguments:
float3x4 const implicit ==const[](m: float3x4 const implicit ==const; i: uint): float3

Returns the i-th row of a float3x4 matrix.

Arguments:
quat_from_euler(angles: float3): float4

Construct quaternion from euler angles.

Arguments:
  • angles : float3

quat_from_euler(x: float; y: float; z: float): float4

Construct quaternion from euler angles.

Arguments:
  • x : float

  • y : float

  • z : float

euler_from_quat(angles: float4): float3

Construct euler angles from quaternion.

Arguments:
  • angles : float4

quat(m: float3x3 implicit): float4

Construct quaternion from matrix.

Arguments:
quat(m: float3x4 implicit): float4

Construct quaternion from matrix.

Arguments:
quat(m: float4x4 implicit): float4

Construct quaternion from matrix.

Arguments:
quat_slerp(t: float; a: float4; b: float4): float4

Spherical linear interpolation between a and b by t.

Arguments:
  • t : float

  • a : float4

  • b : float4

determinant(x: float3x3 implicit): float

Returns the determinant of the matrix m.

Arguments:
float3x3 implicit ==const[](m: float3x3 implicit ==const; i: int): float3&

Returns the i-th row of a float3x3 matrix.

Arguments:
float3x3 const implicit ==const[](m: float3x3 const implicit ==const; i: int): float3

Returns the i-th row of a float3x3 matrix.

Arguments:
float3x3 implicit ==const[](m: float3x3 implicit ==const; i: uint): float3&

Returns the i-th row of a float3x3 matrix.

Arguments:
float3x3 const implicit ==const[](m: float3x3 const implicit ==const; i: uint): float3

Returns the i-th row of a float4x4 matrix.

Arguments: