std/math
Basic numeric operations and constants.
Functions
sqrt :: fn(x: f64) -> f64 Square root.
Parameters
| x | f64 | non-negative finite input. |
Returns
f64 sqrt(x). NaN when x < 0.pow :: fn(x: f64, n: f64) -> f64 Power: x^n. Both base and exponent are floats ; for integer exponents
the caller is expected to cast.
Parameters
| x | f64 | base. |
| n | f64 | exponent. |
Returns
f64 x raised to the n-th power.floor :: fn(x: f64) -> f64 Largest integer n such that n <= x. floor(-1.2) → -2.0.
Parameters
| x | f64 | No description. |
Returns
f64 ceil :: fn(x: f64) -> f64 Smallest integer n such that n >= x. ceil(-1.2) → -1.0.
Parameters
| x | f64 | No description. |
Returns
f64 round :: fn(x: f64) -> f64 Round to the nearest integer, ties away from zero. round(0.5) → 1.0.
Parameters
| x | f64 | No description. |
Returns
f64 sin :: fn(x: f64) -> f64 Sine of x in radians.
Parameters
| x | f64 | No description. |
Returns
f64 cos :: fn(x: f64) -> f64 Cosine of x in radians.
Parameters
| x | f64 | No description. |
Returns
f64 tan :: fn(x: f64) -> f64 Tangent of x in radians.
Parameters
| x | f64 | No description. |
Returns
f64 min :: fn(a: f64, b: f64) -> f64 Smaller of two f64s. min(NaN, x) == NaN (NaN propagates).
Parameters
| a | f64 | No description. |
| b | f64 | No description. |
Returns
f64 min :: fn(a: f32, b: f32) -> f32 Smaller of two f32s. min(NaN, x) == NaN (NaN propagates).
Parameters
| a | f32 | No description. |
| b | f32 | No description. |
Returns
f32 min :: fn(a: i32, b: i32) -> i32 Smaller of two i32s.
Parameters
| a | i32 | No description. |
| b | i32 | No description. |
Returns
i32 min :: fn(a: i64, b: i64) -> i64 Smaller of two i64s.
Parameters
| a | i64 | No description. |
| b | i64 | No description. |
Returns
i64 max :: fn(a: f64, b: f64) -> f64 Larger of two f64s. max(NaN, x) == NaN.
Parameters
| a | f64 | No description. |
| b | f64 | No description. |
Returns
f64 max :: fn(a: f32, b: f32) -> f32 Larger of two f32s. max(NaN, x) == NaN.
Parameters
| a | f32 | No description. |
| b | f32 | No description. |
Returns
f32 max :: fn(a: i32, b: i32) -> i32 Larger of two i32s.
Parameters
| a | i32 | No description. |
| b | i32 | No description. |
Returns
i32 max :: fn(a: i64, b: i64) -> i64 Larger of two i64s.
Parameters
| a | i64 | No description. |
| b | i64 | No description. |
Returns
i64 abs :: fn(x: f64) -> f64 Absolute value of an f64. Preserves the sign of zero (abs(-0.0) →
-0.0): caller normalises if needed.
Parameters
| x | f64 | No description. |
Returns
f64 abs :: fn(x: i32) -> i32 Absolute value of an i32. abs(i32::MIN) overflows (panics in debug,
wraps in release).
Parameters
| x | i32 | No description. |
Returns
i32 abs :: fn(x: i64) -> i64 Absolute value of an i64. Same overflow caveat at i64::MIN.
Parameters
| x | i64 | No description. |
Returns
i64 clamp :: fn(x: f64, lo: f64, hi: f64) -> f64 Clamp x to [lo, hi]. Equivalent to min(max(x, lo), hi). Behaviour
when lo > hi matches the underlying calls: lo wins.
Parameters
| x | f64 | No description. |
| lo | f64 | No description. |
| hi | f64 | No description. |
Returns
f64 clamp :: fn(x: f32, lo: f32, hi: f32) -> f32 Clamp an f32 to [lo, hi].
Parameters
| x | f32 | No description. |
| lo | f32 | No description. |
| hi | f32 | No description. |
Returns
f32 clamp :: fn(x: i32, lo: i32, hi: i32) -> i32 Clamp an i32 to [lo, hi].
Parameters
| x | i32 | No description. |
| lo | i32 | No description. |
| hi | i32 | No description. |
Returns
i32 clamp :: fn(x: i64, lo: i64, hi: i64) -> i64 Clamp an i64 to [lo, hi].
Parameters
| x | i64 | No description. |
| lo | i64 | No description. |
| hi | i64 | No description. |
Returns
i64 lerp :: fn(a: f64, b: f64, t: f64) -> f64 Linear interpolation between a (t = 0) and b (t = 1). t is
clamped to [0, 1] so callers don't accidentally extrapolate.
Parameters
| a | f64 | the value at t = 0. |
| b | f64 | the value at t = 1. |
| t | f64 | blend factor, clamped to [0, 1]. |
Returns
f64 a + (b - a) * clamp(t, 0, 1).Constants
pi: f64 :: 3.141592653589793 π (3.141592653589793).
e: f64 :: 2.718281828459045 Euler's number, e (2.718281828459045).