3. Math library

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.14159f

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

FLT_EPSILON = 1.19209e-07f

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

3.2. Handled types

float4x4

floating point matrix with 4 rows and 4 columns

float3x4

floating point matrix with 4 rows and 3 columns

float3x3

floating point matrix with 3 rows and 3 columns

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

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

min returns int

argument

argument type

x

int const

y

int const

returns the minimum of x and y

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

max returns int

argument

argument type

x

int const

y

int const

returns the maximum of x and y

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

min returns int2

argument

argument type

x

int2 const

y

int2 const

returns the minimum of x and y

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

max returns int2

argument

argument type

x

int2 const

y

int2 const

returns the maximum of x and y

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

min returns int3

argument

argument type

x

int3 const

y

int3 const

returns the minimum of x and y

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

max returns int3

argument

argument type

x

int3 const

y

int3 const

returns the maximum of x and y

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

min returns int4

argument

argument type

x

int4 const

y

int4 const

returns the minimum of x and y

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

max returns int4

argument

argument type

x

int4 const

y

int4 const

returns the maximum of x and y

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

min returns uint

argument

argument type

x

uint const

y

uint const

returns the minimum of x and y

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

max returns uint

argument

argument type

x

uint const

y

uint const

returns the maximum of x and y

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

min returns float

argument

argument type

x

float const

y

float const

returns the minimum of x and y

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

max returns float

argument

argument type

x

float const

y

float const

returns the maximum of x and y

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

min returns float2

argument

argument type

x

float2 const

y

float2 const

returns the minimum of x and y

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

max returns float2

argument

argument type

x

float2 const

y

float2 const

returns the maximum of x and y

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

min returns float3

argument

argument type

x

float3 const

y

float3 const

returns the minimum of x and y

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

max returns float3

argument

argument type

x

float3 const

y

float3 const

returns the maximum of x and y

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

min returns float4

argument

argument type

x

float4 const

y

float4 const

returns the minimum of x and y

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

max returns float4

argument

argument type

x

float4 const

y

float4 const

returns the maximum of x and y

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

min returns double

argument

argument type

x

double const

y

double const

returns the minimum of x and y

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

max returns double

argument

argument type

x

double const

y

double const

returns the maximum of x and y

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

min returns int64

argument

argument type

x

int64 const

y

int64 const

returns the minimum of x and y

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

max returns int64

argument

argument type

x

int64 const

y

int64 const

returns the maximum of x and y

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

min returns uint64

argument

argument type

x

uint64 const

y

uint64 const

returns the minimum of x and y

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

max returns uint64

argument

argument type

x

uint64 const

y

uint64 const

returns the maximum of x and y

3.4. float* and double

sin(x: float const)

sin returns float

argument

argument type

x

float const

returns the sine of x

cos(x: float const)

cos returns float

argument

argument type

x

float const

returns the cosine of x

tan(x: float const)

tan returns float

argument

argument type

x

float const

returns the tangent of x

atan(x: float const)

atan returns float

argument

argument type

x

float const

returns the arctangent of x

asin(x: float const)

asin returns float

argument

argument type

x

float const

returns the arcsine of x

acos(x: float const)

acos returns float

argument

argument type

x

float const

returns the arccosine of x

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

atan2 returns float

argument

argument type

y

float const

x

float const

returns the arctangent of y/x

sin(x: float2 const)

sin returns float2

argument

argument type

x

float2 const

returns the sine of x

cos(x: float2 const)

cos returns float2

argument

argument type

x

float2 const

returns the cosine of x

tan(x: float2 const)

tan returns float2

argument

argument type

x

float2 const

returns the tangent of x

atan(x: float2 const)

atan returns float2

argument

argument type

x

float2 const

returns the arctangent of x

asin(x: float2 const)

asin returns float2

argument

argument type

x

float2 const

returns the arcsine of x

acos(x: float2 const)

acos returns float2

argument

argument type

x

float2 const

