From dccf2c949c10892b368484c3e85bb2bb14e613e2 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 16 Feb 2017 19:42:50 +0100 Subject: Bruteforce digit calculation --- lib/Postdelay/TimeSpec/Utils.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/Postdelay/TimeSpec/Utils.hs') 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 import Data.Time.Zones import Data.Bool +import Data.Maybe +import Data.List import Data.Foldable import Data.Functor import Data.Function @@ -53,7 +55,7 @@ sign = label "sign" $ choice [ char '+' $> id , char '-' $> negateV ] -boundedNatural :: forall s n m. (Show n, Real n, StringParser s m) +boundedNatural :: forall s n m. (Show n, Ord n, Num n, StringParser s m) => Bool -- ^ Require number to be padded with zeroes? -> Interval n -> m n boundedNatural padded (I.intersection (0 <=..< PosInf) -> bounds) = do @@ -84,7 +86,7 @@ boundedNatural padded (I.intersection (0 <=..< PosInf) -> bounds) = do | otherwise = int digits :: n -> Int - digits = succ . floor . (logBase 10 :: Double -> Double) . realToFrac . abs + digits n = succ . fromJust $ findIndex (\(min, max) -> min <= n && n < max) [ (10^i, 10^(succ i)) | i <- ([0..] :: [Int]) ] boundedRational :: forall s m n. (Show n, RealFrac n, StringParser s m) => Bool -- ^ Require number to be padded with zeroes -- cgit v1.2.3