Skip to content

number

Numeric helpers that the standard library does not provide.

Floating-point helpers never panic: an input with no meaningful answer (an empty slice, a zero total, a NaN) gives None, and NaN or infinite values propagate as usual for f64.

Cargo feature number (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features number

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["number"] }

Import path: helpers4::number.

ItemWhat it does
gcdGreatest common divisor of a and b; gcd(0, 0) is 0.
lcmLeast common multiple of a and b, or None when it does not fit in a u64.
lerpLinear interpolation between from and to: from at t = 0, to at t = 1.
meanArithmetic mean of values, or None when it is empty.
medianMedian of values, or None when it is empty or contains a NaN.
percentageWhat percent part is of total, or None when total is zero.
round_toRounds value to decimals decimal places, half away from zero.