-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Numbers represented using scientific notation -- -- Data.Scientific provides a space efficient and arbitrary -- precision scientific number type. -- -- Scientific numbers are represented using scientific -- notation. It uses a coefficient c :: Integer and a -- base-10 exponent e :: Int (do note that since we're -- using an Int to represent the exponent these numbers aren't -- truly arbitrary precision). A scientific number corresponds to the -- Fractional number: fromInteger c * 10 ^^ -- e. -- -- The main application of Scientific is to be used as the target -- of parsing arbitrary precision numbers coming from an untrusted -- source. The advantages over using Rational for this are that: -- -- -- --
--   > read "1e1000000000" :: Scientific
--   1.0e1000000000
--   
-- -- @package scientific @version 0.3.2.2 -- | Data.Scientific provides a space efficient and arbitrary -- precision scientific number type. -- -- Scientific numbers are represented using scientific -- notation. It uses an Integer coefficient c -- and an Int base10Exponent e (do note that since -- we're using an Int to represent the exponent these numbers -- aren't truly arbitrary precision). A scientific number corresponds to -- the Fractional number: fromInteger c * 10 ^^ -- e. -- -- The main application of Scientific is to be used as the target -- of parsing arbitrary precision numbers coming from an untrusted -- source. The advantages over using Rational for this are that: -- -- -- --
--   > read "1e1000000000" :: Scientific
--   1.0e1000000000
--   
-- -- -- -- This module is designed to be imported qualified: -- --
--   import Data.Scientific as Scientific
--   
module Data.Scientific -- | An arbitrary-precision number represented using scientific -- notation. -- -- This type describes the set of all Reals which have a -- finite decimal expansion. -- -- A scientific number with coefficient c and -- base10Exponent e corresponds to the Fractional -- number: fromInteger c * 10 ^^ e data Scientific -- | scientific c e constructs a scientific number which -- corresponds to the Fractional number: fromInteger c -- * 10 ^^ e. scientific :: Integer -> Int -> Scientific -- | The coefficient of a scientific number. -- -- Note that this number is not necessarily normalized, i.e. it could -- contain trailing zeros. -- -- Scientific numbers are automatically normalized when pretty printed or -- in toDecimalDigits. -- -- Use normalize to do manual normalization. coefficient :: Scientific -> Integer -- | The base-10 exponent of a scientific number. base10Exponent :: Scientific -> Int -- | Convert a RealFloat (like a Double or Float) into -- a Scientific number. -- -- Note that this function uses floatToDigits to compute the -- digits and exponent of the RealFloat number. Be aware that the -- algorithm used in floatToDigits doesn't work as expected for -- some numbers, e.g. as the Double 1e23 is converted to -- 9.9999999999999991611392e22, and that value is shown as -- 9.999999999999999e22 rather than the shorter 1e23; -- the algorithm doesn't take the rounding direction for values exactly -- half-way between two adjacent representable values into account, so if -- you have a value with a short decimal representation exactly half-way -- between two adjacent representable values, like 5^23*2^e for -- e close to 23, the algorithm doesn't know in which direction -- the short decimal representation would be rounded and computes more -- digits fromFloatDigits :: RealFloat a => a -> Scientific -- | Convert a Scientific number into a RealFloat (like a -- Double or a Float). -- -- Note that this function uses realToFrac -- (fromRational . toRational) internally but it -- guards against computing huge Integer magnitudes (10^e) that -- could fill up all space and crash your program. -- -- Always prefer toRealFloat over realToFrac when -- converting from scientific numbers coming from an untrusted source. toRealFloat :: RealFloat a => Scientific -> a -- | floatingOrInteger determines if the scientific is floating -- point or integer. In case it's floating-point the scientific is -- converted to the desired RealFloat using toRealFloat. floatingOrInteger :: (RealFloat r, Integral i) => Scientific -> Either r i -- | Like show but provides rendering options. formatScientific :: FPFormat -> Maybe Int -> Scientific -> String -- | Control the rendering of floating point numbers. data FPFormat :: * -- | Scientific notation (e.g. 2.3e123). Exponent :: FPFormat -- | Standard decimal notation. Fixed :: FPFormat -- | Use decimal notation for values between 0.1 and -- 9,999,999, and scientific notation otherwise. Generic :: FPFormat -- | Similar to floatToDigits, toDecimalDigits takes a -- non-negative Scientific number, and returns a list of digits -- and a base-10 exponent. In particular, if x>=0, and -- --
--   toDecimalDigits x = ([d1,d2,...,dn], e)
--   
-- -- then -- --
    --
  1. n >= 1
  2. --
  3. x = 0.d1d2...dn * (10^^e)
  4. --
  5. 0 <= di <= 9
  6. --
  7. null $ takeWhile (==0) $ reverse [d1,d2,...,dn]
  8. --
-- -- The last property means that the coefficient will be normalized, i.e. -- doesn't contain trailing zeros. toDecimalDigits :: Scientific -> ([Int], Int) -- | Normalize a scientific number by dividing out powers of 10 from the -- coefficient and incrementing the base10Exponent each -- time. -- -- You should rarely have a need for this function since scientific -- numbers are automatically normalized when pretty-printed and in -- toDecimalDigits. normalize :: Scientific -> Scientific instance Typeable Scientific instance Data Scientific instance Show Scientific instance Read Scientific instance RealFrac Scientific instance Fractional Scientific instance Real Scientific instance Num Scientific instance Ord Scientific instance Eq Scientific instance Hashable Scientific instance NFData Scientific module Data.Text.Lazy.Builder.Scientific -- | A Text Builder which renders a scientific number to -- full precision, using standard decimal notation for arguments whose -- absolute value lies between 0.1 and 9,999,999, and -- scientific notation otherwise. scientificBuilder :: Scientific -> Builder -- | Like scientificBuilder but provides rendering options. formatScientificBuilder :: FPFormat -> Maybe Int -> Scientific -> Builder -- | Control the rendering of floating point numbers. data FPFormat :: * -- | Scientific notation (e.g. 2.3e123). Exponent :: FPFormat -- | Standard decimal notation. Fixed :: FPFormat -- | Use decimal notation for values between 0.1 and -- 9,999,999, and scientific notation otherwise. Generic :: FPFormat module Data.ByteString.Builder.Scientific -- | A ByteString Builder which renders a scientific -- number to full precision, using standard decimal notation for -- arguments whose absolute value lies between 0.1 and -- 9,999,999, and scientific notation otherwise. scientificBuilder :: Scientific -> Builder -- | Like scientificBuilder but provides rendering options. formatScientificBuilder :: FPFormat -> Maybe Int -> Scientific -> Builder -- | Control the rendering of floating point numbers. data FPFormat :: * -- | Scientific notation (e.g. 2.3e123). Exponent :: FPFormat -- | Standard decimal notation. Fixed :: FPFormat -- | Use decimal notation for values between 0.1 and -- 9,999,999, and scientific notation otherwise. Generic :: FPFormat