Module std::math

Mathematical operations.

Generic numeric functions (absolute value, min, max), integer helpers (clamp, sign), floating-point functions (sqrt, pow, floor, ceil, round), and transcendentals (exp, log, sin, cos) plus common constants.

Generic numeric and floating-point functions are lowered to LLVM math ops by the codegen backend. Integer-only helpers and constants are implemented directly in Hew. The Rust crate in src/lib.rs remains only as a workspace build placeholder.

Examples

import std::math;

fn main() {
    println(math.abs(-5));         // 5
    println(math.clamp(10, 0, 5)); // 5
    println(math.sqrt(4.0));       // 2
    println(math.pi());            // 3.14159
}

Contents

Functions

Function pi

pub fn pi() -> f64

The ratio of a circle's circumference to its diameter.

Function e

pub fn e() -> f64

Euler's number, the base of natural logarithms.

Function abs

pub fn abs(x: T) -> T

Return the absolute value of a numeric value.

Function min

pub fn min(a: T, b: T) -> T

Return the smaller of two numeric values.

Function max

pub fn max(a: T, b: T) -> T

Return the larger of two numeric values.

Function clamp

pub fn clamp(x: i64, lo: i64, hi: i64) -> i64

Clamp x to the range [lo, hi].

Function sign

pub fn sign(x: i64) -> i64

Return the sign of an integer: -1, 0, or 1.

Function sqrt

pub fn sqrt(x: f64) -> f64

Return the square root of a float.

Function pow

pub fn pow(base: f64, exp: f64) -> f64

Raise base to the power exp.

Function floor

pub fn floor(x: f64) -> f64

Return the largest integer value less than or equal to x.

Function ceil

pub fn ceil(x: f64) -> f64

Return the smallest integer value greater than or equal to x.

Function round

pub fn round(x: f64) -> f64

Round to the nearest integer, with ties rounding away from zero.

Function exp

pub fn exp(x: f64) -> f64

Return e raised to the power x.

Function log

pub fn log(x: f64) -> f64

Return the natural logarithm of x.

Function sin

pub fn sin(x: f64) -> f64

Return the sine of x (radians).

Function cos

pub fn cos(x: f64) -> f64

Return the cosine of x (radians).