scientific 0.3.4.3 → 0.3.4.4
raw patch · 4 files changed
+30/−35 lines, 4 filesdep ~basedep ~binary
Dependency ranges changed: base, binary
Files
- bench/bench.hs +7/−0
- changelog +3/−0
- scientific.cabal +4/−14
- src/Data/Scientific.hs +16/−21
bench/bench.hs view
@@ -36,6 +36,10 @@ [ bench "round" (nf (round :: Scientific -> Integer) $! pos) , bench "roundDefault" (nf roundDefault $! pos) ]++ , bgroup "toDecimalDigits"+ [ bench "big" (nf toDecimalDigits $! big)+ ] ] where pos :: Fractional a => a@@ -49,6 +53,9 @@ negInt :: Fractional a => a negInt = -int++ big :: Scientific+ big = read $ "0." ++ concat (replicate 20 "0123456789") realToFracStoD :: Scientific -> Double realToFracStoD = fromRational . toRational
changelog view
@@ -1,3 +1,6 @@+0.3.4.4+ * Improved performance of toDecimalDigits by 13%.+ 0.3.4.3 * Fix build with integer-simple.
scientific.cabal view
@@ -1,5 +1,5 @@ name: scientific-version: 0.3.4.3+version: 0.3.4.4 synopsis: Numbers represented using scientific notation description: @Data.Scientific@ provides the number type 'Scientific'. Scientific numbers are@@ -115,20 +115,10 @@ benchmark bench-scientific type: exitcode-stdio-1.0- hs-source-dirs: bench src+ hs-source-dirs: bench main-is: bench.hs default-language: Haskell2010 ghc-options: -O2- build-depends: base >= 4.3 && < 4.9+ build-depends: scientific+ , base >= 4.3 && < 4.9 , criterion >= 0.5 && < 1.2- , ghc-prim- , deepseq >= 1.3 && < 1.5- , text >= 0.8 && < 1.3- , bytestring >= 0.10 && < 0.11- , hashable >= 1.1.2 && < 1.3- , vector >= 0.5 && < 0.12-- if flag(integer-simple)- build-depends: integer-simple- else- build-depends: integer-gmp
src/Data/Scientific.hs view
@@ -92,7 +92,7 @@ import Control.Exception (throw, ArithException(DivideByZero)) import Control.Monad (mplus) import Control.Monad.ST (runST)-import Control.DeepSeq (NFData(rnf))+import Control.DeepSeq (NFData, rnf) import Data.Binary (Binary, get, put) import Data.Char (intToDigit, ord) import Data.Data (Data)@@ -947,19 +947,14 @@ toDecimalDigits (Scientific 0 _) = ([0], 1) toDecimalDigits (Scientific c' e') = case normalizePositive c' e' of- (c, e) -> case reverseAndLength $ digits c of- (is, n) -> (is, n + e)- where- digits :: Integer -> [Int]- digits 0 = []- digits i = case i `quotRemInteger` 10 of- (# q, r #) -> fromIntegral r : digits q-- reverseAndLength :: [a] -> ([a], Int)- reverseAndLength l = rev l [] 0- where- rev [] a !m = (a, m)- rev (x:xs) a !m = rev xs (x:a) (m+1)+ Scientific c e -> go c 0 []+ where+ go :: Integer -> Int -> [Int] -> ([Int], Int)+ go 0 !n ds = (ds, ne) where !ne = n + e+ go i !n ds = case i `quotRemInteger` 10 of+ (# q, r #) -> go q (n+1) (d:ds)+ where+ !d = fromIntegral r ----------------------------------------------------------------------@@ -973,12 +968,12 @@ -- automatically normalized when pretty-printed and in 'toDecimalDigits'. normalize :: Scientific -> Scientific normalize (Scientific c e)- | c > 0 = case normalizePositive c e of (c', e') -> Scientific c' e'- | c < 0 = case normalizePositive (-c) e of (c', e') -> Scientific (-c') e'+ | c > 0 = normalizePositive c e+ | c < 0 = -(normalizePositive (-c) e) | otherwise {- c == 0 -} = Scientific 0 0 -normalizePositive :: Integer -> Int -> (Integer, Int)-normalizePositive c !e = case quotRemInteger c 10 of- (# c', r #)- | r == 0 -> normalizePositive c' (e+1)- | otherwise -> (c, e)+normalizePositive :: Integer -> Int -> Scientific+normalizePositive !c !e = case quotRemInteger c 10 of+ (# c', r #)+ | r == 0 -> normalizePositive c' (e+1)+ | otherwise -> Scientific c e