stack/packages/stack-shared/src/utils/math.tsx
2024-02-28 14:35:30 +01:00

7 lines
213 B
TypeScript

/**
* Similar to the modulo operator, but always returns a positive number (even when the input is negative).
*/
export function remainder(n: number, d: number): number {
return ((n % d) + Math.abs(d)) % d;
}