-- 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 {-# UNPACK #-} !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.6.1 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 -- | Convert an 8-bit unsigned word to a Scientific. fromWord8 :: Word8 -> Scientific -- | Convert a 16-bit unsigned word to a Scientific. fromWord16 :: Word16 -> Scientific -- | Convert a 32-bit unsigned word to a Scientific. fromWord32 :: Word32 -> Scientific -- | Convert a 64-bit unsigned word to a Scientific. fromWord64 :: Word64 -> Scientific fromInt :: Int -> Scientific fromInt8 :: Int8 -> Scientific fromInt16 :: Int16 -> Scientific fromInt32 :: Int32 -> Scientific fromInt64 :: Int64 -> 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 -- | This works even if the number has a fractional component. For example: -- --
--   >>> roundShiftedToInt64 2 (fromFixed @E3 1.037)
--   103
--   
-- -- The shift amount should be a small constant between -100 and 100. The -- behavior of a shift outside this range is undefined. roundShiftedToInt64 :: Int -> Scientific -> Maybe Int64 -- | Is the number represented in scientific notation greater than the -- 64-bit integer argument? greaterThanInt64 :: Scientific -> Int64 -> Bool -- | 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# -- | Encode a number as text. If the exponent is between -50 and +50 -- (exclusive), this represents the number without any exponent. For -- example: -- --
--   >>> encode (small 87654321 (-3))
--   "87654.321"
--   
--   >>> encode (small 5000 (-3))
--   "-5000"
--   
-- -- The decision of when to use an exponent is not considered stable part -- of this library's API. Check the test suite for examples of what to -- expect, and feel free to open an issue or contribute if the output of -- this function is unsightly in certain situations. encode :: Scientific -> ShortText -- | Variant of encode that provides a builder instead. builderUtf8 :: Scientific -> Builder instance GHC.Show.Show Data.Number.Scientific.Scientific instance GHC.Classes.Eq Data.Number.Scientific.Scientific