lathe-0.1.0.0: Pure incremental byte parser.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Parser.Lathe.Numeric.Fractional

Description

Functions for parsing bounded numbers expressed as fractions.

Parsing functions in this module are only guaranteed to operate correctly when their arguments are sensible and the input number has no leading zeroes.

Example

Converting "-1200.00340e6" to an Int32, skipping operations outside of this module:

>>> parse (fracInt32Dec () Minus (FracInt 0 0) 0) "1200.00340e6"
(Scrap 4 ".00340e6" End,Right (FracInt 12 2))

>>> parse (fracInt32Dec () Minus (FracInt 12 2) 4) "00340e6"
(Scrap 5 "e6" End,Right (FracInt 12000034 8))

>>> let ex = 6 + 4 -- Exponent plus number of digits before decimal point

>>> fracToInt32 Minus (FracInt 12000034 8) ex
Proper (-12000034000)

Similarly, "123456789098.7654321e-17" to Float:

>>> parse (fracFloat23Dec (FracFloat 0 0)) "123456789098.7654321e-17"
(Scrap 12 ".7654321e-17" End,Right (FracFloat 123456789 9))

>>> parse (fracFloat23Dec (FracFloat 123456789 9)) "7654321e-17"
(Scrap 7 "e-17" End,Right (FracFloat 123456789 9))

>>> fracToFloat Plus (FracFloat 123456789 9) ((-17) + 12)
1.2345679e-6
Synopsis

Representation

data Sign Source #

Whether the number is positive or negative.

Constructors

Plus 
Minus 

Instances

Instances details
Show Sign Source # 
Instance details

Defined in Parser.Lathe.Numeric.Internal

Methods

showsPrec :: Int -> Sign -> ShowS #

show :: Sign -> String #

showList :: [Sign] -> ShowS #

data OverUnder a Source #

Whether the integer can be represented properly.

Constructors

Proper !a 
Over

Overflow.

Under

Underflow.

Instances

Instances details
Show a => Show (OverUnder a) Source # 
Instance details

Defined in Parser.Lathe.Numeric.Fractional

Unsigned integral

data FracWord word Source #

Intermediate representation of an unsigned integer.

Constructors

FracWord 

Fields

  • !word

    Either 0 or a number with a non-zero lowest digit.

  • !Int

    Number of decimal digits consumed by this integer.

Instances

Instances details
Show word => Show (FracWord word) Source # 
Instance details

Defined in Parser.Lathe.Numeric.Fractional

Methods

showsPrec :: Int -> FracWord word -> ShowS #

show :: FracWord word -> String #

showList :: [FracWord word] -> ShowS #

Conversions

fracToWord8 Source #

Arguments

:: FracWord Word8 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Word8 

Convert the intermediate representation into a Word8, if possible.

fracToWord16 Source #

Arguments

:: FracWord Word16 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Word16 

Convert the intermediate representation into a Word16, if possible.

fracToWord32 Source #

Arguments

:: FracWord Word32 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Word32 

Convert the intermediate representation into a Word32, if possible.

fracToWord64 Source #

Arguments

:: FracWord Word64 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Word64 

Convert the intermediate representation into a Word64, if possible.

fracToWord Source #

Arguments

:: FracWord Word 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Word 

Convert the intermediate representation into a Word, if possible.

Signed integral

data FracInt word Source #

Intermediate representation of a signed integer.

Constructors

FracInt 

Fields

  • !word

    Either 0 or a number with a non-zero lowest digit.

  • !Int

    Number of decimal digits consumed by this integer.

Instances

Instances details
Show word => Show (FracInt word) Source # 
Instance details

Defined in Parser.Lathe.Numeric.Fractional

Methods

showsPrec :: Int -> FracInt word -> ShowS #

show :: FracInt word -> String #

showList :: [FracInt word] -> ShowS #

Conversions

fracToInt8 Source #

Arguments

:: Sign 
-> FracInt Word8 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Int8 

Convert the intermediate representation into an Int8, if possible.

fracToInt16 Source #

Arguments

:: Sign 
-> FracInt Word16 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Int16 

Convert the intermediate representation into an Int16, if possible.