returns the arccosine of x

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

atan2 returns float2

argument

argument type

y

float2 const

x

float2 const

returns the arctangent of y/x

sin(x: float3 const)

sin returns float3

argument

argument type

x

float3 const

returns the sine of x

cos(x: float3 const)

cos returns float3

argument

argument type

x

float3 const

returns the cosine of x

tan(x: float3 const)

tan returns float3

argument

argument type

x

float3 const

returns the tangent of x

atan(x: float3 const)

atan returns float3

argument

argument type

x

float3 const

returns the arctangent of x

asin(x: float3 const)

asin returns float3

argument

argument type

x

float3 const

returns the arcsine of x

acos(x: float3 const)

acos returns float3

argument

argument type

x

float3 const

returns the arccosine of x

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

atan2 returns float3

argument

argument type

y

float3 const

x

float3 const

returns the arctangent of y/x

sin(x: float4 const)

sin returns float4

argument

argument type

x

float4 const

returns the sine of x

cos(x: float4 const)

cos returns float4

argument

argument type

x

float4 const

returns the cosine of x

tan(x: float4 const)

tan returns float4

argument

argument type

x

float4 const

returns the tangent of x

atan(x: float4 const)

atan returns float4

argument

argument type

x

float4 const

returns the arctangent of x

asin(x: float4 const)

asin returns float4

argument

argument type

x

float4 const

returns the arcsine of x

acos(x: float4 const)

acos returns float4

argument

argument type

x

float4 const

returns the arccosine of x

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

atan2 returns float4

argument

argument type

y

float4 const

x

float4 const

returns the arctangent of y/x

exp(x: float const)

exp returns float

argument

argument type

x

float const

returns the e^x value of x

log(x: float const)

log returns float

argument

argument type

x

float const

returns the natural logarithm of x

exp2(x: float const)

exp2 returns float

argument

argument type

x

float const

returns the 2^x value of x

log2(x: float const)

log2 returns float

argument

argument type

x

float const

returns the logarithm base-2 of x

rcp(x: float const)

rcp returns float

argument

argument type

x

float const

returns the 1/x

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

pow returns float

argument

argument type

x

float const

y

float const

returns x raised to the power of y

exp(x: float2 const)

exp returns float2

argument

argument type

x

float2 const

returns the e^x value of x

log(x: float2 const)

log returns float2

argument

argument type

x

float2 const

returns the natural logarithm of x

exp2(x: float2 const)

exp2 returns float2

argument

argument type

x

float2 const

returns the 2^x value of x

log2(x: float2 const)

log2 returns float2

argument

argument type

x

float2 const

returns the logarithm base-2 of x

rcp(x: float2 const)

rcp returns float2

argument

argument type

x

float2 const

returns the 1/x

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

pow returns float2

argument

argument type

x

float2 const

y

float2 const

returns x raised to the power of y

exp(x: float3 const)

exp returns float3

argument

argument type

x

float3 const

returns the e^x value of x

log(x: float3 const)

log returns float3

argument

argument type

x

float3 const

returns the natural logarithm of x

exp2(x: float3 const)

exp2 returns float3

argument

argument type

x

float3 const

returns the 2^x value of x

log2(x: float3 const)

log2 returns float3

argument

argument type

x

float3 const

returns the logarithm base-2 of x

rcp(x: float3 const)

rcp returns float3

argument

argument type

x

float3 const

returns the 1/x

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

pow returns float3

argument

argument type

x

float3 const

y

float3 const

returns x raised to the power of y

exp(x: float4 const)

exp returns float4

argument

argument type

x

float4 const

returns the e^x value of x

log(x: float4 const)

log returns float4

argument

argument type

x

float4 const

returns the natural logarithm of x

exp2(x: float4 const)

exp2 returns float4

argument

argument type

x

float4 const

returns the 2^x value of x

log2(x: float4 const)

log2 returns float4

argument

argument type

x

float4 const

returns the logarithm base-2 of x

