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

Commit 7ebeae0

Browse files
committed
Merge pull request #12 from rgrempel/master
Add `trunc`, with a polyfill for browsers that don't support it.
2 parents 31e132a + 08207af commit 7ebeae0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Math.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ exports.exp = Math.exp;
2424

2525
exports.floor = Math.floor;
2626

27+
exports.trunc = Math.trunc || function (n) {
28+
return n < 0 ? Math.ceil(n) : Math.floor(n);
29+
};
30+
2731
exports.log = Math.log;
2832

2933
exports.max = function (n1) {

src/Math.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ foreign import sqrt :: Number -> Number
6060
-- | Returns the tangent of the argument.
6161
foreign import tan :: Radians -> Number
6262

63+
-- | Truncates the decimal portion of a number. Equivalent to `floor` if the
64+
-- | number is positive, and `ceil` if the number is negative.
65+
foreign import trunc :: Number -> Number
66+
6367
infixl 7 %
6468

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

0 commit comments

Comments
 (0)