2.2. Math library
The MATH module contains floating point math functions and constants
(trigonometry, exponentials, clamping, interpolation, noise, and vector/matrix operations).
Floating point math in general is not bit-precise: the compiler may optimize
permutations, replace divisions with multiplications, and some functions are
not bit-exact. Use double precision types when exact results are required.
All functions and symbols are in “math” module, use require to get access to it.
require math
Example:
require math
[export]
def main() {
print("sin(PI/2) = {sin(PI / 2.0)}\n")
print("cos(0) = {cos(0.0)}\n")
print("sqrt(16) = {sqrt(16.0)}\n")
print("abs(-5) = {abs(-5)}\n")
print("clamp(15, 0, 10) = {clamp(15, 0, 10)}\n")
print("min(3, 7) = {min(3, 7)}\n")
print("max(3, 7) = {max(3, 7)}\n")
let v = float3(1, 0, 0)
print("length = {length(v)}\n")
}
// output:
// sin(PI/2) = 1
// cos(0) = 1
// sqrt(16) = 4
// abs(-5) = 5
// clamp(15, 0, 10) = 10
// min(3, 7) = 3
// max(3, 7) = 7
// length = 1
2.2.1. Constants
- PI = 3.1415927f
The single-precision float constant pi (3.14159265…), representing the ratio of a circle’s circumference to its diameter.
- DBL_PI = 3.141592653589793lf
The double-precision constant pi (3.141592653589793…), representing the ratio of a circle’s circumference to its diameter.
- FLT_EPSILON = 1.1920929e-07f
The smallest single-precision float value epsilon such that 1.0f + epsilon != 1.0f, approximately 1.1920929e-7.
- DBL_EPSILON = 2.220446049250313e-16lf
The smallest double-precision value epsilon such that 1.0 + epsilon != 1.0, approximately 2.2204460492503131e-16.
2.2.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
2.2.3. all numerics (uint*, int*, float*, double)
2.2.3.1. max
- max(x: int; y: int): int
Returns the component-wise maximum of two values, supporting scalar double, float, int, int64, uint, uint64 and vector float2, float3, float4 types.
- Arguments:
x : int
y : int
- max(x: uint64; y: uint64): uint64
- max(x: int2; y: int2): int2
- max(x: double; y: double): double
- max(x: int4; y: int4): int4
- max(x: int3; y: int3): int3
- max(x: float3; y: float3): float3
- max(x: int64; y: int64): int64
- max(x: uint2; y: uint2): uint2
- max(x: uint; y: uint): uint
- max(x: uint3; y: uint3): uint3
- max(x: float4; y: float4): float4
- max(x: uint4; y: uint4): uint4
- max(x: float2; y: float2): float2
- max(x: float; y: float): float
2.2.3.2. min
- min(x: uint3; y: uint3): uint3
Returns the component-wise minimum of two values, supporting scalar double, float, int, int64, uint, uint64 and vector float2, float3, float4 types.
- Arguments:
x : uint3
y : uint3
- min(x: uint2; y: uint2): uint2
- min(x: int4; y: int4): int4
- min(x: int; y: int): int
- min(x: float3; y: float3): float3
- min(x: float4; y: float4): float4
- min(x: float2; y: float2): float2
- min(x: float; y: float): float
- min(x: int2; y: int2): int2
- min(x: int3; y: int3): int3
- min(x: uint; y: uint): uint
- min(x: uint64; y: uint64): uint64
- min(x: uint4; y: uint4): uint4
- min(x: double; y: double): double
- min(x: int64; y: int64): int64
2.2.4. float* and double
2.2.4.1. abs
- abs(x: float3): float3
Returns the absolute value of the argument, computed component-wise for float2, float3, float4, int2, int3, and int4 vector types, and per-element for scalar float, double, int, and int64 types.
- Arguments:
x : float3
- abs(x: uint): uint
- abs(x: uint64): uint64
- abs(x: int2): int2
- abs(x: int4): int4
- abs(x: int3): int3
- abs(x: int64): int64
- abs(x: uint2): uint2
- abs(x: int): int
- abs(x: uint4): uint4
- abs(x: uint3): uint3
- abs(x: double): double
- abs(x: float): float
- abs(x: float4): float4
- abs(x: float2): float2
2.2.4.2. acos
- acos(x: float4): float4
Returns the arccosine of x in radians; the input must be in the range [-1, 1] and the result is in the range [0, pi]; works with float and double.
- Arguments:
x : float4
- acos(x: float2): float2
- acos(x: float): float
- acos(x: float3): float3
- acos(x: double): double
2.2.4.3. asin
- asin(x: float): float
Returns the arcsine of x in radians; the input must be in the range [-1, 1] and the result is in the range [-pi/2, pi/2]; works with float and double.
- Arguments:
x : float
- asin(x: double): double
- asin(x: float3): float3
- asin(x: float4): float4
- asin(x: float2): float2
2.2.4.4. atan
- atan(x: float2): float2
Returns the arctangent of x in radians, with the result in the range [-pi/2, pi/2]; works with float and double.
- Arguments:
x : float2
- atan(x: float4): float4
- atan(x: double): double
- atan(x: float3): float3
- atan(x: float): float
2.2.4.5. atan2
- atan2(y: float3; x: float3): float3
Returns the arctangent of y/x in radians, using the signs of both arguments to determine the correct quadrant; the result is in the range [-pi, pi]; works with float and double.
- Arguments:
y : float3
x : float3
- atan2(y: float2; x: float2): float2
- atan2(y: float; x: float): float
- atan2(y: float4; x: float4): float4
- atan2(y: double; x: double): double
2.2.4.6. ceil
- ceil(x: float4): float4
Returns the smallest integral value not less than x (rounds toward positive infinity), computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float4
- ceil(x: float3): float3
- ceil(x: float2): float2
- ceil(x: float): float
2.2.4.7. cos
- cos(x: double): double
Returns the cosine of x, where x is specified in radians; works with float and double.
- Arguments:
x : double
- cos(x: float4): float4
- cos(x: float3): float3
- cos(x: float): float
- cos(x: float2): float2
2.2.4.8. exp
- exp(x: float4): float4
Returns e raised to the power of x (the base-e exponential), computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float4
- exp(x: double): double
- exp(x: float2): float2
- exp(x: float): float
- exp(x: float3): float3
2.2.4.9. exp2
- exp2(x: float4): float4
Returns 2 raised to the power of x, computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float4
- exp2(x: float3): float3
- exp2(x: float2): float2
- exp2(x: double): double
- exp2(x: float): float
2.2.4.10. floor
- floor(x: float): float
Returns the largest integral value not greater than x (rounds toward negative infinity), computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float
- floor(x: float2): float2
- floor(x: float4): float4
- floor(x: float3): float3
2.2.4.11. is_finite
- is_finite(x: float): bool
Returns true if x is a finite value (not infinity and not NaN), checked component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float
- is_finite(x: double): bool
2.2.4.12. is_nan
- is_nan(x: float): bool
Returns true if x is NaN (Not a Number), checked component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float
- is_nan(x: double): bool
2.2.4.13. log
- log(x: float4): float4
Returns the natural (base-e) logarithm of x; the input must be positive; computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float4
- log(x: float3): float3
- log(x: float2): float2
- log(x: double): double
- log(x: float): float
2.2.4.14. log2
- log2(x: double): double
Returns the base-2 logarithm of x; the input must be positive; computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : double
- log2(x: float4): float4
- log2(x: float3): float3
- log2(x: float2): float2
- log2(x: float): float
2.2.4.15. pow
- pow(x: double; y: double): double
Returns x raised to the power of y for scalar double, float, or vector float2, float3, float4 types; domain requires x >= 0 for non-integer y values.
- Arguments:
x : double
y : double
- pow(x: float4; y: float4): float4
- pow(x: float3; y: float3): float3
- pow(x: float; y: float): float
- pow(x: float2; y: float2): float2
2.2.4.16. rcp
- rcp(x: double): double
Returns the reciprocal (1/x) of a scalar float or each component of a float2, float3, or float4 vector.
- Arguments:
x : double
- rcp(x: float4): float4
- rcp(x: float3): float3
- rcp(x: float2): float2
- rcp(x: float): float
2.2.4.17. safe_acos
- safe_acos(x: double): double
Returns the arccosine of x in radians, clamping the input to the valid domain [-1, 1] to prevent NaN results from out-of-range values.
- Arguments:
x : double
- safe_acos(x: float2): float2
- safe_acos(x: float3): float3
- safe_acos(x: float): float
- safe_acos(x: float4): float4
2.2.4.18. safe_asin
- safe_asin(x: float3): float3
Returns the arcsine of x in radians, clamping the input to the valid domain [-1, 1] to prevent NaN results from out-of-range values.
- Arguments:
x : float3
- safe_asin(x: float4): float4
- safe_asin(x: double): double
- safe_asin(x: float2): float2
- safe_asin(x: float): float
2.2.4.19. saturate
- saturate(x: float4): float4
Clamps the scalar double, float, or each component of a float2, float3, float4 vector to the [0, 1] range, returning 0 for values below 0 and 1 for values above 1.
- Arguments:
x : float4
- saturate(x: float3): float3
- saturate(x: float2): float2
- saturate(x: float): float
2.2.4.20. sign
- sign(x: uint): uint
Returns the sign of x component-wise: -1 for negative, 0 for zero, or 1 for positive. For unsigned types, the result is 0 or 1.
- Arguments:
x : uint
- sign(x: uint2): uint2
- sign(x: int4): int4
- sign(x: float4): float4
- sign(x: int64): int64
- sign(x: double): double
- sign(x: float3): float3
- sign(x: uint4): uint4
- sign(x: float): float
- sign(x: float2): float2
- sign(x: uint64): uint64
- sign(x: int3): int3
- sign(x: int): int
- sign(x: int2): int2
- sign(x: uint3): uint3
2.2.4.21. sin
- sin(x: double): double
Returns the sine of the angle x given in radians for double or float, with output in the range [-1, 1].
- Arguments:
x : double
- sin(x: float4): float4
- sin(x: float3): float3
- sin(x: float2): float2
- sin(x: float): float
2.2.4.22. sincos
- sincos(x: float; s: float&; c: float&)
Computes both the sine and cosine of the angle x in radians simultaneously, writing the results to output parameters s and c, for float or double types.
- Arguments:
x : float
s : float& implicit
c : float& implicit
- sincos(x: double; s: double&; c: double&)
2.2.4.23. sqrt
- sqrt(x: double): double
Returns the square root of a scalar double, float, or each component of a float2, float3, or float4 vector; input must be non-negative.
- Arguments:
x : double
- sqrt(x: float4): float4
- sqrt(x: float3): float3
- sqrt(x: float2): float2
- sqrt(x: float): float
2.2.4.24. tan
- tan(x: double): double
Returns the tangent of the angle x given in radians for double or float; undefined at odd multiples of pi/2.
- Arguments:
x : double
- tan(x: float4): float4
- tan(x: float2): float2
- tan(x: float): float
- tan(x: float3): float3
2.2.5. float* only
2.2.5.1. atan2_est
- atan2_est(y: float; x: float): float
Returns a fast estimated arctangent of y/x in radians, using the signs of both arguments to determine the correct quadrant; trades some precision for speed.
- Arguments:
y : float
x : float
- atan2_est(y: float4; x: float4): float4
- atan2_est(y: float3; x: float3): float3
- atan2_est(y: float2; x: float2): float2
2.2.5.2. atan_est
- atan_est(x: float2): float2
Returns a fast estimated arctangent of x in radians, trading some precision for speed; the result approximates the range [-pi/2, pi/2].
- Arguments:
x : float2
- atan_est(x: float4): float4
- atan_est(x: float): float
- atan_est(x: float3): float3
2.2.5.3. ceili
- ceili(x: float4): int4
Returns the smallest integer not less than x (rounds toward positive infinity), converting the float argument to an int result.
- Arguments:
x : float4
- ceili(x: float): int
- ceili(x: double): int
- ceili(x: float3): int3
- ceili(x: float2): int2
- float3x3-(x: float3x3): float3x3
Returns the component-wise arithmetic negation of a matrix, flipping the sign of every element; works with float3x3, float3x4, and float4x4 matrix types.
- Arguments:
x : float3x3 implicit
- float3x4-(x: float3x4): float3x4
Returns the component-wise arithmetic negation of a matrix, flipping the sign of every element; works with float3x3, float3x4, and float4x4 matrix types.
- Arguments:
x : float3x4 implicit
- float4x4-(x: float4x4): float4x4
Returns the component-wise arithmetic negation of a matrix, flipping the sign of every element; works with float3x3, float3x4, and float4x4 matrix types.
- Arguments:
x : float4x4 implicit
2.2.5.4. floori
- floori(x: float): int
Returns the largest integer not greater than x (rounds toward negative infinity), converting the float argument to an int result.
- Arguments:
x : float
- floori(x: float2): int2
- floori(x: float4): int4
- floori(x: double): int
- floori(x: float3): int3
2.2.5.5. fract
- fract(x: float3): float3
Returns the fractional part of x (equivalent to x - floor(x)), computed component-wise for float2, float3, and float4 vector types; works with float and double scalars.
- Arguments:
x : float3
- fract(x: float4): float4
- fract(x: float2): float2
- fract(x: float): float
2.2.5.6. rcp_est
- rcp_est(x: float4): float4
Returns a fast hardware estimate of the reciprocal (1/x) of a scalar float or each component of a float2, float3, or float4 vector, trading precision for speed.
- Arguments:
x : float4
- rcp_est(x: float2): float2
- rcp_est(x: float): float
- rcp_est(x: float3): float3
2.2.5.7. round
- round(x: float4): float4
Rounds each component of the scalar double, float, or vector float2, float3, float4 value x to the nearest integer, with halfway cases rounded to the nearest even value.
- Arguments:
x : float4
- round(x: float3): float3
- round(x: float2): float2
- round(x: float): float
2.2.5.8. roundi
- roundi(x: float4): int4
Rounds the float x to the nearest integer value and returns the result as an int.
- Arguments:
x : float4
- roundi(x: float2): int2
- roundi(x: float3): int3
- roundi(x: double): int
- roundi(x: float): int
2.2.5.9. rsqrt
- rsqrt(x: float4): float4
Returns the reciprocal square root (1/sqrt(x)) of a scalar float or each component of a float2, float3, or float4 vector.
- Arguments:
x : float4
- rsqrt(x: float2): float2
- rsqrt(x: float): float
- rsqrt(x: float3): float3
2.2.5.10. rsqrt_est
- rsqrt_est(x: float3): float3
Returns a fast hardware estimate of the reciprocal square root (1/sqrt(x)) of a scalar float or each component of a float2, float3, or float4 vector, trading precision for speed.
- Arguments:
x : float3
- rsqrt_est(x: float4): float4
- rsqrt_est(x: float2): float2
- rsqrt_est(x: float): float
2.2.5.11. trunci
- trunci(x: double): int
Truncates the float x toward zero to the nearest integer and returns the result as an int.
- Arguments:
x : double
- trunci(x: float): int
- trunci(x: float2): int2
- trunci(x: float4): int4
- trunci(x: float3): int3
2.2.6. float3 only
- cross(x: float3; y: float3): float3
Returns the cross product of two float3 vectors, producing a float3 vector perpendicular to both inputs with magnitude equal to the area of the parallelogram they span.
- Arguments:
x : float3
y : float3
2.2.6.1. distance
- distance(x: float2; y: float2): float
Returns the Euclidean distance between two vectors as a float scalar; works with float2, float3, and float4 vector types.
- Arguments:
x : float2
y : float2
- distance(x: float4; y: float4): float
- distance(x: float3; y: float3): float
2.2.6.2. distance_sq
- distance_sq(x: float3; y: float3): float
Returns the squared Euclidean distance between two vectors as a float scalar, avoiding the square root for faster distance comparisons; works with float2, float3, and float4 vector types.
- Arguments:
x : float3
y : float3
- distance_sq(x: float2; y: float2): float
- distance_sq(x: float4; y: float4): float
2.2.6.3. inv_distance
- inv_distance(x: float3; y: float3): float
Returns the reciprocal of the Euclidean distance between two vectors (1 / distance(x, y)) as a float; works with float2, float3, and float4 vector types.
- Arguments:
x : float3
y : float3
- inv_distance(x: float2; y: float2): float
- inv_distance(x: float4; y: float4): float
2.2.6.4. inv_distance_sq
- inv_distance_sq(x: float4; y: float4): float
Returns the reciprocal of the squared Euclidean distance between two vectors (1 / distance_sq(x, y)) as a float; works with float2, float3, and float4 vector types.
- Arguments:
x : float4
y : float4
- inv_distance_sq(x: float2; y: float2): float
- inv_distance_sq(x: float3; y: float3): float
2.2.6.5. reflect
- reflect(v: float3; n: float3): float3
Computes the reflection of float2 or float3 vector v off a surface with unit normal n, returning the reflected vector as v - 2*dot(v,n)*n.
- Arguments:
v : float3
n : float3
- reflect(v: float2; n: float2): float2
2.2.6.6. refract
- refract(v: float2; n: float2; nint: float): float2
Computes the refraction direction of vector v through a surface with unit normal n using Snell’s law with index of refraction ratio nint. Returns a zero vector if total internal reflection occurs.
- Arguments:
v : float2
n : float2
nint : float
- refract(v: float3; n: float3; nint: float): float3
2.2.7. float2, float3, float4
2.2.7.1. dot
- dot(x: float3; y: float3): float
Returns the dot product (scalar product) of two vectors as a float; works with float2, float3, and float4 vector types.
- Arguments:
x : float3
y : float3
- dot(x: float2; y: float2): float
- dot(x: float4; y: float4): float
2.2.7.2. fast_normalize
- fast_normalize(x: float2): float2
Returns a unit-length vector in the same direction as x using a fast approximation; does not check for zero-length input; works with float2, float3, and float4 vector types.
- Arguments:
x : float2
- fast_normalize(x: float4): float4
- fast_normalize(x: float3): float3
2.2.7.3. inv_length
- inv_length(x: float4): float
Returns the reciprocal of the length of the vector (1 / length(x)) as a float; works with float2, float3, and float4 vector types.
- Arguments:
x : float4
- inv_length(x: float3): float
- inv_length(x: float2): float
2.2.7.4. inv_length_sq
- inv_length_sq(x: float4): float
Returns the reciprocal of the squared length of the vector (1 / length_sq(x)) as a float; works with float2, float3, and float4 vector types.
- Arguments:
x : float4
- inv_length_sq(x: float2): float
- inv_length_sq(x: float3): float
2.2.7.5. length
- length(x: float3): float
Returns the Euclidean length (magnitude) of the vector as a float; works with float2, float3, and float4 vector types.
- Arguments:
x : float3
- length(x: float2): float
- length(x: float4): float
2.2.7.6. length_sq
- length_sq(x: float3): float
Returns the squared Euclidean length of the vector as a float, equivalent to dot(x, x) and avoiding the square root for faster magnitude comparisons; works with float2, float3, and float4 vector types.
- Arguments:
x : float3
- length_sq(x: float2): float
- length_sq(x: float4): float
2.2.7.7. normalize
- normalize(x: float2): float2
Returns a unit-length vector with the same direction as the input float2, float3, or float4 vector; behavior is undefined if the input vector has zero length.
- Arguments:
x : float2
- normalize(x: float3): float3
- normalize(x: float4): float4
2.2.8. Noise functions
- uint32_hash(seed: uint): uint
Returns a well-distributed uint hash of the input uint seed using an improved integer hash function suitable for hash tables and procedural generation.
- Arguments:
seed : uint
- uint_noise_1D(position: int; seed: uint): uint
Generates a deterministic uint hash value from a 1D integer position and a uint seed, suitable for repeatable procedural noise.
- Arguments:
position : int
seed : uint
- uint_noise_2D(position: int2; seed: uint): uint
Generates a deterministic uint hash value from 2D integer coordinates (x, y) and a uint seed, suitable for repeatable procedural noise.
- Arguments:
position : int2
seed : uint
- uint_noise_3D(position: int3; seed: uint): uint
Generates a deterministic uint hash value from 3D integer coordinates (x, y, z) and a uint seed, suitable for repeatable procedural noise.
- Arguments:
position : int3
seed : uint
2.2.9. lerp/mad/clamp
2.2.9.1. clamp
- clamp(t: float; a: float; b: float): float
Returns the value t clamped to the inclusive range [a, b], equivalent to min(max(t, a), b); works with float, double, float2, float3, float4, int, int64, uint, and uint64 types.
- Arguments:
t : float
a : float
b : float
- clamp(t: int64; a: int64; b: int64): int64
- clamp(t: int3; a: int3; b: int3): int3
- clamp(t: uint3; a: uint3; b: uint3): uint3
- clamp(t: int; a: int; b: int): int
- clamp(t: uint64; a: uint64; b: uint64): uint64
- clamp(t: int4; a: int4; b: int4): int4
- clamp(t: int2; a: int2; b: int2): int2
- clamp(t: float4; a: float4; b: float4): float4
- clamp(t: float2; a: float2; b: float2): float2
- clamp(t: uint4; a: uint4; b: uint4): uint4
- clamp(t: float3; a: float3; b: float3): float3
- clamp(t: double; a: double; b: double): double
- clamp(t: uint; a: uint; b: uint): uint
- clamp(t: uint2; a: uint2; b: uint2): uint2
2.2.9.2. lerp
- lerp(a: double; b: double; t: double): double
Performs linear interpolation between a and b using the factor t, returning a + (b - a) * t; when t is 0 the result is a, when t is 1 the result is b; works component-wise with float, double, float2, float3, and float4 types.
- Arguments:
a : double
b : double
t : double
- lerp(a: float4; b: float4; t: float4): float4
- lerp(a: float3; b: float3; t: float3): float3
- lerp(a: float2; b: float2; t: float2): float2
- lerp(a: float; b: float; t: float): float
- lerp(a: float3; b: float3; t: float): float3
- lerp(a: float4; b: float4; t: float): float4
- lerp(a: float2; b: float2; t: float): float2
2.2.9.3. mad
- mad(a: uint4; b: uint4; c: uint4): uint4
Computes the fused multiply-add operation a * b + c.
- Arguments:
a : uint4
b : uint4
c : uint4
- mad(a: uint3; b: uint3; c: uint3): uint3
- mad(a: uint2; b: uint; c: uint2): uint2
- mad(a: uint; b: uint; c: uint): uint
- mad(a: int3; b: int; c: int3): int3
- mad(a: int2; b: int; c: int2): int2
- mad(a: int4; b: int; c: int4): int4
- mad(a: uint2; b: uint2; c: uint2): uint2
- mad(a: uint3; b: uint; c: uint3): uint3
- mad(a: int2; b: int2; c: int2): int2
- mad(a: float4; b: float; c: float4): float4
- mad(a: float3; b: float; c: float3): float3
- mad(a: int; b: int; c: int): int
- mad(a: int3; b: int3; c: int3): int3
- mad(a: float4; b: float4; c: float4): float4
- mad(a: double; b: double; c: double): double
- mad(a: float; b: float; c: float): float
- mad(a: float2; b: float2; c: float2): float2
- mad(a: float3; b: float3; c: float3): float3
- mad(a: float2; b: float; c: float2): float2
- mad(a: int4; b: int4; c: int4): int4
- mad(a: uint4; b: uint; c: uint4): uint4
2.2.10. Matrix element access
float3x3 const implicit ==const.[] (m: float3x3 const implicit ==const; i: int) : float3
float3x3 const implicit ==const.[] (m: float3x3 const implicit ==const; i: uint) : float3
float3x3 implicit ==const.[] (m: float3x3 implicit ==const; i: int) : float3&
float3x3 implicit ==const.[] (m: float3x3 implicit ==const; i: uint) : float3&
float3x4 const implicit ==const.[] (m: float3x4 const implicit ==const; i: uint) : float3
float3x4 const implicit ==const.[] (m: float3x4 const implicit ==const; i: int) : float3
float3x4 implicit ==const.[] (m: float3x4 implicit ==const; i: uint) : float3&
float3x4 implicit ==const.[] (m: float3x4 implicit ==const; i: int) : float3&
float4x4 const implicit ==const.[] (m: float4x4 const implicit ==const; i: uint) : float4
float4x4 const implicit ==const.[] (m: float4x4 const implicit ==const; i: int) : float4
float4x4 implicit ==const.[] (m: float4x4 implicit ==const; i: int) : float4&
float4x4 implicit ==const.[] (m: float4x4 implicit ==const; i: uint) : float4&
2.2.10.1. float3x3 const implicit ==const.[]
- float3x3 const implicit ==const.[](m: float3x3 const implicit ==const; i: int): float3
Returns a copy of the row vector at index i from a constant float3x3 matrix.
- Arguments:
m : float3x3 implicit!
i : int
- float3x3 const implicit ==const.[](m: float3x3 const implicit ==const; i: uint): float3
2.2.10.2. float3x3 implicit ==const.[]
- float3x3 implicit ==const.[](m: float3x3 implicit ==const; i: int): float3&
Returns a reference to the row vector at index i from a float3x3 matrix.
- Arguments:
m : float3x3 implicit!
i : int
- float3x3 implicit ==const.[](m: float3x3 implicit ==const; i: uint): float3&
2.2.10.3. float3x4 const implicit ==const.[]
- float3x4 const implicit ==const.[](m: float3x4 const implicit ==const; i: uint): float3
Returns a copy of the row vector at index i from a constant float3x4 matrix.
- Arguments:
m : float3x4 implicit!
i : uint
- float3x4 const implicit ==const.[](m: float3x4 const implicit ==const; i: int): float3
2.2.10.4. float3x4 implicit ==const.[]
- float3x4 implicit ==const.[](m: float3x4 implicit ==const; i: uint): float3&
Returns a reference to the row vector at index i from a float3x4 matrix.
- Arguments:
m : float3x4 implicit!
i : uint
- float3x4 implicit ==const.[](m: float3x4 implicit ==const; i: int): float3&
2.2.10.5. float4x4 const implicit ==const.[]
- float4x4 const implicit ==const.[](m: float4x4 const implicit ==const; i: uint): float4
Returns a copy of the row vector at index i from a constant float4x4 matrix.
- Arguments:
m : float4x4 implicit!
i : uint
- float4x4 const implicit ==const.[](m: float4x4 const implicit ==const; i: int): float4
2.2.10.6. float4x4 implicit ==const.[]
- float4x4 implicit ==const.[](m: float4x4 implicit ==const; i: int): float4&
Returns a reference to the row vector at index i from a float4x4 matrix.
- Arguments:
m : float4x4 implicit!
i : int
- float4x4 implicit ==const.[](m: float4x4 implicit ==const; i: uint): float4&
2.2.11. Matrix operations
- float3x3!=(x: float3x3; y: float3x3): bool
Returns true if two float3x3 matrices are not equal, comparing all elements component-wise.
2.2.11.1. float3x3*
- float3x3*(x: float3x3; y: float3x3): float3x3
Transforms a float3 vector by a 3x3 matrix.
- float3x3*(x: float3x3; y: float3): float3
- float3x3==(x: float3x3; y: float3x3): bool
Returns true if two float3x3 matrices are exactly equal, comparing all elements component-wise.
- float3x4!=(x: float3x4; y: float3x4): bool
Returns true if two float3x4 matrices are not equal, comparing all elements component-wise.
2.2.11.2. float3x4*
- float3x4*(x: float3x4; y: float3x4): float3x4
Transforms a float3 vector by a 3x3 matrix.
- float3x4*(x: float3x4; y: float3): float3
- float3x4==(x: float3x4; y: float3x4): bool
Returns true if two float3x4 matrices are exactly equal, comparing all elements component-wise.
- float4x4!=(x: float4x4; y: float4x4): bool
Returns true if two float4x4 matrices are not equal, comparing all elements component-wise.
2.2.11.3. float4x4*
- float4x4*(x: float4x4; y: float4): float4
Transforms a float4 vector by a 4x4 matrix.
- Arguments:
x : float4x4 implicit
y : float4
- float4x4*(x: float4x4; y: float4x4): float4x4
- float4x4==(x: float4x4; y: float4x4): bool
Returns true if two float4x4 matrices are exactly equal, comparing all elements component-wise.
2.2.12. Matrix initializers
2.2.12.1. float3x3
- float3x3(arg0: float3x4): float3x3
Extracts the upper-left 3x3 rotation part from a float3x4 transformation matrix, returning it as a float3x3.
- Arguments:
arg0 : float3x4 implicit
- float3x3(): float3x3
- float3x3(arg0: float4x4): float3x3
2.2.12.2. float3x4
- float3x4(arg0: float4x4): float3x4
Constructs a float3x4 transformation matrix from a float3x3 rotation matrix, with the translation component set to zero.
- Arguments:
arg0 : float4x4 implicit
- float3x4(): float3x4
2.2.12.3. float4x4
- float4x4(arg0: float3x4): float4x4
Converts a float3x4 transformation matrix to a float4x4 matrix, filling the fourth row with [0, 0, 0, 1].
- Arguments:
arg0 : float3x4 implicit
- float4x4(): float4x4
- identity3x3(): float3x3
Returns a float3x3 identity matrix with ones on the diagonal and zeros elsewhere.
- identity3x4(): float3x4
Returns a float3x4 identity transformation matrix with the rotation part set to identity and the translation set to zero.
- identity4x4(): float4x4
Returns a float4x4 identity matrix with ones on the diagonal and zeros elsewhere.
2.2.13. Matrix manipulation
- compose(pos: float3; rot: float4; scale: float3): float4x4
Constructs a float4x4 transformation matrix from a float3 translation position, a float4 quaternion rotation, and a float3 scale.
- Arguments:
pos : float3
rot : float4
scale : float3
- decompose(mat: float4x4; pos: float3&; rot: float4&; scale: float3&)
Decomposes a float4x4 transformation matrix into its float3 translation position, float4 quaternion rotation, and float3 scale components., writing the results into the output arguments rot and pos.
- Arguments:
mat : float4x4 implicit
pos : float3& implicit
rot : float4& implicit
scale : float3& implicit
2.2.13.1. determinant
- determinant(x: float3x4): float
Returns the determinant of a float3x4 matrix as a float scalar; a zero determinant indicates the matrix is singular and non-invertible.
- Arguments:
x : float3x4 implicit
- determinant(x: float4x4): float
- determinant(x: float3x3): float
2.2.13.2. identity
- identity(x: float3x4)
Sets the given float3x4 matrix to the identity transformation (rotation part is the identity matrix, translation is zero) and returns it.
- Arguments:
x : float3x4 implicit
- identity(x: float4x4)
- identity(x: float3x3)
2.2.13.3. inverse
- inverse(x: float3x4): float3x4
Returns the inverse of a matrix, such that multiplying the original by its inverse yields the identity; works with float3x4 and float4x4 matrix types.
- Arguments:
x : float3x4 implicit
- inverse(m: float4x4): float4x4
- look_at(eye: float3; at: float3; up: float3): float4x4
Constructs a float4x4 look-at view transformation matrix from eye position, target position, and up vector. from an eye position, a target point to look at, and an up direction vector.
- Arguments:
eye : float3
at : float3
up : float3
2.2.13.4. orthonormal_inverse
- orthonormal_inverse(m: float3x3): float3x3
Returns the inverse of a float3x3 orthonormal matrix (each axis is unit length and mutually perpendicular), computed more efficiently than a general matrix inverse.
- Arguments:
m : float3x3 implicit
- orthonormal_inverse(m: float3x4): float3x4
- persp_forward(wk: float; hk: float; zn: float; zf: float): float4x4
Returns a forward (standard) perspective projection float4x4 matrix constructed from horizontal scale wk, vertical scale hk, near plane zn, and far plane zf.
- Arguments:
wk : float
hk : float
zn : float
zf : float
- persp_reverse(wk: float; hk: float; zn: float; zf: float): float4x4
Returns a reverse-depth perspective projection float4x4 matrix constructed from horizontal scale wk, vertical scale hk, near plane zn, and far plane zf, mapping the far plane to 0 and the near plane to 1.
- Arguments:
wk : float
hk : float
zn : float
zf : float
- rotate(x: float3x4; y: float3): float3
Rotates a float3 vector v by the 3x3 rotation part of the float3x4 matrix m, ignoring the translation component.
- Arguments:
x : float3x4 implicit
y : float3
- translation(xyz: float3): float4x4
Constructs a float4x4 matrix representing a pure translation by the given float3 offset. by the float3 offset xyz, with the rotation part set to identity.
- Arguments:
xyz : float3
- transpose(x: float4x4): float4x4
Returns the transpose of a float3x3 or float4x4 matrix, swapping rows and columns.
- Arguments:
x : float4x4 implicit
2.2.14. Quaternion operations
- euler_from_quat(angles: float4): float3
Converts a float4 quaternion to Euler angles, returning a float3 representing rotation around the x, y, and z axes in radians.
- Arguments:
angles : float4
2.2.14.1. quat
- quat(m: float4x4): float4
Extracts the rotation part of a float3x4 matrix and returns it as a float4 quaternion in (x, y, z, w) format.
- Arguments:
m : float4x4 implicit
- quat(m: float3x3): float4
- quat(m: float3x4): float4
- quat_conjugate(q: float4): float4
Returns the conjugate of the float4 quaternion q by negating its xyz components, which for unit quaternions equals the inverse rotation.
- Arguments:
q : float4
2.2.14.2. quat_from_euler
- quat_from_euler(x: float; y: float; z: float): float4
Creates a float4 quaternion from a float3 of Euler angles (pitch, yaw, roll) given in radians.
- Arguments:
x : float
y : float
z : float
- quat_from_euler(angles: float3): float4
- quat_from_unit_arc(v0: float3; v1: float3): float4
Creates a float4 quaternion representing the shortest rotation arc from unit-length float3 vector v0 to unit-length float3 vector v1; both input vectors must be normalized.
- Arguments:
v0 : float3
v1 : float3
- quat_from_unit_vec_ang(v: float3; ang: float): float4
Creates a float4 quaternion representing a rotation of ang radians around the unit-length float3 axis vector v.
- Arguments:
v : float3
ang : float
- quat_mul(q1: float4; q2: float4): float4
Returns the float4 quaternion product of q1 and q2, representing the combined rotation of q2 followed by q1.
- Arguments:
q1 : float4
q2 : float4
- quat_mul_vec(q: float4; v: float3): float3
Rotates a float3 vector v by the float4 quaternion q and returns the resulting float3 vector.
- Arguments:
q : float4
v : float3
- quat_slerp(t: float; a: float4; b: float4): float4
Performs spherical linear interpolation between float4 quaternions a and b by factor t in the range [0,1], returning a smoothly interpolated float4 quaternion.
- Arguments:
t : float
a : float4
b : float4
2.2.15. Packing and unpacking
- pack_float_to_byte(x: float4): uint
Packs a float4 vector into a single uint by converting each component to an 8-bit byte value, mapping the XYZW components to the four bytes of the result.
- Arguments:
x : float4
- unpack_byte_to_float(x: uint): float4
Unpacks the four bytes of a uint into a float4 vector, converting each 8-bit byte value to its corresponding floating-point component.
- Arguments:
x : uint