rcp(x: float4 const)

rcp returns float4

argument

argument type

x

float4 const

returns the 1/x

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

pow returns float4

argument

argument type

x

float4 const

y

float4 const

returns x raised to the power of y

floor(x: float const)

floor returns float

argument

argument type

x

float const

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

ceil(x: float const)

ceil returns float

argument

argument type

x

float const

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

sqrt(x: float const)

sqrt returns float

argument

argument type

x

float const

returns the square root of x

saturate(x: float const)

saturate returns float

argument

argument type

x

float const

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

floor(x: float2 const)

floor returns float2

argument

argument type

x

float2 const

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

ceil(x: float2 const)

ceil returns float2

argument

argument type

x

float2 const

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

sqrt(x: float2 const)

sqrt returns float2

argument

argument type

x

float2 const

returns the square root of x

saturate(x: float2 const)

saturate returns float2

argument

argument type

x

float2 const

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

floor(x: float3 const)

floor returns float3

argument

argument type

x

float3 const

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

ceil(x: float3 const)

ceil returns float3

argument

argument type

x

float3 const

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

sqrt(x: float3 const)

sqrt returns float3

argument

argument type

x

float3 const

returns the square root of x

saturate(x: float3 const)

saturate returns float3

argument

argument type

x

float3 const

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

floor(x: float4 const)

floor returns float4

argument

argument type

x

float4 const

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

ceil(x: float4 const)

ceil returns float4

argument

argument type

x

float4 const

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

sqrt(x: float4 const)

sqrt returns float4

argument

argument type

x

float4 const

returns the square root of x

saturate(x: float4 const)

saturate returns float4

argument

argument type

x

float4 const

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

abs(x: int const)

abs returns int

argument

argument type

x

int const

returns the absolute value of x

sign(x: int const)

sign returns int

argument

argument type

x

int const

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

abs(x: int2 const)

abs returns int2

argument

argument type

x

int2 const

returns the absolute value of x

sign(x: int2 const)

sign returns int2

argument

argument type

x

int2 const

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

abs(x: int3 const)

abs returns int3

argument

argument type

x

int3 const

returns the absolute value of x

sign(x: int3 const)

sign returns int3

argument

argument type

x

int3 const

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

abs(x: int4 const)

abs returns int4

argument

argument type

x

int4 const

returns the absolute value of x

sign(x: int4 const)

sign returns int4

argument

argument type

x

int4 const

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

abs(x: uint const)

abs returns uint

argument

argument type

x

uint const

returns the absolute value of x

sign(x: uint const)

sign returns uint

argument

argument type

x

uint const

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

abs(x: float const)

abs returns float

argument

argument type

x

float const

returns the absolute value of x

sign(x: float const)

sign returns float

argument

argument type

x

float const

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

abs(x: float2 const)

abs returns float2

argument

argument type

x

float2 const

returns the absolute value of x

sign(x: float2 const)

sign returns float2

argument

argument type

x

float2 const

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

abs(x: float3 const)

abs returns float3

argument

argument type

x

float3 const

returns the absolute value of x

sign(x: float3 const)

sign returns float3

argument

argument type

x

float3 const

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

abs(x: float4 const)

abs returns float4

argument

argument type

x

float4 const

returns the absolute value of x

sign(x: float4 const)

sign returns float4

argument

argument type

x

float4 const

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

abs(x: double const)

abs returns double

argument

argument type

x

double const

returns the absolute value of x

sign(x: double const)

sign returns double

argument

argument type

x

double const

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

abs(x: int64 const)

abs returns int64

argument

argument type

x

int64 const

returns the absolute value of x

sign(x: int64 const)

sign returns int64

argument

argument type

x

int64 const

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

abs(x: uint64 const)

abs returns uint64

argument

argument type

x

uint64 const

returns the absolute value of x

sign(x: uint64 const)

sign returns uint64

argument

argument type

x

uint64 const

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

is_nan(x: float const)

