Copyright | Bryan O'Sullivan 2011, Mario Blažević <blamario@yahoo.com> 2014 |
---|---|
License | BSD3 |
Maintainer | Mario Blažević |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
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.
- data Number
- decimal :: (TextualMonoid t, Integral a) => Parser t a
- hexadecimal :: (TextualMonoid t, Integral a, Bits a) => Parser t a
- signed :: (TextualMonoid t, Num a) => Parser t a -> Parser t a
- double :: TextualMonoid t => Parser t Double
- number :: TextualMonoid t => Parser t Number
- rational :: (TextualMonoid t, Fractional a) => Parser t a
- scientific :: TextualMonoid t => Parser t Scientific
Documentation
A numeric type that can represent integers accurately, and
floating point numbers to the precision of a Double
.
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.
double :: TextualMonoid t => Parser t Double Source
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".
number :: TextualMonoid t => Parser t Number Source
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" rational "e3" == Fail "input does not start with a digit"
Examples of differences from read
:
rational "3.foo" == Done 3.0 ".foo" rational "3e" == Done 3.0 "e"
This function does not accept string representations of "NaN" or "Infinity".
scientific :: TextualMonoid t => Parser t Scientific Source
Parse a scientific number.
The syntax accepted by this parser is the same as for rational
.