scientific-0.3.3.8: 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 :: and a base-10 exponent Integere :: (do
note that since we're using an IntInt 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:
- A
Scientificis more efficient to construct. Rational numbers need to be constructed using%which has to compute thegcdof thenumeratoranddenominator. Scientificis safe against numbers with huge exponents. For example:1e1000000000 ::will fill up all space and crash your program. Scientific works as expected:Rational
> read "1e1000000000" :: Scientific 1.0e1000000000
- Also, the space usage of converting scientific numbers with huge exponents to
(like:IntegralsInt) or(like:RealFloatsDoubleorFloat) will always be bounded by the target type.
Modules
- Data
- ByteString
- Data.Scientific
- Text
- Lazy