is_nan returns bool

argument

argument type

x

float const

Returns true if x is NaN (not a number)

is_finite(x: float const)

is_finite returns bool

argument

argument type

x

float const

Returns true if x is not a negative or positive infinity

is_nan(x: double const)

is_nan returns bool

argument

argument type

x

double const

Returns true if x is NaN (not a number)

is_finite(x: double const)

is_finite returns bool

argument

argument type

x

double const

Returns true if x is not a negative or positive infinity

sqrt(x: double const)

sqrt returns double

argument

argument type

x

double const

returns the square root of x

exp(x: double const)

exp returns double

argument

argument type

x

double const

returns the e^x value of x

rcp(x: double const)

rcp returns double

argument

argument type

x

double const

returns the 1/x

log(x: double const)

log returns double

argument

argument type

x

double const

returns the natural logarithm of x

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

pow returns double

argument

argument type

x

double const

y

double const

returns x raised to the power of y

exp2(x: double const)

exp2 returns double

argument

argument type

x

double const

returns the 2^x value of x

log2(x: double const)

log2 returns double

argument

argument type

x

double const

returns the logarithm base-2 of x

sin(x: double const)

sin returns double

argument

argument type

x

double const

returns the sine of x

cos(x: double const)

cos returns double

argument

argument type

x

double const

returns the cosine of x

asin(x: double const)

asin returns double

argument

argument type

x

double const

returns the arcsine of x

acos(x: double const)

acos returns double

argument

argument type

x

double const

returns the arccosine of x

tan(x: double const)

tan returns double

argument

argument type

x

double const

returns the tangent of x

atan(x: double const)

atan returns double

argument

argument type

x

double const

returns the arctangent of x

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

atan2 returns double

argument

argument type

y

double const

x

double const

returns the arctangent of y/x

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

argument

argument type

x

float const

s

float& implicit

c

float& implicit

returns oth sine and cosine of x

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

argument

argument type

x

double const

s

double& implicit

c

double& implicit

returns oth sine and cosine of x

3.5. float* only

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

atan2_est returns float

argument

argument type

y

float const

x

float const

returns the fast approximation of arctangent of y/x

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

atan2_est returns float2

argument

argument type

y

float2 const

x

float2 const

returns the fast approximation of arctangent of y/x

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

atan2_est returns float3

argument

argument type

y

float3 const

x

float3 const

returns the fast approximation of arctangent of y/x

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

atan2_est returns float4

argument

argument type

y

float4 const

x

float4 const

returns the fast approximation of arctangent of y/x

rcp_est(x: float const)

rcp_est returns float

argument

argument type

x

float const

returns the fast approximation 1/x

rcp_est(x: float2 const)

rcp_est returns float2

argument

argument type

x

float2 const

returns the fast approximation 1/x

rcp_est(x: float3 const)

rcp_est returns float3

argument

argument type

x

float3 const

returns the fast approximation 1/x

rcp_est(x: float4 const)

rcp_est returns float4

argument

argument type

x

float4 const

returns the fast approximation 1/x

rsqrt(x: float const)

rsqrt returns float

argument

argument type

x

float const

returns 1/sqrt(x)

rsqrt_est(x: float const)

rsqrt_est returns float

argument

argument type

x

float const

returns the fast approximation 1/sqrt(x)

rsqrt(x: float2 const)

rsqrt returns float2

argument

argument type

x

float2 const

returns 1/sqrt(x)

rsqrt_est(x: float2 const)

rsqrt_est returns float2

argument

argument type

x

float2 const

returns the fast approximation 1/sqrt(x)

rsqrt(x: float3 const)

rsqrt returns float3

argument

argument type

x

float3 const

returns 1/sqrt(x)

rsqrt_est(x: float3 const)

rsqrt_est returns float3

argument

argument type

x

float3 const

returns the fast approximation 1/sqrt(x)

rsqrt(x: float4 const)

rsqrt returns float4

