NK     Bas van Dijk 2013BSD3#Bas van Dijk <v.dijk.bas@gmail.com>None+M 1An arbitrary-precision number represented using  0http://en.wikipedia.org/wiki/Scientific_notationscientific notation.#This type describes the set of all s( which have a finite decimal expansion.A scientific number with  c and  e corresponds to the  number:  c * 10  e'The coefficient of a scientific number.,The base-10 exponent of a scientific number.scientific c e: constructs a scientific number which corresponds to the  number:  c * 10  e.WNote that this function performs normalization, i.e. it divides out powers of 10 from c and adds them to e.This function is used in the Y methods to guard against computing a huge magnitude (-e) which could take up all space.Think about parsing a scientific number from an untrusted string. An attacker could supply 1e-1000000000. Lets say we want to  that number to an ). When we naively try to floor it using: 7floor = whenFloating $ c e -> fromInteger (c  magnitude (-e)) "We will compute the huge Integer: magnitude 1000000000I. This computation will quickly fill up all space and crash the program.Note that for large positive3 exponents there is no risk of a space-leak since  will compute:  fromInteger c * magnitude e :: awhere ab is the target type (Int in this example). So here the space usage is bounded by the target type.)For large negative exponents we check if the exponent is smaller than some limit (currently -20). In that case we know that the scientific number is really small (unless the coefficient has many digits) so we can immediately return -1 for negative scientific numbers or 0 for positive numbers.More precisely if dangerouslySmall c e returns  the scientific number s is guaranteed to be between: -0.1 > s < 0.1.qNote that we avoid computing the number of decimal digits in c (log10 c) if the exponent is not below the limit. magnitude e == 10 ^ e Convert a  (like a  or  ) into a  number.Note that this function uses , to compute the digits and exponent of the . number. Be aware that the algorithm used in 9 doesn't work as expected for some numbers, e.g. as the  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  Convert a  number into a  (like a  or a ).Note that this function uses   (! . "G) internally but it guards against computing huge Integer magnitudes (10^e7) that could fill up all space and crash your program.Always prefer   over  J when converting from scientific numbers coming from an untrusted source. Like # but provides rendering options.  Similar to  floatToDigits, toDecimalDigits takes a non-negative Q 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  n >= 1  x = 0.d1d2...dn * (10^^e)  0 <= di <= 9$WARNING: % and &F will diverge when their outputs have an infinite decimal expansion. ! will diverge when the input '# has an infinite decimal expansion.(WARNING: " needs to compute the ) magnitude: 10^eU. If applied to a huge exponent this could fill up all space and crash your program!Avoid applying " (or  A) to scientific numbers coming from an untrusted source and use  ; instead. The latter guards against excessive space usage."*+,-./0 12345 #Number of decimal places to render.6 789$(:;<=>    *+,-./0 12345 6 789$(:;<=>None; 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. Like   but provides rendering options.?%Unsafe conversion for decimal digits. #Number of decimal places to render.?@   ?@None;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.Like  but provides rendering options.A%Unsafe conversion for decimal digits.#Number of decimal places to render.ABABC      !"#$%&'(%)*+,-./012345677 89:;<=>?@ABCDEFGHIJAJAKscientific-0.3.0.0Data.Scientific!Data.Text.Lazy.Builder.Scientific"Data.ByteString.Builder.Scientific text-1.2.0.0 Data.Text.Lazy.Builder.RealFloatExponentFixedGenericFPFormat Scientific coefficientbase10Exponent scientificfromFloatDigits toRealFloatformatScientifictoDecimalDigitsscientificBuilderformatScientificBuilderbaseGHC.RealReal FractionalGHC.Num fromInteger^^dangerouslySmallRealFracfloorghc-prim GHC.TypesIntdiv whenFloatingTrue magnitude GHC.Float RealFloatDoubleFloat floatToDigits realToFrac fromRational toRationalGHC.Showshow$fFractionalScientificrecip/Rational$fRealScientific integer-gmpGHC.Integer.TypeIntegerSP normalize positivizemaxExptexpts10 scientificP foldDigits isDecimalisSignisEroundTo$fShowScientific$fReadScientific$fRealFracScientific$fNumScientific$fOrdScientific$fEqScientific$fHashableScientific$fNFDataScientifici2d