@@ -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
2829import Data.Int.Bits ((.&.))
2930import Data.Maybe (Maybe (..), fromMaybe )
3031import 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.
4949floor :: 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.
5555ceil :: 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.
6167round :: 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`.
0 commit comments