argument

argument type

x

float4 const

returns 1/sqrt(x)

rsqrt_est(x: float4 const)

rsqrt_est returns float4

argument

argument type

x

float4 const

returns the fast approximation 1/sqrt(x)

floori(x: float const)

floori returns int

argument

argument type

x

float const

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

ceili(x: float const)

ceili returns int

argument

argument type

x

float const

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

roundi(x: float const)

roundi returns int

argument

argument type

x

float const

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

trunci(x: float const)

trunci returns int

argument

argument type

x

float const

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

floori(x: double const)

floori returns int

argument

argument type

x

double const

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

ceili(x: double const)

ceili returns int

argument

argument type

x

double const

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

roundi(x: double const)

roundi returns int

argument

argument type

x

double const

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

trunci(x: double const)

trunci returns int

argument

argument type

x

double const

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

floori(x: float2 const)

floori returns int2

argument

argument type

x

float2 const

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

ceili(x: float2 const)

ceili returns int2

argument

argument type

x

float2 const

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

roundi(x: float2 const)

roundi returns int2

argument

argument type

x

float2 const

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

trunci(x: float2 const)

trunci returns int2

argument

argument type

x

float2 const

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

floori(x: float3 const)

floori returns int3

argument

argument type

x

float3 const

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

ceili(x: float3 const)

ceili returns int3

argument

argument type

x

float3 const

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

roundi(x: float3 const)

roundi returns int3

argument

argument type

x

float3 const

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

trunci(x: float3 const)

trunci returns int3

argument

argument type

x

float3 const

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

floori(x: float4 const)

floori returns int4

argument

argument type

x

float4 const

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

ceili(x: float4 const)

ceili returns int4

argument

argument type

x

float4 const

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

roundi(x: float4 const)

roundi returns int4

argument

argument type

x

float4 const

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

trunci(x: float4 const)

trunci returns int4

argument

argument type

x

float4 const

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

3.6. float3 only

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

cross returns float3

argument

argument type

x

float3 const

y

float3 const

returns vector representing cross product between x and y

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

distance returns float

argument

argument type

x

float3 const

y

float3 const

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

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

distance_sq returns float

argument

argument type

x

float3 const

y

float3 const

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

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

inv_distance returns float

argument

argument type

x

float3 const

y

float3 const

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

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

inv_distance_sq returns float

argument

argument type

x

float3 const

y

float3 const

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

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

reflect returns float3

argument

argument type

v

float3 const

n

float3 const

returns vector representing reflection of vector v from normal n same as

def reflect(v, n: float3)
    return v - 2. * dot(v, n) * n
refract(v: float3 const; n: float3 const; nint: float const)

refract returns float3

argument

argument type

v

float3 const

n

float3 const

nint

float const

returns vector representing refractoin of vector v from normal n same as

def refract(v, n: float3; nint: float; outRefracted: float3&)
    let dt = dot(v, n)
    let discr = 1. - nint * nint * (1. - dt * dt)
    if discr > 0.
        outRefracted = nint * (v - n * dt) - n * sqrt(discr)
        return true
    return false

3.7. float2, float3, float4

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

dot returns float

argument

argument type

x

float2 const

y

float2 const

returns scalar representing dot product between x and y

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

dot returns float

argument

argument type

x

float3 const

y

float3 const

returns scalar representing dot product between x and y

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

dot returns float

argument

argument type

x

float4 const

y

float4 const

returns scalar representing dot product between x and y

fast_normalize(x: float2 const)

fast_normalize returns float2

argument

argument type

x

float2 const

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

fast_normalize(x: float3 const)

fast_normalize returns float3

argument

argument type

x

float3 const

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

fast_normalize(x: float4 const)

fast_normalize returns float4

argument

argument type

x

float4 const

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

normalize(x: float2 const)

normalize returns float2

argument

argument type

x

float2 const

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

normalize(x: float3 const)

normalize returns float3

argument

argument type

x

