@ende/math
ende add jsr:@ende/mathVersion 2026.10.15 on JSR.
Math functions such as modulo and clamp.
import { clamp, modulo } from "@ende/math";
import { assertEquals } from "@ende/assert";
for (let n = -3; n <= 3; ++n) {
const val = n * 12 + 5;
// 5 o'clock is always 5 o'clock, no matter how many twelve-hour cycles you add or remove
assertEquals(modulo(val, 12), 5);
assertEquals(clamp(val, 0, 11), n === 0 ? 5 : n > 0 ? 11 : 0);
}
Modules
Exports
clamp— Clamp a number within the inclusive [min, max] range.modulo— Computes the floored modulo of a number.RoundingOptions— Options for roundTo.roundTo— Round a number to a specified number of digits.