docs / Getting Started / system.math

system.math

The math module ships a single set of numeric primitives that works on both CPU and GPU kernels. Functions are imported as free names — no receiver object, no method-call syntax.

use system.io
use system.math as M
use system.math.{sqrt, pow, abs, min, max, sin, cos, floor, ceil, round}

fn main()
    // Numeric primitives — single set, GPU-compatible.
    println(f"{sqrt(2.0)}")
    println(f"{pow(2.0, 10.0)}")
    println(f"{abs(-3.0)}")
    println(f"{min(5.0, 9.0)} {max(5.0, 9.0)}")

    // Trigonometry.
    println(f"{sin(0.0)} {cos(0.0)}")

    // Rounding.
    println(f"{floor(3.7)} {ceil(3.2)} {round(3.5)}")

    // Constants — accessed through the aliased module.
    println(f"{M.PI} {M.E}")

The current surface covers abs, min, max, pow, sqrt, floor, ceil, round, sin, cos, tan, log, exp, plus the constants PI, E, and INF. CPU calls lower to libm / Cranelift intrinsics. GPU calls lower to the target backend's built-in equivalents (tanh, atan2, step, clamp, and mix are available in kernels too) — same source, same answer.