Skip to content

Commit

Permalink
feat(math): add safeDiv() (from @nkint PR #206)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 23, 2020
1 parent c821c63 commit 0567b93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/math/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export * from "./min-error";
export * from "./mix";
export * from "./prec";
export * from "./ratio";
export * from "./safe-div";
export * from "./solve";
export * from "./step";
7 changes: 7 additions & 0 deletions packages/math/src/safe-div.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Returns `a` divided by `b` or zero if `b = 0`.
*
* @param a
* @param b
*/
export const safeDiv = (a: number, b: number) => (b !== 0 ? a / b : 0);

0 comments on commit 0567b93

Please sign in to comment.