Skip to content
This repository has been archived by the owner on Jun 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #12 from rgrempel/master
Browse files Browse the repository at this point in the history
Add `trunc`, with a polyfill for browsers that don't support it.
  • Loading branch information
garyb committed Apr 13, 2016
2 parents 31e132a + 08207af commit 7ebeae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ exports.exp = Math.exp;

exports.floor = Math.floor;

exports.trunc = Math.trunc || function (n) {
return n < 0 ? Math.ceil(n) : Math.floor(n);
};

exports.log = Math.log;

exports.max = function (n1) {
Expand Down
4 changes: 4 additions & 0 deletions src/Math.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ foreign import sqrt :: Number -> Number
-- | Returns the tangent of the argument.
foreign import tan :: Radians -> Number

-- | Truncates the decimal portion of a number. Equivalent to `floor` if the
-- | number is positive, and `ceil` if the number is negative.
foreign import trunc :: Number -> Number

infixl 7 %

-- | Computes the remainder after division, wrapping Javascript's `%` operator.
Expand Down

0 comments on commit 7ebeae0

Please sign in to comment.