All files / math floor-to-step.ts

100% Statements 1/1
100% Branches 1/1
100% Functions 1/1
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                          7x    
import { snapToStep } from './internal';
 
/**
 * Rounds a number down to a multiple of a step, without float noise.
 *
 * @param value - The number to round down.
 * @param step - The step, a positive number. Defaults to `1`.
 * @returns The largest multiple of `step` lower than or equal to `value`.
 * @example
 * floorToStep(0.39, 0.1); // 0.3
 * floorToStep(-7, 5); // -10
 */
export function floorToStep(value: number, step = 1): number {
  return snapToStep(value, step, Math.floor);
}