Skip to content

Commit 7bd97b7

Browse files
Migrate functions from Math; drop Math as dependency (#51)
1 parent b234c41 commit 7bd97b7

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ Notable changes to this project are documented in this file. The format is based
66

77
Breaking changes:
88
- Migrate FFI to ES modules (#50 by @kl0tl and @JordanMartinez)
9+
- Migrate `trunc` from `math` package (#51 by @JordanMartinez)
910

1011
New features:
1112

1213
Bugfixes:
1314

1415
Other improvements:
16+
- Drop dependency on deprecated `math` package (#51 by @JordanMartinez)
1517

1618
## [v5.0.0](https://github.com/purescript/purescript-integers/releases/tag/v5.0.0) - 2021-02-26
1719

bower.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-math": "master",
2019
"purescript-maybe": "master",
2120
"purescript-numbers": "master",
2221
"purescript-prelude": "master"

src/Data/Int.purs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Data.Int
22
( fromNumber
33
, ceil
44
, floor
5+
, trunc
56
, round
67
, toNumber
78
, fromString
@@ -28,8 +29,7 @@ import Prelude
2829
import Data.Int.Bits ((.&.))
2930
import Data.Maybe (Maybe(..), fromMaybe)
3031
import Data.Number (isFinite)
31-
32-
import Math as Math
32+
import Data.Number as Number
3333

3434
-- | Creates an `Int` from a `Number` value. The number must already be an
3535
-- | integer and fall within the valid range of values for the `Int` type
@@ -47,19 +47,25 @@ foreign import fromNumberImpl
4747
-- | less than the argument. Values outside the `Int` range are clamped, `NaN`
4848
-- | and `Infinity` values return 0.
4949
floor :: Number -> Int
50-
floor = unsafeClamp <<< Math.floor
50+
floor = unsafeClamp <<< Number.floor
5151

5252
-- | Convert a `Number` to an `Int`, by taking the closest integer equal to or
5353
-- | greater than the argument. Values outside the `Int` range are clamped,
5454
-- | `NaN` and `Infinity` values return 0.
5555
ceil :: Number -> Int
56-
ceil = unsafeClamp <<< Math.ceil
56+
ceil = unsafeClamp <<< Number.ceil
57+
58+
-- | Convert a `Number` to an `Int`, by dropping the decimal.
59+
-- | Values outside the `Int` range are clamped, `NaN` and `Infinity`
60+
-- | values return 0.
61+
trunc :: Number -> Int
62+
trunc = unsafeClamp <<< Number.trunc
5763

5864
-- | Convert a `Number` to an `Int`, by taking the nearest integer to the
5965
-- | argument. Values outside the `Int` range are clamped, `NaN` and `Infinity`
6066
-- | values return 0.
6167
round :: Number -> Int
62-
round = unsafeClamp <<< Math.round
68+
round = unsafeClamp <<< Number.round
6369

6470
-- | Convert an integral `Number` to an `Int`, by clamping to the `Int` range.
6571
-- | This function will return 0 if the input is `NaN` or an `Infinity`.

test/Test/Data/Int.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ testInt = do
155155
let
156156
q = quot a b
157157
r = rem a b
158-
msg = show a <> " / " <> show b <> ": "
159158
in do
160159
assert $ q * b + r == a
161160
-- Check when dividend goes into divisor exactly

0 commit comments

Comments
 (0)