|Maintainer||Bas van Dijk <firstname.lastname@example.org>|
Data.Scientific provides a space efficient and arbitrary precision
scientific number type.
Scientific numbers are represented using
scientific notation. It
c and an
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
fromInteger c * 10
Scientificis more efficient to construct. Rational numbers need to be constructed using
%which has to compute the
Scientificis safe against numbers with huge exponents. For example:
1e1000000000 ::will fill up all space and crash your program. Scientific works as expected:
> read "1e1000000000" :: Scientific 1.0e1000000000
- Also, the space usage of converting scientific numbers with huge exponents
Float) will always be bounded by the target type.
Note that, in order to do fast magnitude computations (
10^e), this module
computes the first 1100 powers of 10 and stores them in a top-level
array. This means that the first magnitude computation (used in
among others) is slower but subsequent computations should be O(1).
This module is designed to be imported qualified:
import Data.Scientific as Scientific
- data Scientific
- scientific :: Integer -> Int -> Scientific
- coefficient :: Scientific -> Integer
- base10Exponent :: Scientific -> Int
- fromFloatDigits :: RealFloat a => a -> Scientific
- toRealFloat :: forall a. RealFloat a => Scientific -> a
- formatScientific :: FPFormat -> Maybe Int -> Scientific -> String
- data FPFormat
- toDecimalDigits :: Scientific -> ([Int], Int)
- normalize :: Scientific -> Scientific
An arbitrary-precision number represented using scientific notation.
This type describes the set of all
which have a finite
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
1e23 is converted to
9.9999999999999991611392e22, and that
value is shown as
9.999999999999999e22 rather than the shorter
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
e close to 23, the
algorithm doesn't know in which direction the short decimal representation
would be rounded and computes more digits
show but provides rendering options.
Control the rendering of floating point numbers.
Scientific notation (e.g.
Standard decimal notation.
Use decimal notation for values between
toDecimalDigits x = ([d1,d2,...,dn], e)
n >= 1
x = 0.d1d2...dn * (10^^e)
0 <= di <= 9
null $ takeWhile (==0) $ reverse [d1,d2,...,dn]
The last property means that the coefficient will be normalized, i.e. doesn't contain trailing zeros.