std.math Module Reference
The std.math module provides mathematical functions, trigonometry, and scientific constants.
math_example.sp
1import std.io;2import std.math;34fn main() -> void {5 let root = math.sqrt(144.0);6 let power = math.pow(2.0, 10.0);7 let angle = math.sin(math.PI / 2.0);89 println("sqrt(144) = ${root}");10 println("2^10 = ${power}");11 println("sin(PI/2) = ${angle}");12}
Exported Functions & Constants
math.PI
Native Builtinconst double math.PI = 3.14159265358979323846
The mathematical constant pi.
math.sqrt
Native Builtinfn math.sqrt(double x) -> double
Returns the positive square root of a non-negative floating-point number.
Parameters
x(double)
Input value.Returns:
doublemath.pow
Native Builtinfn math.pow(double base, double exp) -> double
Returns base raised to the power of exp.
Parameters
base(double)
Base number.exp(double)
Exponent.Returns:
doublemath.abs
Native Builtinfn math.abs(double x) -> double
Returns the absolute magnitude of x.
Parameters
x(double)
Target number.Returns:
doublemath.min / math.max
Native Builtinfn math.min(double a, double b) -> double fn math.max(double a, double b) -> double
Returns the smaller or larger of two numbers.
Returns:
double