Skip to content

std.math

Width-suffixed f32 / f64 floating-point helpers.

std.math exposes a small set of floating-point helpers. Every function is width-suffixed: there is an _f32 and an _f64 form, because Zmeu does not implicitly promote between float widths. Pick the suffix that matches your value’s type.

import std.math as math
export def sqrt_f32(value: f32) -> f32
export def sqrt_f64(value: f64) -> f64
export def abs_f32(value: f32) -> f32
export def abs_f64(value: f64) -> f64
export def floor_f32(value: f32) -> f32
export def floor_f64(value: f64) -> f64
export def ceil_f32(value: f32) -> f32
export def ceil_f64(value: f64) -> f64
export def trunc_f32(value: f32) -> f32
export def trunc_f64(value: f64) -> f64
export def is_nan_f32(value: f32) -> bool
export def is_nan_f64(value: f64) -> bool
export def is_finite_f32(value: f32) -> bool
export def is_finite_f64(value: f64) -> bool

These map directly onto the native floating-point operations with default IEEE behaviour: there are no fast-math flags. sqrt of a negative produces nan; is_nan / is_finite classify the value without trapping.

import std.math as math
def magnitude(x: f64, y: f64) -> f64:
return math.sqrt_f64(x * x + y * y)
  • There is no implicit f32f64 conversion; cast explicitly with value as f64 when you need to cross widths.
  • Trigonometric, logarithmic, and exponential functions are not in this slice yet: they will be added with the same width-suffixed convention.