diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ddf194..3cea7e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bower.json b/bower.json index 154ef73..7cea11a 100644 --- a/bower.json +++ b/bower.json @@ -16,7 +16,6 @@ "package.json" ], "dependencies": { - "purescript-math": "master", "purescript-maybe": "master", "purescript-numbers": "master", "purescript-prelude": "master" diff --git a/src/Data/Int.purs b/src/Data/Int.purs index 28952ed..c637fc8 100644 --- a/src/Data/Int.purs +++ b/src/Data/Int.purs @@ -2,6 +2,7 @@ module Data.Int ( fromNumber , ceil , floor + , trunc , round , toNumber , fromString @@ -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 @@ -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`. diff --git a/test/Test/Data/Int.purs b/test/Test/Data/Int.purs index ae3df7a..1eabc6b 100644 --- a/test/Test/Data/Int.purs +++ b/test/Test/Data/Int.purs @@ -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