std::mathMathematical 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.
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
}
piThe ratio of a circle's circumference to its diameter.
eEuler's number, the base of natural logarithms.
absReturn the absolute value of a numeric value.
minReturn the smaller of two numeric values.
maxReturn the larger of two numeric values.
clampClamp x to the range [lo, hi].
signReturn the sign of an integer: -1, 0, or 1.
sqrtReturn the square root of a float.
powRaise base to the power exp.
floorReturn the largest integer value less than or equal to x.
ceilReturn the smallest integer value greater than or equal to x.
roundRound to the nearest integer, with ties rounding away from zero.
expReturn e raised to the power x.
logReturn the natural logarithm of x.
sinReturn the sine of x (radians).
cosReturn the cosine of x (radians).
tanReturn the tangent of x (radians).
asinReturn the arcsine of x, in radians, in the range [-pi/2, pi/2].
acosReturn the arccosine of x, in radians, in the range [0, pi].
atanReturn the arctangent of x, in radians, in the range [-pi/2, pi/2].
atan2Return the four-quadrant arctangent of y / x, in radians, using the
signs of both arguments to select the correct quadrant.
sinhReturn the hyperbolic sine of x.
coshReturn the hyperbolic cosine of x.
tanhReturn the hyperbolic tangent of x.
exp2Return 2 raised to the power x.
log2Return the base-2 logarithm of x.
log10Return the base-10 logarithm of x.
log1pReturn the natural logarithm of 1 + x, accurate for x near zero.
expm1Return e^x - 1, accurate for x near zero.
cbrtReturn the cube root of x.
hypotReturn sqrt(x*x + y*y), computed without spurious overflow or underflow.
fmaReturn a * b + c, computed as one correctly-rounded ternary operation
(fused multiply-add).
truncReturn x truncated toward zero to the nearest integer value.
copysignReturn a value with the magnitude of x and the sign of y.
powiReturn x raised to the integer power n.
n is i32: LLVM's powi intrinsic is parameterized on a fixed integer
width and does not generalize across widths the way pow's float
exponent does.
from_bitsReinterpret the bits of bits as an f64 (the inverse of x.to_bits()).
Spelled as a module function rather than the static call f64.from_bits:
the checker does not admit a bare builtin type name as a call receiver
today.