std.math Module Reference

The std.math module provides mathematical functions, trigonometry, and scientific constants.

math_example.sp
1import std.io;
2import std.math;
3
4fn 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);
8
9 println("sqrt(144) = ${root}");
10 println("2^10 = ${power}");
11 println("sin(PI/2) = ${angle}");
12}

Exported Functions & Constants

math.PI

Native Builtin
const double math.PI = 3.14159265358979323846

The mathematical constant pi.

math.sqrt

Native Builtin
fn math.sqrt(double x) -> double

Returns the positive square root of a non-negative floating-point number.

Parameters
x(double)
Input value.
Returns:double

math.pow

Native Builtin
fn math.pow(double base, double exp) -> double

Returns base raised to the power of exp.

Parameters
base(double)
Base number.
exp(double)
Exponent.
Returns:double

math.abs

Native Builtin
fn math.abs(double x) -> double

Returns the absolute magnitude of x.

Parameters
x(double)
Target number.
Returns:double

math.min / math.max

Native Builtin
fn 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