stdlib/mathView source ↗
math
51 items · generated by scribe fromstdlib/math.fd· synced 2026-11-15
Contents
- math_pi (function)
- math_e (function)
- math_sqrt (function)
- math_sin (function)
- math_cos (function)
- math_floor (function)
- math_ceil (function)
- math_pow (function)
- math_fabs (function)
- math_log (function)
- math_exp (function)
- math_abs_i64 (function)
- math_max_f64 (function)
- math_min_f64 (function)
- math_clamp_f64 (function)
- vec2 (struct)
- vec3 (struct)
- vec4 (struct)
- mat4 (struct)
- quat (struct)
- vec2 (function)
- vec3 (function)
- vec4 (function)
- quat (function)
- radians (function)
- degrees (function)
- lerp (function)
- distance (function)
- vec2 (impl)
- vec3 (impl)
- vec4 (impl)
- mat4 (impl)
- translate (function)
- mat_scale (function)
- quat (impl)
- perspective (function)
- orthographic (function)
- look_at (function)
- rotation_x (function)
- rotation_y (function)
- rotation_z (function)
- vec3_sub (function)
math_pi
The constant pi (3.14159…).
Example: assert(math_pi() > 3.14159 && math_pi() < 3.1416);
pub fn math_pi() -> f64 {Returns: f64
Defined at line 35
math_e
Euler’s number e (2.71828…).
Example: assert(math_fabs(math_log(math_e()) - 1.0) < 0.000001);
pub fn math_e() -> f64 {Returns: f64
Defined at line 43
math_sqrt
Square root of x.
Example: println(float_to_str(math_sqrt(16.0))); assert(math_sqrt(16.0) == 4.0);
pub fn math_sqrt(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 54
math_sin
Sine of x (x in radians).
Example: assert(math_fabs(math_sin(math_pi() / 2.0) - 1.0) < 0.000001);
pub fn math_sin(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 62
math_cos
Cosine of x (x in radians).
Example: assert(math_fabs(math_cos(0.0) - 1.0) < 0.000001);
pub fn math_cos(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 70
math_floor
Floor of x (largest integer <= x).
Example: assert(math_floor(2.7) == 2.0); assert(math_floor(-2.5) == -3.0);
pub fn math_floor(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 79
math_ceil
Ceiling of x (smallest integer >= x).
Example: assert(math_ceil(2.1) == 3.0);
pub fn math_ceil(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 87
math_pow
base raised to the power of exp.
Example: assert(math_pow(2.0, 10.0) == 1024.0);
pub fn math_pow(base: f64, exp: f64) -> f64 {Parameters:
base:f64exp:f64
Returns: f64
Defined at line 95
math_fabs
Absolute value of a float.
Example: assert(math_fabs(-3.5) == 3.5);
pub fn math_fabs(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 103
math_log
Natural logarithm (base e) of x.
Example: assert(math_fabs(math_log(math_exp(2.0)) - 2.0) < 0.000001);
pub fn math_log(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 111
math_exp
Exponential function (e^x).
Example: assert(math_exp(0.0) == 1.0);
pub fn math_exp(x: f64) -> f64 {Parameters:
x:f64
Returns: f64
Defined at line 119
math_abs_i64
Absolute value of an integer.
Example: assert_eq(math_abs_i64(-7), 7);
pub fn math_abs_i64(n: i64) -> i64 {Parameters:
n:i64
Returns: i64
Defined at line 127
math_max_f64
Maximum of two floats.
Example: assert(math_max_f64(1.5, 2.5) == 2.5);
pub fn math_max_f64(a: f64, b: f64) -> f64 {Parameters:
a:f64b:f64
Returns: f64
Defined at line 138
math_min_f64
Minimum of two floats.
Example: assert(math_min_f64(1.5, 2.5) == 1.5);
pub fn math_min_f64(a: f64, b: f64) -> f64 {Parameters:
a:f64b:f64
Returns: f64
Defined at line 149
math_clamp_f64
Clamp a float to a range.
Example: assert(math_clamp_f64(5.0, 0.0, 1.0) == 1.0); assert(math_clamp_f64(-5.0, 0.0, 1.0) == 0.0);
pub fn math_clamp_f64(n: f64, lo: f64, hi: f64) -> f64 {Parameters:
n:f64lo:f64hi:f64
Returns: f64
Defined at line 161
vec2
pub struct vec2 {Fields:
| Name | Type |
|---|---|
x | f64 |
y | f64 |
Defined at line 174
vec3
pub struct vec3 {Fields:
| Name | Type |
|---|---|
x | f64 |
y | f64 |
z | f64 |
Defined at line 178
vec4
pub struct vec4 {Fields:
| Name | Type |
|---|---|
x | f64 |
y | f64 |
z | f64 |
w | f64 |
Defined at line 183
mat4
pub struct mat4 {Fields:
| Name | Type |
|---|---|
m00 | f64 |
m01 | f64 |
m02 | f64 |
m03 | f64 |
m10 | f64 |
m11 | f64 |
m12 | f64 |
m13 | f64 |
m20 | f64 |
m21 | f64 |
m22 | f64 |
m23 | f64 |
m30 | f64 |
m31 | f64 |
m32 | f64 |
m33 | f64 |
Defined at line 191
quat
pub struct quat {Fields:
| Name | Type |
|---|---|
w | f64 |
x | f64 |
y | f64 |
z | f64 |
Defined at line 211
vec2
A 2D vector with components x and y.
Example: var a = vec2(3.0, 4.0); assert(a.length() == 5.0); assert(a.add(vec2(1.0, 1.0)).x == 4.0); assert(a.dot(vec2(1.0, 0.0)) == 3.0);
pub fn vec2(x: f64, y: f64) -> vec2 {Parameters:
x:f64y:f64
Returns: vec2
Defined at line 227
vec3
A 3D vector with components x, y and z.
Example: var x = vec3(1.0, 0.0, 0.0); var y = vec3(0.0, 1.0, 0.0); var z = x.cross(y); assert(z.z == 1.0); assert(x.add(y).scale(2.0).y == 2.0);
pub fn vec3(x: f64, y: f64, z: f64) -> vec3 {Parameters:
x:f64y:f64z:f64
Returns: vec3
Defined at line 241
vec4
A 4D vector with components x, y, z and w.
Example: var v = vec4(1.0, 2.0, 3.0, 1.0); assert(v.xyz().z == 3.0); assert(v.dot(vec4(1.0, 1.0, 1.0, 0.0)) == 6.0);
pub fn vec4(x: f64, y: f64, z: f64, w: f64) -> vec4 {Parameters:
x:f64y:f64z:f64w:f64
Returns: vec4
Defined at line 253
quat
A quaternion (w, x, y, z); quat(1, 0, 0, 0) is no rotation.
Example: var q = quat::from_axis_angle(vec3(0.0, 0.0, 1.0), math_pi() / 2.0); var r = q.rotate_vec3(vec3(1.0, 0.0, 0.0)); assert(math_fabs(r.y - 1.0) < 0.000001);
pub fn quat(w: f64, x: f64, y: f64, z: f64) -> quat {Parameters:
w:f64x:f64y:f64z:f64
Returns: quat
Defined at line 265
radians
Degrees converted to radians.
Example: assert(math_fabs(radians(180.0) - math_pi()) < 0.000001);
pub fn radians(degrees: f64) -> f64 {Parameters:
degrees:f64
Returns: f64
Defined at line 277
degrees
Radians converted to degrees.
Example: assert(math_fabs(degrees(math_pi()) - 180.0) < 0.000001);
pub fn degrees(radians: f64) -> f64 {Parameters:
radians:f64
Returns: f64
Defined at line 285
lerp
Linear interpolation: a at t = 0, b at t = 1.
Example: assert(lerp(10.0, 20.0, 0.25) == 12.5);
pub fn lerp(a: f64, b: f64, t: f64) -> f64 {Parameters:
a:f64b:f64t:f64
Returns: f64
Defined at line 293
distance
Euclidean distance between two points.
Example: assert(distance(vec3(0.0, 0.0, 0.0), vec3(1.0, 2.0, 2.0)) == 3.0);
pub fn distance(a: vec3, b: vec3) -> f64 {Parameters:
a:vec3b:vec3
Returns: f64
Defined at line 301
vec2
impl vec2 {Defined at line 310
vec3
impl vec3 {Defined at line 358
vec4
impl vec4 {Defined at line 412
mat4
impl mat4 {Defined at line 466
translate
A translation matrix that moves points by t.
Example: var p = translate(vec3(1.0, 2.0, 3.0)).transform_vec3(vec3(1.0, 1.0, 1.0)); assert(p.x == 2.0 && p.y == 3.0 && p.z == 4.0);
pub fn translate(t: vec3) -> mat4 {Parameters:
t:vec3
Returns: mat4
Defined at line 503
mat_scale
A uniform scaling matrix.
Example: var p = mat_scale(2.0).transform_vec3(vec3(1.0, 2.0, 3.0)); assert(p.z == 6.0);
pub fn mat_scale(s: f64) -> mat4 {Parameters:
s:f64
Returns: mat4
Defined at line 514
quat
impl quat {Defined at line 522
perspective
Perspective projection matrix (field of view in radians).
pub fn perspective(fov: f64, aspect: f64, near: f64, far: f64) -> mat4 {Parameters:
fov:f64aspect:f64near:f64far:f64
Returns: mat4
Defined at line 641
orthographic
Orthographic projection matrix.
pub fn orthographic(left: f64, right: f64, bottom: f64, top: f64, near: f64, far: f64) -> mat4 {Parameters:
left:f64right:f64bottom:f64top:f64near:f64far:f64
Returns: mat4
Defined at line 650
look_at
Look-at view matrix (camera at eye, looking at target, up direction).
pub fn look_at(eye: vec3, target: vec3, up: vec3) -> mat4 {Parameters:
eye:vec3target:vec3up:vec3
Returns: mat4
Defined at line 660
rotation_x
Rotation matrix around X axis (angle in radians).
pub fn rotation_x(angle: f64) -> mat4 {Parameters:
angle:f64
Returns: mat4
Defined at line 674
rotation_y
Rotation matrix around Y axis (angle in radians).
pub fn rotation_y(angle: f64) -> mat4 {Parameters:
angle:f64
Returns: mat4
Defined at line 683
rotation_z
Rotation matrix around Z axis (angle in radians).
Example: var p = rotation_z(math_pi() / 2.0).transform_vec3(vec3(1.0, 0.0, 0.0)); assert(math_fabs(p.y - 1.0) < 0.000001);
pub fn rotation_z(angle: f64) -> mat4 {Parameters:
angle:f64
Returns: mat4
Defined at line 696
vec3_sub
Helper: vec3 subtraction (for look_at).
Example: var d = vec3_sub(vec3(5.0, 5.0, 5.0), vec3(1.0, 2.0, 3.0)); assert(d.x == 4.0 && d.z == 2.0);
pub fn vec3_sub(a: vec3, b: vec3) -> vec3 {Parameters:
a:vec3b:vec3
Returns: vec3
Defined at line 709
Generated by scribe, the Fides documentation generator