Standard Library
std.math
Extended math: powers, logarithms, trigonometry, and float utilities.
Exported functions
Return pi.
Return Euler's number e.
Raise base to the given power.
Examples
use math from "std.math"
@println(math.pow(2.0, 10.0)) # 1024Return e raised to the given power.
Return the natural logarithm.
Return the base-2 logarithm.
Examples
use math from "std.math"
@println(math.log2(1024.0)) # 10Return the base-10 logarithm.
Return the sine of an angle in radians.
Examples
use math from "std.math"
const radians = 90.0 * math.pi() / 180.0
@println(math.sin(radians)) # 1Return the cosine of an angle in radians.
Return the tangent of an angle in radians.
Return the arcsine in radians.
Return the arccosine in radians.
Return the arctangent in radians.
Return the four-quadrant arctangent of y/x in radians.
Return sqrt(x^2 + y^2) without intermediate overflow.
Examples
use math from "std.math"
@println(math.hypot(3.0, 4.0)) # 5Truncate toward zero, returning an Int.
Return -1, 0, or 1 according to the sign of the value.
Clamp a value into the inclusive range [low, high].
Examples
use math from "std.math"
@println(math.clamp(1.5, 0.0, 1.0)) # 1Round down to the nearest integer (same as the @floor builtin).
Round up to the nearest integer (same as the @ceil builtin).
Round to the nearest integer (same as the @round builtin).
Examples
use math from "std.math"
@println(math.round(3.6)) # 4
@println(math.trunc(3.6)) # 3Return the absolute value (same as the @abs builtin).
Return the square root (same as the @sqrt builtin).
Return the smaller of two values (same as the @min builtin).
Return the larger of two values (same as the @max builtin).