Skip to content

std/math ​

Mathematical functions and constants.

milo
from "std/math" import { Math }

API reference ​

Math ​

milo
pub struct Math

Math.abs ​

milo
fn Math.abs(x: f64): f64

Math.absI32 ​

milo
fn Math.absI32(x: i32): i32

Math.absI64 ​

milo
fn Math.absI64(x: i64): i64

Math.acos ​

milo
fn Math.acos(x: f64): f64

Clamped before the call. Round-off in a dot product routinely lands a cosine at 1.0000000000000002, and libm's acos returns NaN there rather than 0 — a NaN that then propagates silently through an angle calculation.

Math.asin ​

milo
fn Math.asin(x: f64): f64

Math.atan ​

milo
fn Math.atan(x: f64): f64

Math.atan2 ​

milo
fn Math.atan2(y: f64, x: f64): f64

Math.ceil ​

milo
fn Math.ceil(x: f64): f64

Math.clampF64 ​

milo
fn Math.clampF64(x: f64, lo: f64, hi: f64): f64

Math.clampI64 ​

milo
fn Math.clampI64(x: i64, lo: i64, hi: i64): i64

Math.cos ​

milo
fn Math.cos(x: f64): f64

Math.e ​

milo
fn Math.e(): f64

Math.exp ​

milo
fn Math.exp(x: f64): f64

Math.floor ​

milo
fn Math.floor(x: f64): f64

Math.inf ​

milo
fn Math.inf(): f64

Math.isFinite ​

milo
fn Math.isFinite(x: f64): bool

Math.isInf ​

milo
fn Math.isInf(x: f64): bool

Math.isNan ​

milo
fn Math.isNan(x: f64): bool

NaN is the only value not equal to itself, so this is the one reliable test — x == f64.NAN is always false (the compiler lints that mistake).

Math.log ​

milo
fn Math.log(x: f64): f64

Math.log10 ​

milo
fn Math.log10(x: f64): f64

Math.log2 ​

milo
fn Math.log2(x: f64): f64

Math.max ​

milo
fn Math.max<T>(a: T, b: T): T

The larger of two values of any one type with >. See Math.min.

Math.maxF64 ​

milo
fn Math.maxF64(a: f64, b: f64): f64

Math.maxI32 ​

milo
fn Math.maxI32(a: i32, b: i32): i32

Math.maxI64 ​

milo
fn Math.maxI64(a: i64, b: i64): i64

Math.min ​

milo
fn Math.min<T>(a: T, b: T): T

The smaller of two values of any one type with <: Math.min(x, 1.0) on f64, Math.min(n, 10) on an int of any width. A literal takes the other argument's type. NaN is not ordered, so a NaN a yields b (as minF64 does).

Math.minF64 ​

milo
fn Math.minF64(a: f64, b: f64): f64

Math.minI32 ​

milo
fn Math.minI32(a: i32, b: i32): i32

Math.minI64 ​

milo
fn Math.minI64(a: i64, b: i64): i64

Math.mod ​

milo
fn Math.mod(x: f64, y: f64): f64

Math.pi ​

milo
fn Math.pi(): f64

Math.pow ​

milo
fn Math.pow(base: f64, exponent: f64): f64

Math.round ​

milo
fn Math.round(x: f64): f64

Math.sin ​

milo
fn Math.sin(x: f64): f64

Math.sqrt ​

milo
fn Math.sqrt(x: f64): f64

Math.tan ​

milo
fn Math.tan(x: f64): f64