parsec-numbers 0.0.2 → 0.0.3
raw patch · 2 files changed
+18/−6 lines, 2 files
Files
Text/ParserCombinators/Parsec/Number.hs view
@@ -48,9 +48,16 @@ Note that most top-level parsers succeed on a string like \"@1.0e-100@\", but only the floating point parsers consume the whole string. The fractional parsers stop before the exponent and the integral parsers before the decimal-point. You may which to check for the end of a string using-'Text.ParserCombinators.Parsec.eof', i.e. @liftM2 const nat eof@.+point. You may wish to check for the end of a string using+'Text.ParserCombinators.Parsec.eof', i.e. \"@liftM2 const nat eof@\". +The returned values may be inaccurate. 'Int' may overflow. Fractional numbers+should be accurate as only one division is performed. Floating point numbers+with decimal exponents may be inaccurate due to using '**'. Rational numbers+are needed for correct conversions, but large positive or negative exponents+may be a problem and the class `RealFloat` is needed to check for minimal and+maximal exponents.+ -} module Text.ParserCombinators.Parsec.Number where@@ -208,6 +215,8 @@ fractFract :: Fractional f => Integer -> Bool -> CharParser st f fractFract i = genFractFract i . fraction +{- | combine the given number before the dot with a parser for the fractional+part -} genFractFract :: Fractional f => Integer -> CharParser st f -> CharParser st f genFractFract i = liftM (fromInteger i +) @@ -227,10 +236,13 @@ ((if requireDigit then many1 else many) baseDigit <?> "fraction") <?> "fraction" --- | compute the fraction given by a sequence of digits following the dot+{- | compute the fraction given by a sequence of digits following the dot.+Only one division is performed and trailing zeros are ignored. -} fractionValue :: Fractional f => Int -> String -> f-fractionValue base =- foldr (\ d -> (/ fromIntegral base) . (+ fromIntegral (digitToInt d))) 0+fractionValue base = uncurry (/)+ . foldl (\ (s, p) d ->+ (p * fromIntegral (digitToInt d) + s, p * fromIntegral base))+ (0, 1) . dropWhile (== '0') . reverse -- * integers and naturals
parsec-numbers.cabal view
@@ -1,5 +1,5 @@ name: parsec-numbers-version: 0.0.2+version: 0.0.3 build-type: Simple cabal-version: >= 1.6 license: BSD3