|Maintainer||Bas van Dijk <email@example.com>|
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
denominator. Scientific numbers only need to be normalized, i.e.
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.
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)
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 takes a
Scientific number, and returns a list of digits and
a base-10 exponent. In particular, if
toDecimalDigits x = ([d1,d2,...,dn], e)
n >= 1
x = 0.d1d2...dn * (10^^e)
0 <= di <= 9