git.iko.soy/rowtype-yoga/purescript-fixed-precision
on main help sign in
Add `fromBigInt` (#21)

commitcc2674e242de833c2463e2f5a25e2778c8207cd4 authorArthur Xavier <arthur.xavierx@gmail.com> dateMon 13 Jan 2020, 12:33 (7 years ago) parent6190539
2 files changed+12−2
bower.json+1−1 src/Data/Fixed.purs+11−1
bower.json+1−1
@@ -20,6 +20,6 @@
2020 },
2121 "devDependencies": {
2222 "purescript-psci-support": "^4.0.0",
23− "purescript-quickcheck": "^5.0.0"
23+ "purescript-quickcheck": "^6.1.0"
2424 }
2525}
src/Data/Fixed.purs+11−1
@@ -5,6 +5,7 @@
55module Data.Fixed
66 ( Fixed
77 , fromInt
8+ , fromBigInt
89 , fromNumber
910 , toNumber
1011 , fromString
@@ -36,6 +37,7 @@ import Prelude
3637
3738import Control.MonadZero (guard)
3839import Data.Array (replicate)
40+import Data.BigInt (BigInt)
3941import Data.BigInt as BigInt
4042import Data.Int as Int
4143import Data.Maybe (Maybe(..))
@@ -169,7 +171,15 @@ fromInt
169171 . KnownPrecision precision
170172 => Int
171173 -> Fixed precision
172−fromInt i = Fixed (BigInt.fromInt i * reflectPrecision (PProxy :: PProxy 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
182+fromBigInt i = Fixed (i * reflectPrecision (PProxy :: PProxy precision))
173183
174184-- | Approximate a `Number` as a `Fixed` value with the specified precision.
175185-- |