diff options
author | Gregor Kleen <aethoago@141.li> | 2017-02-16 19:42:50 +0100 |
---|---|---|
committer | Gregor Kleen <aethoago@141.li> | 2017-02-16 19:42:50 +0100 |
commit | dccf2c949c10892b368484c3e85bb2bb14e613e2 (patch) | |
tree | bf730c4a5ac7e083cef04ca009da71f7e6a159ea /lib | |
parent | f70dd6176af54b81f167d3963a8bf8f089f0fb8a (diff) | |
download | postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar.gz postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar.bz2 postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar.xz postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.zip |
Bruteforce digit calculation
Diffstat (limited to 'lib')
-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 |