Skip to main content
On this page

@std/math

Overview Jump to heading

Math functions such as modulo and clamp.

import { clamp, modulo } from "@std/math";
import { assertEquals } from "@std/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);
}

Add to your project Jump to heading

deno add jsr:@std/math

See all symbols in @std/math on

Did you find what you needed?

Privacy policy