h$6S4)      !"#$%&'( Trustworthy)*+ Trustworthy, scientific%Unsafe conversion for decimal digits.- scientificThe same limit as in GHC.Float.. scientific magnitude e == 10 ^ e/,-.Bas van Dijk 2013BSD3#Bas van Dijk  Trustworthy23;1z scientific1An arbitrary-precision number represented using  0http://en.wikipedia.org/wiki/Scientific_notationscientific notation.#This type describes the set of all 0s( which have a finite decimal expansion.A scientific number with  c and  e corresponds to the 1 number: 2 c * 10 3 e 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 .Use  to do manual normalization.WARNING:  and base10exponent violate substantivity of 4.let x = scientific 1 2let y = scientific 100 0x == yTruebut(coefficient x == coefficient y, base10Exponent x == base10Exponent y) (False,False) scientific,The base-10 exponent of a scientific number. scientificscientific c e: constructs a scientific number which corresponds to the 1 number: 2 c * 10 3 e. scientific Although 5, is unsafe because it will throw errors on  /https://en.wikipedia.org/wiki/Repeating_decimalrepeating decimals, unsafeFromRational is even more unsafe because it will diverge instead (i.e loop and consume all space). Though it will be more efficient because it doesn't need to consume space linear in the number of digits in the resulting scientific to detect the repetition.Consider using   for these rationals which will detect the repetition and indicate where it starts.  scientificLike 5 and , this function converts a 6 to a  but instead of failing or diverging (i.e loop and consume all space) on  /https://en.wikipedia.org/wiki/Repeating_decimalrepeating decimals% it detects the repeating part, the repetend, and returns where it starts.To detect the repetition this function consumes space linear in the number of digits in the resulting scientific. In order to bound the space usage an optional limit can be specified. If the number of digits reaches this limit  Left (s, r) will be returned. Here s is the  constructed so far and r is the remaining 6. toRational s + r yields the original 66If the limit is not reached or no limit was specified Right (s, mbRepetendIx) will be returned. Here s is the  without any repetition and  mbRepetendIx specifies if and where in the fractional part the repetend begins. For example: fromRationalRepetend Nothing (1 % 28) == Right (3.571428e-2, Just 2)'This represents the repeating decimal: 0.03571428571428571428...3 which is sometimes also unambiguously denoted as  0.03(571428). Here the repetend is enclosed in parentheses and starts at the 3rd digit (index 2) in the fractional part. Specifying a limit results in the following: fromRationalRepetend (Just 4) (1 % 28) == Left (3.5e-2, 1 % 1400).You can expect the following property to hold. < forall (mbLimit :: Maybe Int) (r :: Rational). r == (case   mbLimit r of Left (s, r') -> toRational s + r' Right (s, mbRepetendIx) -> case mbRepetendIx of Nothing -> toRational s Just repetendIx ->   s repetendIx)  scientificLike   but always accepts a limit.  scientificLike   but doesn't accept a limit.  scientific Converts a  with a repetend (a repeating part in the fraction), which starts at the given index, into its corresponding 6.-For example to convert the repeating decimal  0.03(571428) you would use: )toRationalRepetend 0.03571428 2 == 1 % 28Preconditions for toRationalRepetend s r: r >= 0 r < -(base10Exponent s)WARNING: toRationalRepetend needs to compute the 7 magnitude: 10^^n. Where n is based on the  of the scientific. If applied to a huge exponent this could fill up all space and crash your program! So don't apply this function to untrusted input.The formula to convert the  Scientific s$ with a repetend starting at index r is described in the paper:  http://fiziko.bureau42.com/teaching_tidbits/turning_repeating_decimals_into_fractions.pdf-turning_repeating_decimals_into_fractions.pdf and is defined as follows:  (fromInteger nonRepetend + repetend % nines) / fromInteger (10^^r) where c = coefficient s e = base10Exponent s -- Size of the fractional part. f = (-e) -- Size of the repetend. n = f - r m = 10^^n (nonRepetend, repetend) = c `quotRem` m nines = m - 1  Also see:  .  scientific Convert a 8 (like a 9 or : ) into a  number.Note that this function uses ;, to compute the digits and exponent of the 8. number. Be aware that the algorithm used in ;9 doesn't work as expected for some numbers, e.g. as the 9 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 scientificSafely convert a  number into a 8 (like a 9 or a :).Note that this function uses < (5 . =) internally but it guards against computing huge Integer magnitudes (10^e?) that could fill up all space and crash your program. If the  of the given  is too big or too small to be represented in the target type, Infinity or 0 will be returned respectively. Use 1 which explicitly handles this case by returning >.Always prefer  over < when converting from scientific numbers coming from an untrusted source. scientificPreciser version of  . If the  of the given  is too big or too small to be represented in the target type, Infinity or 0 will be returned as >. scientific Convert a  to a bounded integer. If the given ; doesn't fit in the target representation, it will return ?.This function also guards against computing huge Integer magnitudes (10^e7) that could fill up all space and crash your program. scientificfloatingOrInteger< determines if the scientific is floating point or integer.In case it's floating-point the scientific is converted to the desired 8 using  and wrapped in >.?In case it's integer to scientific is converted to the desired @ and wrapped in A.WARNING:8 To convert the scientific to an integral the magnitude 10^e needs to be computed. If applied to a huge exponent this could take a long time. Even worse, when the destination type is unbounded (i.e. 7) it could fill up all space and crash your program! So don't apply this function to untrusted input but use  instead. Also see:  or . scientificReturn B( if the scientific is a floating point, C otherwise. Also see: . scientificReturn B" if the scientific is an integer, C otherwise. Also see: . scientific5A parser for parsing a floating-point number into a  value. Example: > import Text.ParserCombinators.ReadP (readP_to_S) > readP_to_S scientificP "3" [(3.0,"")] > readP_to_S scientificP "3.0e2" [(3.0,"e2"),(300.0,"")] > readP_to_S scientificP "+3.0e+2" [(3.0,"e+2"),(300.0,"")] > readP_to_S scientificP "-3.0e-2" [(-3.0,"e-2"),(-3.0e-2,"")]Note: This parser only parses the number itself; it does not parse any surrounding parentheses or whitespaces. scientificLike D but provides rendering options. scientific Similar to ;, toDecimalDigits takes a positive  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 /null $ takeWhile (==0) $ reverse [d1,d2,...,dn]The last property means that the coefficient will be normalized, i.e. doesn't contain trailing zeros. scientificNormalize a scientific number by dividing out powers of 10 from the  and incrementing the  each time.You should rarely have a need for this function since scientific numbers are automatically normalized when pretty-printed and in . scientificSee - if you need more control over the rendering. scientific>Supports the skipping of parentheses and whitespaces. Example: 2> read " ( (( -1.0e+3 ) ))" :: Scientific -1000.0 (Note: This Read! instance makes internal use of % to parse the floating-point number.) scientificWARNING: the methods of the RealFrac) instance need to compute the magnitude 10^e. If applied to a huge exponent this could take a long time. Even worse, when the destination type is unbounded (i.e. 75) it could fill up all space and crash your program! scientificWARNING: E and F- will throw an error when their outputs are  /https://en.wikipedia.org/wiki/Repeating_decimalrepeating decimals.These methods also compute 7 magnitudes (10^e). If these methods are applied to arguments which have huge exponents this could fill up all space and crash your program! So don't apply these methods to scientific numbers coming from untrusted sources.5$ will throw an error when the input 6* is a repeating decimal. Consider using   for these rationals which will detect the repetition and indicate where it starts. scientificWARNING: = needs to compute the 7 magnitude: 10^e. If applied to a huge exponent this could fill up all space and crash your program!Avoid applying = (or <) to scientific numbers coming from an untrusted source and use ; instead. The latter guards against excessive space usage. scientificWARNING: G and H compute the 7 magnitude: 10^e where e is the difference between the s of the arguments. If these methods are applied to arguments which have huge exponents this could fill up all space and crash your program! So don't apply these methods to scientific numbers coming from untrusted sources. The other methods can be used safely. scientificScientific numbers can be safely compared for ordering. No magnitude 10^e is calculated so there's no risk of a blowup in space or time when comparing scientific numbers coming from untrusted sources. scientificScientific numbers can be safely compared for equality. No magnitude 10^e is calculated so there's no risk of a blowup in space or time when comparing scientific numbers coming from untrusted sources.  scientific;Note that in the future I intend to change the type of the  from Int to Integer. To be forward compatible the Binary+ instance already encodes the exponent as 7.! scientific'A hash can be safely calculated from a  Scientific. No magnitude 10^e is calculated so there's no risk of a blowup in space or time when hashing scientific numbers coming from untrusted sources.import Data.Hashable (hash)let x = scientific 1 2let y = scientific 100 0(x == y, hash x == hash y) (True,True)$ scientific  scientificOptional limit  scientificlimit  scientificRepetend index scientific#Number of decimal places to render.   Safe 36% scientificA 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.& scientificLike % but provides rendering options.& scientific#Number of decimal places to render.%&%&Safe 4' scientificA  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.( scientificLike ' but provides rendering options.( scientific#Number of decimal places to render.'('(      !"#$%&'()*+,-.-./01/02/03456789:89;8<=89>?@A89B89C/0D8EF?GH?GI8EJ89K89L8MN8OP89Q8MR?GS?GT8UV89W89X8<Y8<Z)scientific-0.3.7.0-IjvAzRFEzKW4AZZ4kLP1wfData.Scientific!Data.Text.Lazy.Builder.Scientific"Data.ByteString.Builder.ScientificGHC.Integer.CompatUtils text-1.2.3.2 Data.Text.Lazy.Builder.RealFloatGenericFixedExponentFPFormat Scientific coefficientbase10Exponent scientificunsafeFromRationalfromRationalRepetendfromRationalRepetendLimitedfromRationalRepetendUnlimitedtoRationalRepetendfromFloatDigits toRealFloattoBoundedRealFloattoBoundedIntegerfloatingOrInteger isFloating isInteger scientificPformatScientifictoDecimalDigits normalize$fShowScientific$fReadScientific$fRealFracScientific$fFractionalScientific$fRealScientific$fNumScientific$fOrdScientific$fEqScientific$fBinaryScientific$fHashableScientific$fNFDataScientific$fDataScientific$fLiftLiftedRepScientificscientificBuilderformatScientificBuilderinteger-wired-inGHC.Integer.Type quotInteger divIntegerquotRemIntegeri2dmaxExpt magnituderoundTobaseGHC.RealReal FractionalGHC.Num fromInteger^^ghc-prim GHC.ClassesEq fromRationalRationalInteger GHC.Float RealFloat GHC.TypesDoubleFloat floatToDigits realToFrac toRational Data.EitherLeft GHC.MaybeNothingIntegralRightTrueFalseGHC.Showshowrecip/+-