-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Scientific notation intended for tokenization -- -- This library provides a type used to represent a number in scientific -- notation. This is most frequently useful when tokenizing or parsing a -- language. Languages like JSON and SQL support numberic literals -- written in scientific notation, even though backends frequently reject -- numbers outside a given range. This library provides a compact -- representation of numbers in scientific notation. In the common case -- of the coefficient and then exponent each being small enough to be -- represented by a machine word, this library avoids the need for any -- indirections to retrieve the number. Consider some tokenization -- scheme: `data Token = ... | Number {--} !Scientific`. In this case, -- the unboxed coefficient and exponent are unpacked into the -- Number data constructor if they can each be represented by a -- machine word. -- -- The internal representation does not normalize numbers. That is, -- parsing `300e-2` resulting in a representation that uses `300` and -- `-2` rather than `3` and `0`. This work is deferred with the -- expectation that a number in scientific notation is consumed either -- zero or one times. This library is not optimized for use-cases that -- consume a Scientific more than once since normalization is -- reapplied every time. -- -- The primary library that operates in this same space is -- scientific. Compared to scientific, this library -- distinguishes itself from scientific in the following ways: -- -- @package scientific-notation @version 0.1.2.0 module Data.Number.Scientific data Scientific type Scientific# = (# Int#, Int#, LargeScientific #) -- | Construct a Scientific from a coefficient and exponent that fit -- in a machine word. small :: Int -> Int -> Scientific -- | Construct a Scientific from a coefficient and exponent of -- arbitrary size. large :: Integer -> Integer -> Scientific -- | Construct a Scientific from a fixed-precision number. This does -- not perform well and is only included for convenience. fromFixed :: HasResolution e => Fixed e -> Scientific toWord :: Scientific -> Maybe Word toWord8 :: Scientific -> Maybe Word8 toWord16 :: Scientific -> Maybe Word16 toWord32 :: Scientific -> Maybe Word32 toWord64 :: Scientific -> Maybe Word64 toInt :: Scientific -> Maybe Int toInt32 :: Scientific -> Maybe Int32 toInt64 :: Scientific -> Maybe Int64 -- | Expose the non-normalized exponent and coefficient. withExposed :: (Int -> Int -> a) -> (Integer -> Integer -> a) -> Scientific -> a -- | Parse a number that is encoded in UTF-8 and in scientific notation. -- All of these are accepted: -- -- parserSignedUtf8Bytes :: e -> Parser e s Scientific parserTrailingUtf8Bytes :: e -> Int -> Parser e s Scientific -- | Variant of parserSignedUtf8Bytes that rejects strings with a -- leading plus or minus sign. parserUnsignedUtf8Bytes :: e -> Parser e s Scientific -- | Variant of parserUnsignedUtf8Bytes that negates the result. parserNegatedUtf8Bytes :: e -> Parser e s Scientific parserNegatedTrailingUtf8Bytes :: e -> Int -> Parser e s Scientific parserSignedUtf8Bytes# :: e -> Parser e s Scientific# parserTrailingUtf8Bytes# :: e -> Int# -> Parser e s Scientific# -- | Variant of parseUnsignedUtf8Bytes where all arguments are -- unboxed. parserUnsignedUtf8Bytes# :: e -> Parser e s Scientific# parserNegatedUtf8Bytes# :: e -> Parser e s Scientific# parserNegatedTrailingUtf8Bytes# :: e -> Int# -> Parser e s Scientific# builderUtf8 :: Scientific -> Builder instance GHC.Show.Show Data.Number.Scientific.Scientific instance GHC.Classes.Eq Data.Number.Scientific.Scientific