Skip to content

Commit

Permalink
feat(math): add floorTo/ceilTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 8, 2021
1 parent aefdd97 commit 595fe83
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/math/src/prec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const trunc: FnN = (x) => (x < 0 ? Math.ceil(x) : Math.floor(x));

export const roundTo = (x: number, prec = 1) => Math.round(x / prec) * prec;

export const floorTo = (x: number, prec = 1) => Math.floor(x / prec) * prec;

export const ceilTo = (x: number, prec = 1) => Math.ceil(x / prec) * prec;

/**
* Only rounds `x` to nearest int if `fract(x)` <= `eps` or >= `1-eps`.
*
Expand Down

0 comments on commit 595fe83

Please sign in to comment.