float3 const

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

normalize(x: float4 const)

normalize returns float4

argument

argument type

x

float4 const

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

length(x: float2 const)

length returns float

argument

argument type

x

float2 const

returns a non-negative value representing magnitude of x

length(x: float3 const)

length returns float

argument

argument type

x

float3 const

returns a non-negative value representing magnitude of x

length(x: float4 const)

length returns float

argument

argument type

x

float4 const

returns a non-negative value representing magnitude of x

inv_length(x: float2 const)

inv_length returns float

argument

argument type

x

float2 const

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

inv_length(x: float3 const)

inv_length returns float

argument

argument type

x

float3 const

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

inv_length(x: float4 const)

inv_length returns float

argument

argument type

x

float4 const

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

inv_length_sq(x: float2 const)

inv_length_sq returns float

argument

argument type

x

float2 const

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

inv_length_sq(x: float3 const)

inv_length_sq returns float

argument

argument type

x

float3 const

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

inv_length_sq(x: float4 const)

inv_length_sq returns float

argument

argument type

x

float4 const

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

length_sq(x: float2 const)

length_sq returns float

argument

argument type

x

float2 const

returns a non-negative value representing squared magnitude of x

length_sq(x: float3 const)

length_sq returns float

argument

argument type

x

float3 const

returns a non-negative value representing squared magnitude of x

length_sq(x: float4 const)

length_sq returns float

argument

argument type

x

float4 const

returns a non-negative value representing squared magnitude of x

3.8. Noise functions

uint32_hash(seed: uint const)

uint32_hash returns uint

argument

argument type

seed

uint const

returns hashed value of seed

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

uint_noise_1D returns uint

argument

argument type

position

int const

seed

uint const

returns noise value of position in the seeded sequence

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

uint_noise_2D returns uint

argument

argument type

position

int2 const

seed

uint const

returns noise value of position in the seeded sequence

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

uint_noise_3D returns uint

argument

argument type

position

int3 const

seed

uint const

returns noise value of position in the seeded sequence

3.9. lerp/mad/clamp

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

mad returns float

argument

argument type

a

float const

b

float const

c

float const

returns vector or scalar representing a * b + c

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

lerp returns float

argument

argument type

a

float const

b

float const

t

float const

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

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

mad returns float2

argument

argument type

a

float2 const

b

float2 const

c

float2 const

returns vector or scalar representing a * b + c

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

lerp returns float2

argument

argument type

a

float2 const

b

float2 const

t

float2 const

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

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

mad returns float3

argument

argument type

a

float3 const

b

float3 const

c

float3 const

returns vector or scalar representing a * b + c

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

lerp returns float3

argument

argument type

a

float3 const

b

float3 const

t

float3 const

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

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

mad returns float4

argument

argument type

a

float4 const

b

float4 const

c

float4 const

returns vector or scalar representing a * b + c

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

lerp returns float4

argument

argument type

a

float4 const

b

float4 const

t

float4 const

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

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

mad returns float2

argument

argument type

a

float2 const

b

float const

c

float2 const

returns vector or scalar representing a * b + c

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

mad returns float3

argument

argument type

a

float3 const

b

float const

c

float3 const

returns vector or scalar representing a * b + c

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

mad returns float4

argument

argument type

a

float4 const

b

float const

c

float4 const

returns vector or scalar representing a * b + c

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

clamp returns int

argument

argument type

t

int const

a

int const

b

int const

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

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

clamp returns int2

argument

argument type

t

int2 const

a

int2 const

b

int2 const

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

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

clamp returns int3

argument

argument type

t

int3 const

a

int3 const

b

int3 const

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

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

clamp returns int4

argument

argument type

t

int4 const

a

int4 const

b

int4 const

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

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

clamp returns uint

argument

argument type

t

uint const

a

uint const

b

uint const

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

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

clamp returns float

argument

argument type

t

float const

a

float const

b

float const

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

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

clamp returns float2

argument

