Math
Auto-generated from
src/stdlib/math.mcrs— do not edit manually.
API
- abs
- sign
- min
- max
- clamp
- lerp
- lerp_t1000
- sqrt_fixed
- sqrt_fx1000
- mul_fx1000
- div_fx1000
- smoothstep_t1000
- smootherstep_t1000
abs v1.0.0
Return the absolute value of x.
fn abs<T>(x: T) -> TParameters
| Parameter | Description |
|---|---|
x | The input value (any numeric type T) |
Returns: x if x >= 0, else -x
Example
let a = abs(-5) // result: 5
let b = abs(3) // result: 3sign v1.0.0
Return the sign of x: 1, 0, or -1.
fn sign(x: int) -> intParameters
| Parameter | Description |
|---|---|
x | Input integer |
Returns: 1 if x > 0, -1 if x < 0, 0 if x == 0
Example
let s = sign(-42) // result: -1min v1.0.0
Return the smaller of two values.
fn min<T>(a: T, b: T) -> TParameters
| Parameter | Description |
|---|---|
a | First value |
b | Second value |
Returns: a if a < b, else b
Example
let m = min(3, 7) // result: 3max v1.0.0
Return the larger of two values.
fn max<T>(a: T, b: T) -> TParameters
| Parameter | Description |
|---|---|
a | First value |
b | Second value |
Returns: a if a > b, else b
Example
let m = max(3, 7) // result: 7clamp v1.0.0
Clamp x to the range [lo, hi].
fn clamp<T>(x: T, lo: T, hi: T) -> TParameters
| Parameter | Description |
|---|---|
x | Input value |
lo | Lower bound (inclusive) |
hi | Upper bound (inclusive) |
Returns: lo if x < lo; hi if x > hi; otherwise x
Example
let c = clamp(150, 0, 100) // result: 100
let d = clamp(50, 0, 100) // result: 50lerp v1.0.0
Linear interpolation between a and b using fixed-point t in [0, 1000].
fn lerp(a: int, b: int, t: int) -> intParameters
| Parameter | Description |
|---|---|
a | Start value |
b | End value |
t | Interpolation factor ×1000 (0 = a, 1000 = b) |
Returns: a + (b - a) * t / 1000
Example
let v = lerp(0, 1000, 500) // result: 500
let w = lerp(100, 200, 750) // result: 175lerp_t1000 v3.1.0
Explicit alias for legacy ×1000 interpolation. Prefer this name in new code when the t parameter is a ×1000 fraction. lerp remains available for compatibility.
fn lerp_t1000(a: int, b: int, t: int) -> intsqrt_fixed v1.0.0
Fixed-point square root (scale = 1000).
fn sqrt_fixed(x: int) -> intParameters
| Parameter | Description |
|---|---|
x | Input value ×1000 (i.e. 2.0 → 2000) |
Returns: sqrt(x/1000) × 1000
Example
let s = sqrt_fixed(2000) // result: ~1414 (√2 × 1000)
let t = sqrt_fixed(1000) // result: 1000 (√1 × 1000)sqrt_fx1000 v3.1.0
Explicit alias for legacy ×1000 square root. Prefer this name in new code to avoid confusing it with language fixed (×10000). sqrt_fixed remains available for compatibility.
fn sqrt_fx1000(x: int) -> intmul_fx1000 v3.1.0
Explicit alias for legacy ×1000 fixed-point multiply. mulfix remains available for compatibility.
fn mul_fx1000(a: int, b: int) -> intdiv_fx1000 v3.1.0
Explicit alias for legacy ×1000 fixed-point divide. divfix remains available for compatibility.
fn div_fx1000(a: int, b: int) -> intsmoothstep_t1000 v3.1.0
Explicit alias for legacy ×1000 smoothstep output. smoothstep remains available for compatibility.
fn smoothstep_t1000(lo: int, hi: int, x: int) -> intsmootherstep_t1000 v3.1.0
Explicit alias for legacy ×1000 smootherstep output. smootherstep remains available for compatibility.
fn smootherstep_t1000(lo: int, hi: int, x: int) -> int