Math Functions

Table of Contents


math::abs!()

The math::abs function returns the absolute value of a number.

Function signature: math::abs(number) -> number

Example:

#![allow(unused)]
fn main() {
math::abs!(45.23);
}

math::ceil!()

The math::ceil function rounds a number up to the next largest integer.

Function signature: math::ceil(number) -> number

Example:

#![allow(unused)]
fn main() {
math::ceil!(45.23);
}

math::floor!()

The math::floor function rounds a number down to the next largest integer.

Function signature: math::floor(number) -> number

Example:

#![allow(unused)]
fn main() {
math::floor!(45.23);
}

math::round!()

The math::round function rounds a number up or down to the nearest integer.

Function signature: math::round(number) -> number

Example:

#![allow(unused)]
fn main() {
math::round!(45.23);
}

math::sqrt!()

The math::sqrt function returns the square root of a number.

Function signature: math::sqrt(number) -> number

Example:

#![allow(unused)]
fn main() {
math::sqrt!(45.23);
}

math::mean!()

The math::mean function returns the average of a set of numbers.

Function signature: math::mean(array) -> number

Example:

#![allow(unused)]
fn main() {
math::mean!(vec![1, 2, 3, 4, 5]);
}

math::median!()

The math::median function returns the median of a set of numbers.

Function signature: math::median(array) -> number

Example:

#![allow(unused)]
fn main() {
math::median!(vec![1, 2, 3, 4, 5]);
}

math::mode!()

The math::mode function returns the mode of a set of numbers.

Function signature: math::mode(array) -> number

Example:

#![allow(unused)]
fn main() {
math::mode!(vec![1, 2, 3, 4, 5]);
}

math::min!()

The math::min function returns the minimum number in a set of numbers.

Function signature: math::min(array) -> number

Example:

#![allow(unused)]
fn main() {
math::min!(vec![1, 2, 3, 4, 5]);
}

math::product!()

The math::product function returns the product of a set of numbers.

Function signature: math::product(array) -> number

Example:

#![allow(unused)]
fn main() {
math::product!(vec![1, 2, 3, 4, 5]);
}

math::sum!()

The math::sum function returns the total sum of a set of numbers.

Function signature: math::sum(array) -> number

Example:

#![allow(unused)]
fn main() {
math::sum!(vec![1, 2, 3, 4, 5]);
}

That concludes the documentation for the math macros.