argument type

t

float2 const

a

float2 const

b

float2 const

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

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

clamp returns float3

argument

argument type

t

float3 const

a

float3 const

b

float3 const

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

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

clamp returns float4

argument

argument type

t

float4 const

a

float4 const

b

float4 const

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

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

clamp returns double

argument

argument type

t

double const

a

double const

b

double const

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

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

clamp returns int64

argument

argument type

t

int64 const

a

int64 const

b

int64 const

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

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

clamp returns uint64

argument

argument type

t

uint64 const

a

uint64 const

b

uint64 const

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

3.10. Matrix operations

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

argument

argument type

x

math::float4x4 const implicit

y

math::float4x4 const implicit

Multiplies x by y.

operator ==(x: float4x4 const implicit; y: float4x4 const implicit)

== returns bool

argument

argument type

x

math::float4x4 const implicit

y

math::float4x4 const implicit

Compares x and y per component. Returns false if at least one component does not match.

operator !=(x: float4x4 const implicit; y: float4x4 const implicit)

!= returns bool

argument

argument type

x

math::float4x4 const implicit

y

math::float4x4 const implicit

Compares x and y per component. Returns true if at least one component does not match.

operator *(x: float3x4 const implicit; y: float3x4 const implicit)

argument

argument type

x

math::float3x4 const implicit

y

math::float3x4 const implicit

Multiplies x by y.

operator *(x: float3x4 const implicit; y: float3 const)
  • returns float3

argument

argument type

x

math::float3x4 const implicit

y

float3 const

Multiplies x by y.

operator *(x: float4x4 const implicit; y: float4 const)
  • returns float4

argument

argument type

x

math::float4x4 const implicit

y

float4 const

Multiplies x by y.

operator ==(x: float3x4 const implicit; y: float3x4 const implicit)

== returns bool

argument

argument type

x

math::float3x4 const implicit

y

math::float3x4 const implicit

Compares x and y per component. Returns false if at least one component does not match.

operator !=(x: float3x4 const implicit; y: float3x4 const implicit)

!= returns bool

argument

argument type

x

math::float3x4 const implicit

y

math::float3x4 const implicit

Compares x and y per component. Returns true if at least one component does not match.

operator *(x: float3x3 const implicit; y: float3x3 const implicit)

argument

argument type

x

math::float3x3 const implicit

y

math::float3x3 const implicit

Multiplies x by y.

operator *(x: float3x3 const implicit; y: float3 const)
  • returns float3

argument

argument type

x

math::float3x3 const implicit

y

float3 const

Multiplies x by y.

operator ==(x: float3x3 const implicit; y: float3x3 const implicit)

== returns bool

argument

argument type

x

math::float3x3 const implicit

y

math::float3x3 const implicit

Compares x and y per component. Returns false if at least one component does not match.

operator !=(x: float3x3 const implicit; y: float3x3 const implicit)

!= returns bool

argument

argument type

x

math::float3x3 const implicit

y

math::float3x3 const implicit

Compares x and y per component. Returns true if at least one component does not match.

3.11. Matrix initializers

float3x3()

float3x3 returns math::float3x3

Returns empty matrix, where each component is 0.

float3x4()

float3x4 returns math::float3x4

Returns empty matrix, where each component is 0.

float4x4()

float4x4 returns math::float4x4

Returns empty matrix, where each component is 0.

float4x4(arg0: float3x4 const implicit)

float4x4 returns math::float4x4

argument

argument type

arg0

math::float3x4 const implicit

Returns empty matrix, where each component is 0.

identity4x4()

identity4x4 returns math::float4x4

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

float3x4(arg0: float4x4 const implicit)

float3x4 returns math::float3x4

argument

argument type

arg0

math::float4x4 const implicit

Returns empty matrix, where each component is 0.

identity3x4()

identity3x4 returns math::float3x4

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

float3x3(arg0: float4x4 const implicit)

float3x3 returns math::float3x3

