packages feed

scientific 0.0.0.1 → 0.0.0.2

raw patch · 2 files changed

+23/−17 lines, 2 filesdep ~base

Dependency ranges changed: base

Files

scientific.cabal view
@@ -1,5 +1,5 @@ name:                scientific-version:             0.0.0.1+version:             0.0.0.2 synopsis:            Arbitrary-precision floating-point numbers represented using scientific notation description:         A @Scientific@ number is an arbitrary-precision floating-point number                      represented using scientific notation.@@ -31,7 +31,7 @@   exposed-modules:     Data.Scientific   other-extensions:    DeriveDataTypeable, BangPatterns   ghc-options:         -Wall-  build-depends:       base     >= 4.6   && < 4.7+  build-depends:       base     >= 4.3   && < 4.7                      , deepseq  >= 1.3   && < 1.4                      , text     >= 0.8   && < 0.12                      , hashable >= 1.1.2 && < 1.3@@ -46,7 +46,7 @@   ghc-options:      -Wall    build-depends: scientific-               , base             >= 4.6   && < 4.7+               , base             >= 4.3   && < 4.7                , tasty            >= 0.3.1 && < 0.4                , tasty-smallcheck >= 0.2   && < 0.3                , smallcheck       >= 1.0   && < 1.1@@ -59,5 +59,5 @@   default-language: Haskell2010   ghc-options:      -O2   build-depends:    scientific-                  , base       >= 4.6 && < 4.7+                  , base       >= 4.3 && < 4.7                   , criterion  >= 0.5 && < 0.9
src/Data/Scientific.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE DeriveDataTypeable, BangPatterns #-}  -- TODO: The following extensions are needed for scientificBuilder:-{-# LANGUAGE MagicHash, OverloadedStrings #-}+{-# LANGUAGE CPP, MagicHash, OverloadedStrings #-}  -- | -- Module      :  Data.Scientific@@ -36,7 +36,7 @@  ---------------------------------------------------------------------- -import           Control.Applicative (pure, (<|>), (*>))+import           Control.Monad       (mplus) import           Control.DeepSeq     (NFData) import           Data.Char           (intToDigit, ord) import           Data.Function       (on)@@ -55,9 +55,15 @@ import Data.Text.Lazy.Builder       (Builder, fromString, singleton, fromText) import Data.Text.Lazy.Builder.Int   (decimal) import qualified Data.Text as T     (replicate)-import Data.Monoid                  ((<>)) import GHC.Base                     (Int(I#), Char(C#), chr#, ord#, (+#))-+#if MIN_VERSION_base(4,5,0)+import Data.Monoid                  ((<>))+#else+import Data.Monoid                  (Monoid, mappend)+(<>) :: Monoid a => a -> a -> a+(<>) = mappend+infixr 6 <>+#endif  ---------------------------------------------------------------------- @@ -95,7 +101,7 @@  scientificP :: ReadP Scientific scientificP = do-  let positive = (('+' ==) <$> ReadP.satisfy isSign) <|> pure True+  let positive = (('+' ==) <$> ReadP.satisfy isSign) `mplus` return True   pos <- positive    let step :: Num a => a -> Int -> a@@ -106,7 +112,7 @@   let s = Scientific n 0       fractional = foldDigits (\(Scientific a e) digit -> scientific (step a digit) (e-1)) s -  Scientific coeff expnt <- (ReadP.satisfy (== '.') *> fractional) <|> pure s+  Scientific coeff expnt <- (ReadP.satisfy (== '.') >> fractional) `mplus` return s    let signedCoeff | pos       = coeff                   | otherwise = negate coeff@@ -114,23 +120,23 @@       eP = do posE <- positive               e <- foldDigits step 0               if posE-                then pure e-                else pure $ negate e+                then return e+                else return $ negate e -  (ReadP.satisfy isE *>-         ((scientific signedCoeff . (expnt +)) <$> eP)) <|>-     pure (scientific signedCoeff    expnt)+  (ReadP.satisfy isE >>+           ((scientific signedCoeff . (expnt +)) <$> eP)) `mplus`+     return (scientific signedCoeff    expnt)  foldDigits :: (a -> Int -> a) -> a -> ReadP a foldDigits f z = ReadP.look >>= go z     where-      go !a [] = pure a+      go !a [] = return a       go !a (c:cs)           | isDecimal c = do               _ <- ReadP.get               let digit = ord c - 48               go (f a digit) cs-          | otherwise = pure a+          | otherwise = return a  isDecimal :: Char -> Bool isDecimal c = c >= '0' && c <= '9'