fracToInt32 Source #

Arguments

:: Sign 
-> FracInt Word32 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Int32 

Convert the intermediate representation into an Int32, if possible.

fracToInt64 Source #

Arguments

:: Sign 
-> FracInt Word64 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Int64 

Convert the intermediate representation into an Int64, if possible.

fracToInt Source #

Arguments

:: Sign 
-> FracInt Word 
-> Integer

Radix-10 order of magnitude of the expected result.

-> OverUnder Int 

Convert the intermediate representation into an Int, if possible.

Floating-point

data FracFloat word Source #

Intermediate representation of a floating-point number's significand.

Constructors

FracFloat 

Fields

  • !word

    Significand in untrimmed integer form.

  • !Int

    Number of decimal digits consumed by the significand.

Instances

Instances details
Show word => Show (FracFloat word) Source # 
Instance details

Defined in Parser.Lathe.Numeric.Fractional

Methods

showsPrec :: Int -> FracFloat word -> ShowS #

show :: FracFloat word -> String #

showList :: [FracFloat word] -> ShowS #

fracToFloat Source #

Arguments

:: Sign 
-> FracFloat Word32 
-> Integer

Radix-10 order of magnitude of the expected result.

-> Float 

Convert the intermediate representation to a Float.

fracToDouble Source #

Arguments

:: Sign 
-> FracFloat Word64 
-> Integer

Radix-10 order of magnitude of the expected result.

-> Double 

Convert the intermediate representation to a Double.

Parsing

Decimal

Unsigned integral

fracWord8Dec Source #

Arguments

:: overflow 
-> FracWord Word8 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracWord Word8) 

Consume up to 3 decimal digits and any number of zeroes after into a Word8-compatible container.

fracWord16Dec Source #

Arguments

:: overflow 
-> FracWord Word16 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracWord Word16) 

Consume up to 5 decimal digits and any number of zeroes after into a Word16-compatible container.

fracWord32Dec Source #

Arguments

:: overflow 
-> FracWord Word32 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracWord Word32) 

Consume up to 9 decimal digits and any number of zeroes after into a Word32-compatible container.

fracWord64Dec Source #

Arguments

:: overflow 
-> FracWord Word64 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracWord Word64) 

Consume up to 20 decimal digits and any number of zeroes after into a Word64-compatible container.

fracWordDec Source #

Arguments

:: overflow 
-> FracWord Word 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracWord Word) 

Consume up to 9 or 20 decimal digits (depending on current platform's integer size) and any number of zeroes after into a Word-compatible container.

Signed integral

fracInt8Dec Source #

Arguments

:: overflow 
-> Sign 
-> FracInt Word8 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracInt Word8) 

Consume up to 3 decimal digits and any number of zeroes after into an Int8-compatible container.

fracInt16Dec Source #

Arguments

:: overflow 
-> Sign 
-> FracInt Word16 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracInt Word16) 

Consume up to 5 decimal digits and any number of zeroes after into an Int16-compatible container.

fracInt32Dec Source #

Arguments

:: overflow 
-> Sign 
-> FracInt Word32 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracInt Word32) 

Consume up to 9 decimal digits and any number of zeroes after into an Int32-compatible container.

fracInt64Dec Source #

Arguments

:: overflow 
-> Sign 
-> FracInt Word64 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracInt Word64) 

Consume up to 19 decimal digits and any number of zeroes after into an Int64-compatible container.

fracIntDec Source #

Arguments

:: overflow 
-> Sign 
-> FracInt Word 
-> Int64

Number of decimal digits consumed by this number.

-> Parser overflow (FracInt Word) 

Consume up to 9 or 19 decimal digits (depending on current platform's integer size) and any number of zeroes after into an Int-compatible container.

Floating-point

fracFloat23Dec :: FracFloat Word32 -> Parser never (FracFloat Word32) Source #

Consume any number of consecutive decimal digits into a Float-compatible container.

The container retains no more than 9 leading decimal digits.

fracFloat52Dec :: FracFloat Word64 -> Parser never (FracFloat Word64) Source #

Consume any number of consecutive decimal digits into a Double-compatible container.

The container retains no more than 17 leading decimal digits.