Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- data Sign
- data OverUnder a
- data FracWord word = FracWord !word !Int
- fracToWord8 :: FracWord Word8 -> Integer -> OverUnder Word8
- fracToWord16 :: FracWord Word16 -> Integer -> OverUnder Word16
- fracToWord32 :: FracWord Word32 -> Integer -> OverUnder Word32
- fracToWord64 :: FracWord Word64 -> Integer -> OverUnder Word64
- fracToWord :: FracWord Word -> Integer -> OverUnder Word
- data FracInt word = FracInt !word !Int
- fracToInt8 :: Sign -> FracInt Word8 -> Integer -> OverUnder Int8
- fracToInt16 :: Sign -> FracInt Word16 -> Integer -> OverUnder Int16
- fracToInt32 :: Sign -> FracInt Word32 -> Integer -> OverUnder Int32
- fracToInt64 :: Sign -> FracInt Word64 -> Integer -> OverUnder Int64
- fracToInt :: Sign -> FracInt Word -> Integer -> OverUnder Int
- data FracFloat word = FracFloat !word !Int
- fracToFloat :: Sign -> FracFloat Word32 -> Integer -> Float
- fracToDouble :: Sign -> FracFloat Word64 -> Integer -> Double
- fracWord8Dec :: overflow -> FracWord Word8 -> Int64 -> Parser overflow (FracWord Word8)
- fracWord16Dec :: overflow -> FracWord Word16 -> Int64 -> Parser overflow (FracWord Word16)
- fracWord32Dec :: overflow -> FracWord Word32 -> Int64 -> Parser overflow (FracWord Word32)
- fracWord64Dec :: overflow -> FracWord Word64 -> Int64 -> Parser overflow (FracWord Word64)
- fracWordDec :: overflow -> FracWord Word -> Int64 -> Parser overflow (FracWord Word)
- fracInt8Dec :: overflow -> Sign -> FracInt Word8 -> Int64 -> Parser overflow (FracInt Word8)
- fracInt16Dec :: overflow -> Sign -> FracInt Word16 -> Int64 -> Parser overflow (FracInt Word16)
- fracInt32Dec :: overflow -> Sign -> FracInt Word32 -> Int64 -> Parser overflow (FracInt Word32)
- fracInt64Dec :: overflow -> Sign -> FracInt Word64 -> Int64 -> Parser overflow (FracInt Word64)
- fracIntDec :: overflow -> Sign -> FracInt Word -> Int64 -> Parser overflow (FracInt Word)
- fracFloat23Dec :: FracFloat Word32 -> Parser never (FracFloat Word32)
- fracFloat52Dec :: FracFloat Word64 -> Parser never (FracFloat Word64)
Representation
Whether the number is positive or negative.
Whether the integer can be represented properly.
Unsigned integral
Intermediate representation of an unsigned integer.
Conversions
Arguments
:: FracWord Word8 | |
-> Integer | Radix-10 order of magnitude of the expected result. |
-> OverUnder Word8 |
Convert the intermediate representation into a Word8
, if possible.
Arguments
:: FracWord Word16 | |
-> Integer | Radix-10 order of magnitude of the expected result. |
-> OverUnder Word16 |
Convert the intermediate representation into a Word16
, if possible.
Arguments
:: FracWord Word32 | |
-> Integer | Radix-10 order of magnitude of the expected result. |
-> OverUnder Word32 |
Convert the intermediate representation into a Word32
, if possible.
Arguments
:: FracWord Word64 | |
-> Integer | Radix-10 order of magnitude of the expected result. |
-> OverUnder Word64 |
Convert the intermediate representation into a Word64
, if possible.
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
Intermediate representation of a signed integer.
Conversions
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.
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.
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.
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.
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
Intermediate representation of a floating-point number's significand.
Arguments
:: Sign | |
-> FracFloat Word32 | |
-> Integer | Radix-10 order of magnitude of the expected result. |
-> Float |
Convert the intermediate representation to a Float
.
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
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.
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.
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.
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.
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
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.
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.
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.
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.
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.