picoparsec-0.1.2.2: Fast combinator parsing for bytestrings and text

Copyright Bryan O'Sullivan 2011, Mario Blažević 2014 BSD3 Mario Blažević experimental unknown None Haskell2010

Data.Picoparsec.Number

Contents

Description

This module is deprecated, and both the module and `Number` type will be removed in the next major release. Use the scientific package and the `Scientific` type instead.

A simple number type, useful for parsing both exact and inexact quantities without losing much precision.

Synopsis

Documentation

data Number Source

A numeric type that can represent integers accurately, and floating point numbers to the precision of a `Double`.

Constructors

 I !Integer D !Double

Instances

 Eq Number Fractional Number Data Number Num Number Ord Number Real Number RealFrac Number Show Number NFData Number Typeable * Number

Numeric parsers

decimal :: (TextualMonoid t, Integral a) => Parser t a Source

Parse and decode an unsigned decimal number.

hexadecimal :: (TextualMonoid t, Integral a, Bits a) => Parser t a Source

Parse and decode an unsigned hexadecimal number. The hex digits `'a'` through `'f'` may be upper or lower case.

This parser does not accept a leading `"0x"` string.

signed :: (TextualMonoid t, Num a) => Parser t a -> Parser t a Source

Parse a number with an optional leading `'+'` or `'-'` sign character.

Parse a rational number.

The syntax accepted by this parser is the same as for `rational`.

Note: This function is almost ten times faster than `rational`, but is slightly less accurate.

The `Double` type supports about 16 decimal places of accuracy. For 94.2% of numbers, this function and `rational` give identical results, but for the remaining 5.8%, this function loses precision around the 15th decimal place. For 0.001% of numbers, this function will lose precision at the 13th or 14th decimal place.

This function does not accept string representations of "NaN" or "Infinity".

Parse a number, attempting to preserve both speed and precision.

The syntax accepted by this parser is the same as for `rational`.

Note: This function is almost ten times faster than `rational`. On integral inputs, it gives perfectly accurate answers, and on floating point inputs, it is slightly less accurate than `rational`.

This function does not accept string representations of "NaN" or "

rational :: (TextualMonoid t, Fractional a) => Parser t a Source

Parse a rational number.

This parser accepts an optional leading sign character, followed by at least one decimal digit. The syntax similar to that accepted by the `read` function, with the exception that a trailing `'.'` or `'e'` not followed by a number is not consumed.

Examples with behaviour identical to `read`, if you feed an empty continuation to the first result:

```rational "3"     == Done 3.0 ""
rational "3.1"   == Done 3.1 ""
rational "3e4"   == Done 30000.0 ""
rational "3.1e4" == Done 31000.0, ""```

Examples with behaviour identical to `read`:

```rational ".3"    == Fail "input does not start with a digit"
Examples of differences from `read`:
```rational "3.foo" == Done 3.0 ".foo"
The syntax accepted by this parser is the same as for `rational`.