summaryrefslogtreecommitdiff
path: root/lib/Postdelay/TimeSpec/Utils.hs
diff options
context:
space:
mode:
authorGregor Kleen <aethoago@141.li>2017-02-16 19:42:50 +0100
committerGregor Kleen <aethoago@141.li>2017-02-16 19:42:50 +0100
commitdccf2c949c10892b368484c3e85bb2bb14e613e2 (patch)
treebf730c4a5ac7e083cef04ca009da71f7e6a159ea /lib/Postdelay/TimeSpec/Utils.hs
parentf70dd6176af54b81f167d3963a8bf8f089f0fb8a (diff)
downloadpostdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar
postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar.gz
postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar.bz2
postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.tar.xz
postdelay-dccf2c949c10892b368484c3e85bb2bb14e613e2.zip
Bruteforce digit calculation
Diffstat (limited to 'lib/Postdelay/TimeSpec/Utils.hs')
-rw-r--r--lib/Postdelay/TimeSpec/Utils.hs6
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
22import Data.Time.Zones 22import Data.Time.Zones
23 23
24import Data.Bool 24import Data.Bool
25import Data.Maybe
26import Data.List
25import Data.Foldable 27import Data.Foldable
26import Data.Functor 28import Data.Functor
27import Data.Function 29import Data.Function
@@ -53,7 +55,7 @@ sign = label "sign" $ choice [ char '+' $> id
53 , char '-' $> negateV 55 , char '-' $> negateV
54 ] 56 ]
55 57
56boundedNatural :: forall s n m. (Show n, Real n, StringParser s m) 58boundedNatural :: 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
59boundedNatural padded (I.intersection (0 <=..< PosInf) -> bounds) = do 61boundedNatural 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
89boundedRational :: forall s m n. (Show n, RealFrac n, StringParser s m) 91boundedRational :: 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