Standard library
Math
Integer and floating-point math helpers.
Introduction
Integer and floating-point math helpers. Import std/math to bind the module as math. Call free functions as math.name(...). Struct methods use a receiver value.
/ std/math
This page is the package reference for std/math. Private helpers used only by co-located tests are not listed.
Functions
Free functions on math. Each function has a short description, an example, then parameters and return shape.
abs_i
Absolute value of an integer. Call form: math.abs_i(n).
/ std/math
$ n = math.abs_i(-3)
Parameters: n: integer. Returns: Non-negative integer.
min
Returns the smaller of two integers. Call form: math.min(a, b).
/ std/math
$ result = math.min("a", "b")Parameters: a, b: integers. Returns: Integer.
max
Returns the larger of two integers. Call form: math.max(a, b).
/ std/math
$ result = math.max("a", "b")Parameters: a, b: integers. Returns: Integer.
sqrt
Non-negative square root of float x. Call form: math.sqrt(x).
/ std/math
$ y = math.sqrt(<f64>9.0)
Parameters: x: float. Returns: Float square root.
sin
Sine of angle x measured in radians. Call form: math.sin(x).
/ std/math
$ y = math.sin(<f64>0.0)
Parameters: x: float radians. Returns: Float sine.
cos
Cosine of x radians. Call form: math.cos(x).
/ std/math
$ y = math.cos(<f64>0.0)
Parameters: x: float radians. Returns: Float cosine.
tan
Tangent of x radians. Call form: math.tan(x).
/ std/math
$ y = math.tan(<f64>0.0)
Parameters: x: float radians. Returns: Float tangent.
floor
Greatest integer value not greater than x, as float. Call form: math.floor(x).
/ std/math
$ y = math.floor(<f64>3.7)
Parameters: x: float. Returns: Floored float.
ceil
Ceiling of x as float: the least integer value greater than or equal to x. Call form: math.ceil(x).
/ std/math
$ y = math.ceil(<f64>3.2)
Parameters: x: float. Returns: Ceiling float.
abs_f
Floating-point absolute value. Call form: math.abs_f(x).
/ std/math
$ result = math.abs_f(3)
Parameters: x: float. Returns: Integer.
pow
Raises a to the power b. Call form: math.pow(a, b).
/ std/math
$ y = math.pow(<f64>2.0, <f64>3.0)
Parameters: a: base float. b: exponent float. Returns: Float power.