Skip to content

Migrate functions from Math; drop Math as dependency #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ Notable changes to this project are documented in this file. The format is based

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

New features:

Bugfixes:

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

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

Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"package.json"
],
"dependencies": {
"purescript-math": "master",
"purescript-maybe": "master",
"purescript-numbers": "master",
"purescript-prelude": "master"
Expand Down
16 changes: 11 additions & 5 deletions src/Data/Int.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Data.Int
( fromNumber
, ceil
, floor
, trunc
, round
, toNumber
, fromString
Expand All @@ -28,8 +29,7 @@ import Prelude
import Data.Int.Bits ((.&.))
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Number (isFinite)

import Math as Math
import Data.Number as Number

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

-- | Convert a `Number` to an `Int`, by taking the closest integer equal to or
-- | greater than the argument. Values outside the `Int` range are clamped,
-- | `NaN` and `Infinity` values return 0.
ceil :: Number -> Int
ceil = unsafeClamp <<< Math.ceil
ceil = unsafeClamp <<< Number.ceil

-- | Convert a `Number` to an `Int`, by dropping the decimal.
-- | Values outside the `Int` range are clamped, `NaN` and `Infinity`
-- | values return 0.
trunc :: Number -> Int
trunc = unsafeClamp <<< Number.trunc

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

-- | Convert an integral `Number` to an `Int`, by clamping to the `Int` range.
-- | This function will return 0 if the input is `NaN` or an `Infinity`.
Expand Down
1 change: 0 additions & 1 deletion test/Test/Data/Int.purs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ testInt = do
let
q = quot a b
r = rem a b
msg = show a <> " / " <> show b <> ": "
in do
assert $ q * b + r == a
-- Check when dividend goes into divisor exactly
Expand Down