git.iko.soy/rowtype-yoga/purescript-fixed-precision
on main help sign in
Add `fromBigInt` (#21)
cc2674eArthur Xavier
bower.json+1−1
@@ -20,6 +20,6 @@
20 },
20 },
21 "devDependencies": {
21 "devDependencies": {
22 "purescript-psci-support": "^4.0.0",
22 "purescript-psci-support": "^4.0.0",
23− "purescript-quickcheck": "^5.0.0"
23+ "purescript-quickcheck": "^6.1.0"
24 }
24 }
25}
25}
src/Data/Fixed.purs+11−1
@@ -5,6 +5,7 @@
5module Data.Fixed
5module Data.Fixed
6 ( Fixed
6 ( Fixed
7 , fromInt
7 , fromInt
8+ , fromBigInt
8 , fromNumber
9 , fromNumber
9 , toNumber
10 , toNumber
10 , fromString
11 , fromString
@@ -36,6 +37,7 @@ import Prelude
36
37
37import Control.MonadZero (guard)
38import Control.MonadZero (guard)
38import Data.Array (replicate)
39import Data.Array (replicate)
40+import Data.BigInt (BigInt)
39import Data.BigInt as BigInt
41import Data.BigInt as BigInt
40import Data.Int as Int
42import Data.Int as Int
41import Data.Maybe (Maybe(..))
43import Data.Maybe (Maybe(..))
@@ -169,7 +171,15 @@ fromInt
169 . KnownPrecision precision
171 . KnownPrecision precision
170 => Int
172 => Int
171 -> Fixed precision
173 -> Fixed precision
174+fromInt = fromBigInt <<< BigInt.fromInt
175+
176+-- | Create a `Fixed` representation of a `BigInt`.
177+fromBigInt
178+ :: forall precision
179+ . KnownPrecision precision
180+ => BigInt
181+ -> Fixed precision
172−fromInt i = Fixed (BigInt.fromInt i * reflectPrecision (PProxy :: PProxy precision))
182+fromBigInt i = Fixed (i * reflectPrecision (PProxy :: PProxy precision))
173
183
174-- | Approximate a `Number` as a `Fixed` value with the specified precision.
184-- | Approximate a `Number` as a `Fixed` value with the specified precision.
175-- |
185-- |