diff options
Diffstat (limited to 'lib/Postdelay/TimeSpec')
-rw-r--r-- | lib/Postdelay/TimeSpec/Utils.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Postdelay/TimeSpec/Utils.hs b/lib/Postdelay/TimeSpec/Utils.hs index a8c7d4a..fd9c1be 100644 --- a/lib/Postdelay/TimeSpec/Utils.hs +++ b/lib/Postdelay/TimeSpec/Utils.hs | |||
@@ -22,6 +22,8 @@ import Data.Time.Lens | |||
22 | import Data.Time.Zones | 22 | import Data.Time.Zones |
23 | 23 | ||
24 | import Data.Bool | 24 | import Data.Bool |
25 | import Data.Maybe | ||
26 | import Data.List | ||
25 | import Data.Foldable | 27 | import Data.Foldable |
26 | import Data.Functor | 28 | import Data.Functor |
27 | import Data.Function | 29 | import Data.Function |
@@ -53,7 +55,7 @@ sign = label "sign" $ choice [ char '+' $> id | |||
53 | , char '-' $> negateV | 55 | , char '-' $> negateV |
54 | ] | 56 | ] |
55 | 57 | ||
56 | boundedNatural :: forall s n m. (Show n, Real n, StringParser s m) | 58 | boundedNatural :: forall s n m. (Show n, Ord n, Num n, StringParser s m) |
57 | => Bool -- ^ Require number to be padded with zeroes? | 59 | => Bool -- ^ Require number to be padded with zeroes? |
58 | -> Interval n -> m n | 60 | -> Interval n -> m n |
59 | boundedNatural padded (I.intersection (0 <=..< PosInf) -> bounds) = do | 61 | boundedNatural padded (I.intersection (0 <=..< PosInf) -> bounds) = do |
@@ -84,7 +86,7 @@ boundedNatural padded (I.intersection (0 <=..< PosInf) -> bounds) = do | |||
84 | | otherwise = int | 86 | | otherwise = int |
85 | 87 | ||
86 | digits :: n -> Int | 88 | digits :: n -> Int |
87 | digits = succ . floor . (logBase 10 :: Double -> Double) . realToFrac . abs | 89 | digits n = succ . fromJust $ findIndex (\(min, max) -> min <= n && n < max) [ (10^i, 10^(succ i)) | i <- ([0..] :: [Int]) ] |
88 | 90 | ||
89 | boundedRational :: forall s m n. (Show n, RealFrac n, StringParser s m) | 91 | boundedRational :: forall s m n. (Show n, RealFrac n, StringParser s m) |
90 | => Bool -- ^ Require number to be padded with zeroes | 92 | => Bool -- ^ Require number to be padded with zeroes |