argument

argument type

arg0

math::float4x4 const implicit

Returns empty matrix, where each component is 0.

float3x3(arg0: float3x4 const implicit)

float3x3 returns math::float3x3

argument

argument type

arg0

math::float3x4 const implicit

Returns empty matrix, where each component is 0.

identity3x3()

identity3x3 returns math::float3x3

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

3.12. Matrix manipulation

identity(x: float4x4 implicit)

argument

argument type

x

math::float4x4 implicit

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

translation(xyz: float3 const)

translation returns math::float4x4

argument

argument type

xyz

float3 const

produces a translation by xyz

1

0

0

0

0

1

0

0

0

0

1

0

x

y

z

1

transpose(x: float4x4 const implicit)

transpose returns math::float4x4

argument

argument type

x

math::float4x4 const implicit

Transposes the specified input matrix x.

persp_forward(wk: float const; hk: float const; zn: float const; zf: float const)

persp_forward returns math::float4x4

argument

argument type

wk

float const

hk

float const

zn

float const

zf

float const

Perspective matrix, zn - 0, zf - 1

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

persp_reverse returns math::float4x4

argument

argument type

wk

float const

hk

float const

zn

float const

zf

float const

Perspective matrix, zn - 1, zf - 0

look_at(eye: float4 const; at: float4 const; up: float4 const)

look_at returns math::float4x4

argument

argument type

eye

float4 const

at

float4 const

up

float4 const

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

compose(pos: float4 const; rot: float4 const; scale: float4 const)

compose returns math::float4x4

argument

argument type

pos

float4 const

rot

float4 const

scale

float4 const

Compose transformation out of translation, rotation and scale.

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

argument

argument type

mat

math::float4x4 const implicit

pos

float3& implicit

rot

float4& implicit

scale

float4& implicit

Decompose transformation into translation, rotation and scale.

identity(x: float3x4 implicit)

argument

argument type

x

math::float3x4 implicit

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

inverse(x: float3x4 const implicit)

inverse returns math::float3x4

argument

argument type

x

math::float3x4 const implicit

Returns the inverse of the matrix x.

inverse(m: float4x4 const implicit)

inverse returns math::float4x4

argument

argument type

m

math::float4x4 const implicit

Returns the inverse of the matrix x.

orthonormal_inverse(m: float4x4 const implicit)

orthonormal_inverse returns math::float4x4

argument

argument type

m

math::float4x4 const implicit

Fast inverse for the orthonormal matrix.

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

rotate returns float3

argument

argument type

x

math::float3x4 const implicit

y

float3 const

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

identity(x: float3x3 implicit)

argument

argument type

x

math::float3x3 implicit

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

3.13. Quaternion operations

un_quat_from_unit_arc(v0: float3 const; v1: float3 const)

un_quat_from_unit_arc returns float4

argument

argument type

v0

float3 const

v1

float3 const

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

un_quat_from_unit_vec_ang(v: float3 const; ang: float const)

un_quat_from_unit_vec_ang returns float4

argument

argument type

v

float3 const

ang

float const

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

un_quat(m: float4x4 const implicit)

un_quat returns float4

argument

argument type

m

math::float4x4 const implicit

Quaternion from the rotation part of the matrix

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

quat_mul returns float4

argument

argument type

q1

float4 const

q2

float4 const

Quaternion which is multiplication of q1 and q2

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

quat_mul_vec returns float3

argument

argument type

q

float4 const

v

float3 const

Transform vector v by quaternion q

quat_conjugate(q: float4 const)

quat_conjugate returns float4

argument

argument type

q

float4 const

Quaternion which is conjugate of q

3.14. Packing and unpacking

pack_float_to_byte(x: float4 const)

pack_float_to_byte returns uint

argument

argument type

x

float4 const

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

unpack_byte_to_float(x: uint const)

unpack_byte_to_float returns float4

argument

argument type

x

uint const

Unpacks byte4 vector to float4 vector.