/usr/share/doc/libghc-scientific-doc/html/Data-Scientific.html is in libghc-scientific-doc 0.3.4.4-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Data.Scientific</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Data-Scientific.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Data-Scientific.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">scientific-0.3.4.4: Numbers represented using scientific notation</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>Bas van Dijk 2013</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>Bas van Dijk <v.dijk.bas@gmail.com></td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">Data.Scientific</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Construction</a></li><li><a href="#g:2">Projections</a></li><li><a href="#g:3">Predicates</a></li><li><a href="#g:4">Conversions</a></li><li><a href="#g:5">Pretty printing</a></li><li><a href="#g:6">Normalization</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>This module provides the number type <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code>. Scientific numbers are
arbitrary precision and space efficient. They are represented using
<a href="http://en.wikipedia.org/wiki/Scientific_notation">scientific notation</a>. The
implementation uses an <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a></code> <code><a href="Data-Scientific.html#v:coefficient">coefficient</a></code> <code>c</code> and an <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></code>
<code><a href="Data-Scientific.html#v:base10Exponent">base10Exponent</a></code> <code>e</code>. A scientific number corresponds to the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Fractional">Fractional</a></code>
number: <code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromInteger">fromInteger</a></code> c * 10 <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:-94--94-">^^</a></code> e</code>.</p><p>Note that since we're using an <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></code> to represent the exponent these numbers
aren't truly arbitrary precision. I intend to change the type of the exponent
to <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a></code> in a future release.</p><p>The main application of <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> is to be used as the target of parsing
arbitrary precision numbers coming from an untrusted source. The advantages
over using <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code> for this are that:</p><ul><li>A <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> is more efficient to construct. Rational numbers need to be
constructed using <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Ratio.html#v:-37-">%</a></code> which has to compute the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:gcd">gcd</a></code> of the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Ratio.html#v:numerator">numerator</a></code> and
<code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Ratio.html#v:denominator">denominator</a></code>.</li><li><code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> is safe against numbers with huge exponents. For example:
<code>1e1000000000 :: <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code></code> will fill up all space and crash your
program. Scientific works as expected:</li></ul><pre>> read "1e1000000000" :: Scientific
1.0e1000000000</pre><ul><li>Also, the space usage of converting scientific numbers with huge exponents
to <code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integral">Integral</a></code>s</code> (like: <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></code>) or <code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a></code>s</code> (like: <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Double">Double</a></code> or <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Float">Float</a></code>)
will always be bounded by the target type.</li></ul><p><em>WARNING:</em> Although <code>Scientific</code> is an instance of <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Fractional">Fractional</a></code>, the methods
are only partially defined! Specifically <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:recip">recip</a></code> and <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:-47-">/</a></code> will diverge
(i.e. loop and consume all space) when their outputs have an infinite decimal
expansion. <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromRational">fromRational</a></code> will diverge when the input <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code> has an
infinite decimal expansion. Consider using <code><a href="Data-Scientific.html#v:fromRationalRepetend">fromRationalRepetend</a></code> for these
rationals which will detect the repetition and indicate where it starts.</p><p>This module is designed to be imported qualified:</p><pre>import Data.Scientific as Scientific</pre></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:Scientific">Scientific</a></li><li class="src short"><a href="#v:scientific">scientific</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-Scientific.html#t:Scientific">Scientific</a></li><li class="src short"><a href="#v:coefficient">coefficient</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a></li><li class="src short"><a href="#v:base10Exponent">base10Exponent</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:isFloating">isFloating</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isInteger">isInteger</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:fromRationalRepetend">fromRationalRepetend</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#t:Either">Either</a> (<a href="Data-Scientific.html#t:Scientific">Scientific</a>, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a>) (<a href="Data-Scientific.html#t:Scientific">Scientific</a>, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a>)</li><li class="src short"><a href="#v:toRationalRepetend">toRationalRepetend</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></li><li class="src short"><a href="#v:floatingOrInteger">floatingOrInteger</a> :: (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> r, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integral">Integral</a> i) => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#t:Either">Either</a> r i</li><li class="src short"><a href="#v:toRealFloat">toRealFloat</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> a => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> a</li><li class="src short"><a href="#v:toBoundedRealFloat">toBoundedRealFloat</a> :: <span class="keyword">forall</span> a. <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> a => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#t:Either">Either</a> a a</li><li class="src short"><a href="#v:toBoundedInteger">toBoundedInteger</a> :: <span class="keyword">forall</span> i. (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integral">Integral</a> i, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Bounded">Bounded</a> i) => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> i</li><li class="src short"><a href="#v:fromFloatDigits">fromFloatDigits</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> a => a -> <a href="Data-Scientific.html#t:Scientific">Scientific</a></li><li class="src short"><a href="#v:formatScientific">formatScientific</a> :: <a href="Data-Scientific.html#t:FPFormat">FPFormat</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:FPFormat">FPFormat</a> :: *<ul class="subs"><li>= <a href="#v:Exponent">Exponent</a></li><li>| <a href="#v:Fixed">Fixed</a></li><li>| <a href="#v:Generic">Generic</a></li></ul></li><li class="src short"><a href="#v:toDecimalDigits">toDecimalDigits</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> ([<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a>], <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a>)</li><li class="src short"><a href="#v:normalize">normalize</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="Data-Scientific.html#t:Scientific">Scientific</a></li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Scientific" class="def">Scientific</a> <a href="src/Data-Scientific.html#Scientific" class="link">Source</a></p><div class="doc"><p>An arbitrary-precision number represented using
<a href="http://en.wikipedia.org/wiki/Scientific_notation">scientific notation</a>.</p><p>This type describes the set of all <code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Real">Real</a></code>s</code> which have a finite
decimal expansion.</p><p>A scientific number with <code><a href="Data-Scientific.html#v:coefficient">coefficient</a></code> <code>c</code> and <code><a href="Data-Scientific.html#v:base10Exponent">base10Exponent</a></code> <code>e</code>
corresponds to the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Fractional">Fractional</a></code> number: <code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromInteger">fromInteger</a></code> c * 10 <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:-94--94-">^^</a></code> e</code></p></div><div class="subs instances"><p id="control.i:Scientific" class="caption collapser" onclick="toggleSection('i:Scientific')">Instances</p><div id="section.i:Scientific" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Eq.html#t:Eq">Eq</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-185" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Fractional">Fractional</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-268" class="link">Source</a></td><td class="doc"><p><em>WARNING:</em> <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:recip">recip</a></code> and <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:-47-">/</a></code> will diverge (i.e. loop and consume all space)
when their outputs are <a href="https://en.wikipedia.org/wiki/Repeating_decimal">repeating decimals</a>.</p><p><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromRational">fromRational</a></code> will diverge when the input <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code> is a repeating decimal.
Consider using <code><a href="Data-Scientific.html#v:fromRationalRepetend">fromRationalRepetend</a></code> for these rationals which will detect
the repetition and indicate where it starts.</p></td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Data.html#t:Data">Data</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-157" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Num">Num</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-208" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Ord.html#t:Ord">Ord</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-192" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Text-Read.html#t:Read">Read</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-758" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Real">Real</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-248" class="link">Source</a></td><td class="doc"><p><em>WARNING:</em> <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:toRational">toRational</a></code> needs to compute the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a></code> magnitude:
<code>10^e</code>. If applied to a huge exponent this could fill up all space
and crash your program!</p><p>Avoid applying <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:toRational">toRational</a></code> (or <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:realToFrac">realToFrac</a></code>) to scientific numbers
coming from an untrusted source and use <code><a href="Data-Scientific.html#v:toRealFloat">toRealFloat</a></code> instead. The
latter guards against excessive space usage.</p></td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFrac">RealFrac</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-439" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Text-Show.html#t:Show">Show</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-829" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/binary-0.7.5.0/Data-Binary.html#t:Binary">Binary</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-175" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/deepseq-1.4.1.1/Control-DeepSeq.html#t:NFData">NFData</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-169" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/libghc-hashable-doc/html/Data-Hashable.html#t:Hashable">Hashable</a> <a href="Data-Scientific.html#t:Scientific">Scientific</a></span> <a href="src/Data-Scientific.html#line-172" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:1">Construction</h1><div class="top"><p class="src"><a name="v:scientific" class="def">scientific</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-Scientific.html#t:Scientific">Scientific</a> <a href="src/Data-Scientific.html#scientific" class="link">Source</a></p><div class="doc"><p><code>scientific c e</code> constructs a scientific number which corresponds
to the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Fractional">Fractional</a></code> number: <code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromInteger">fromInteger</a></code> c * 10 <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:-94--94-">^^</a></code> e</code>.</p></div></div><h1 id="g:2">Projections</h1><div class="top"><p class="src"><a name="v:coefficient" class="def">coefficient</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integer">Integer</a> <a href="src/Data-Scientific.html#coefficient" class="link">Source</a></p><div class="doc"><p>The coefficient of a scientific number.</p><p>Note that this number is not necessarily normalized, i.e.
it could contain trailing zeros.</p><p>Scientific numbers are automatically normalized when pretty printed or
in <code><a href="Data-Scientific.html#v:toDecimalDigits">toDecimalDigits</a></code>.</p><p>Use <code><a href="Data-Scientific.html#v:normalize">normalize</a></code> to do manual normalization.</p></div></div><div class="top"><p class="src"><a name="v:base10Exponent" class="def">base10Exponent</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a> <a href="src/Data-Scientific.html#base10Exponent" class="link">Source</a></p><div class="doc"><p>The base-10 exponent of a scientific number.</p></div></div><h1 id="g:3">Predicates</h1><div class="top"><p class="src"><a name="v:isFloating" class="def">isFloating</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#t:Bool">Bool</a> <a href="src/Data-Scientific.html#isFloating" class="link">Source</a></p><div class="doc"><p>Return <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#v:True">True</a></code> if the scientific is a floating point, <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#v:False">False</a></code> otherwise.</p><p>Also see: <code><a href="Data-Scientific.html#v:floatingOrInteger">floatingOrInteger</a></code>.</p></div></div><div class="top"><p class="src"><a name="v:isInteger" class="def">isInteger</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#t:Bool">Bool</a> <a href="src/Data-Scientific.html#isInteger" class="link">Source</a></p><div class="doc"><p>Return <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#v:True">True</a></code> if the scientific is an integer, <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Bool.html#v:False">False</a></code> otherwise.</p><p>Also see: <code><a href="Data-Scientific.html#v:floatingOrInteger">floatingOrInteger</a></code>.</p></div></div><h1 id="g:4">Conversions</h1><div class="top"><p class="src"><a name="v:fromRationalRepetend" class="def">fromRationalRepetend</a> <a href="src/Data-Scientific.html#fromRationalRepetend" class="link">Source</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Optional limit</p></td></tr><tr><td class="src">-> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#t:Either">Either</a> (<a href="Data-Scientific.html#t:Scientific">Scientific</a>, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a>) (<a href="Data-Scientific.html#t:Scientific">Scientific</a>, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a>)</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Like <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromRational">fromRational</a></code>, this function converts a <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code> to a <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code>
but instead of diverging (i.e loop and consume all space) on
<a href="https://en.wikipedia.org/wiki/Repeating_decimal">repeating decimals</a>
it detects the repeating part, the <em>repetend</em>, and returns where it starts.</p><p>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
<code>Left (s, r)</code> will be returned. Here <code>s</code> is the <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> constructed so
far and <code>r</code> is the remaining <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code>. <code>toRational s + r</code> yields the
original <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code></p><p>If the limit is not reached or no limit was specified <code>Right (s,
mbRepetendIx)</code> will be returned. Here <code>s</code> is the <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> without any
repetition and <code>mbRepetendIx</code> specifies if and where in the fractional part
the repetend begins.</p><p>For example:</p><pre>fromRationalRepetend Nothing (1 % 28) == Right (3.571428e-2, Just 2)</pre><p>This represents the repeating decimal: <code>0.03571428571428571428...</code>
which is sometimes also unambiguously denoted as <code>0.03(571428)</code>.
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:</p><pre>fromRationalRepetend (Just 4) (1 % 28) == Left (3.5e-2, 1 % 1400)</pre><p>You can expect the following property to hold.</p><pre> forall (mbLimit :: Maybe Int) (r :: Rational).
r == (case <code><a href="Data-Scientific.html#v:fromRationalRepetend">fromRationalRepetend</a></code> mbLimit r of
Left (s, r') -> toRational s + r'
Right (s, mbRepetendIx) ->
case mbRepetendIx of
Nothing -> toRational s
Just repetendIx -> <code><a href="Data-Scientific.html#v:toRationalRepetend">toRationalRepetend</a></code> s repetendIx)
</pre></div></div><div class="top"><p class="src"><a name="v:toRationalRepetend" class="def">toRationalRepetend</a> <a href="src/Data-Scientific.html#toRationalRepetend" class="link">Source</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Data-Scientific.html#t:Scientific">Scientific</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Repetend index</p></td></tr><tr><td class="src">-> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Converts a <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> with a <em>repetend</em> (a repeating part in the fraction),
which starts at the given index, into its corresponding <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Rational">Rational</a></code>.</p><p>For example to convert the repeating decimal <code>0.03(571428)</code> you would use:
<code>toRationalRepetend 0.03571428 2 == 1 % 28</code></p><p>Preconditions for <code>toRationalRepetend s r</code>:</p><ul><li><pre>r >= 0</pre></li><li><pre>r < -(base10Exponent s)</pre></li></ul><p>The formula to convert the <code>Scientific</code> <code>s</code>
with a repetend starting at index <code>r</code> is described in the paper:
<a href="http://fiziko.bureau42.com/teaching_tidbits/turning_repeating_decimals_into_fractions.pdf">turning_repeating_decimals_into_fractions.pdf</a>
and is defined as follows:</p><pre> (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
</pre><p>Also see: <code><a href="Data-Scientific.html#v:fromRationalRepetend">fromRationalRepetend</a></code>.</p></div></div><div class="top"><p class="src"><a name="v:floatingOrInteger" class="def">floatingOrInteger</a> :: (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> r, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integral">Integral</a> i) => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#t:Either">Either</a> r i <a href="src/Data-Scientific.html#floatingOrInteger" class="link">Source</a></p><div class="doc"><p><code>floatingOrInteger</code> determines if the scientific is floating point
or integer. In case it's floating-point the scientific is converted
to the desired <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a></code> using <code><a href="Data-Scientific.html#v:toRealFloat">toRealFloat</a></code>.</p><p>Also see: <code><a href="Data-Scientific.html#v:isFloating">isFloating</a></code> or <code><a href="Data-Scientific.html#v:isInteger">isInteger</a></code>.</p></div></div><div class="top"><p class="src"><a name="v:toRealFloat" class="def">toRealFloat</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> a => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> a <a href="src/Data-Scientific.html#toRealFloat" class="link">Source</a></p><div class="doc"><p>Safely convert a <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> number into a <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a></code> (like a <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Double">Double</a></code> or a
<code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Float">Float</a></code>).</p><p>Note that this function uses <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:realToFrac">realToFrac</a></code> (<code><code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:fromRational">fromRational</a></code> . <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:toRational">toRational</a></code></code>)
internally but it guards against computing huge Integer magnitudes (<code>10^e</code>)
that could fill up all space and crash your program. If the <code><a href="Data-Scientific.html#v:base10Exponent">base10Exponent</a></code>
of the given <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> is too big or too small to be represented in the
target type, Infinity or 0 will be returned respectively. Use
<code><a href="Data-Scientific.html#v:toBoundedRealFloat">toBoundedRealFloat</a></code> which explicitly handles this case by returning <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#v:Left">Left</a></code>.</p><p>Always prefer <code><a href="Data-Scientific.html#v:toRealFloat">toRealFloat</a></code> over <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#v:realToFrac">realToFrac</a></code> when converting from scientific
numbers coming from an untrusted source.</p></div></div><div class="top"><p class="src"><a name="v:toBoundedRealFloat" class="def">toBoundedRealFloat</a> :: <span class="keyword">forall</span> a. <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> a => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#t:Either">Either</a> a a <a href="src/Data-Scientific.html#toBoundedRealFloat" class="link">Source</a></p><div class="doc"><p>Preciser version of <code><a href="Data-Scientific.html#v:toRealFloat">toRealFloat</a></code>. If the <code><a href="Data-Scientific.html#v:base10Exponent">base10Exponent</a></code> of the given
<code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> is too big or too small to be represented in the target type,
Infinity or 0 will be returned as <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Either.html#v:Left">Left</a></code>.</p></div></div><div class="top"><p class="src"><a name="v:toBoundedInteger" class="def">toBoundedInteger</a> :: <span class="keyword">forall</span> i. (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Integral">Integral</a> i, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Bounded">Bounded</a> i) => <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> i <a href="src/Data-Scientific.html#toBoundedInteger" class="link">Source</a></p><div class="doc"><p>Convert a <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> to a bounded integer.</p><p>If the given <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> doesn't fit in the target representation, it will
return <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#v:Nothing">Nothing</a></code>.</p><p>This function also guards against computing huge Integer magnitudes (<code>10^e</code>)
that could fill up all space and crash your program.</p></div></div><div class="top"><p class="src"><a name="v:fromFloatDigits" class="def">fromFloatDigits</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a> a => a -> <a href="Data-Scientific.html#t:Scientific">Scientific</a> <a href="src/Data-Scientific.html#fromFloatDigits" class="link">Source</a></p><div class="doc"><p>Convert a <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a></code> (like a <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Double">Double</a></code> or <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Float">Float</a></code>) into a <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code>
number.</p><p>Note that this function uses <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Numeric.html#v:floatToDigits">floatToDigits</a></code> to compute the digits
and exponent of the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:RealFloat">RealFloat</a></code> number. Be aware that the algorithm used in
<code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Numeric.html#v:floatToDigits">floatToDigits</a></code> doesn't work as expected for some numbers, e.g. as
the <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Double">Double</a></code> <code>1e23</code> is converted to <code>9.9999999999999991611392e22</code>, and that
value is shown as <code>9.999999999999999e22</code> rather than the shorter <code>1e23</code>; 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 <code>5^23*2^e</code> for <code>e</code> close to 23, the
algorithm doesn't know in which direction the short decimal representation
would be rounded and computes more digits</p></div></div><h1 id="g:5">Pretty printing</h1><div class="top"><p class="src"><a name="v:formatScientific" class="def">formatScientific</a> <a href="src/Data-Scientific.html#formatScientific" class="link">Source</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Data-Scientific.html#t:FPFormat">FPFormat</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Number of decimal places to render.</p></td></tr><tr><td class="src">-> <a href="Data-Scientific.html#t:Scientific">Scientific</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-String.html#t:String">String</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Like <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Text-Show.html#v:show">show</a></code> but provides rendering options.</p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:FPFormat" class="def">FPFormat</a> :: *</p><div class="doc"><p>Control the rendering of floating point numbers.</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Exponent" class="def">Exponent</a></td><td class="doc"><p>Scientific notation (e.g. <code>2.3e123</code>).</p></td></tr><tr><td class="src"><a name="v:Fixed" class="def">Fixed</a></td><td class="doc"><p>Standard decimal notation.</p></td></tr><tr><td class="src"><a name="v:Generic" class="def">Generic</a></td><td class="doc"><p>Use decimal notation for values between <code>0.1</code> and
<code>9,999,999</code>, and scientific notation otherwise.</p></td></tr></table></div><div class="subs instances"><p id="control.i:FPFormat" class="caption collapser" onclick="toggleSection('i:FPFormat')">Instances</p><div id="section.i:FPFormat" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Prelude.html#t:Enum">Enum</a> <a href="Data-Scientific.html#t:FPFormat">FPFormat</a></span></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Text-Read.html#t:Read">Read</a> <a href="Data-Scientific.html#t:FPFormat">FPFormat</a></span></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Text-Show.html#t:Show">Show</a> <a href="Data-Scientific.html#t:FPFormat">FPFormat</a></span></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:toDecimalDigits" class="def">toDecimalDigits</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> ([<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a>], <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Data-Int.html#t:Int">Int</a>) <a href="src/Data-Scientific.html#toDecimalDigits" class="link">Source</a></p><div class="doc"><p>Similar to <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.8.2.0/Numeric.html#v:floatToDigits">floatToDigits</a></code>, <code>toDecimalDigits</code> takes a
positive <code><a href="Data-Scientific.html#t:Scientific">Scientific</a></code> number, and returns a list of digits and
a base-10 exponent. In particular, if <code>x>=0</code>, and</p><pre>toDecimalDigits x = ([d1,d2,...,dn], e)</pre><p>then</p><ol><li><pre>n >= 1</pre></li><li><pre>x = 0.d1d2...dn * (10^^e)</pre></li><li><pre>0 <= di <= 9</pre></li><li><pre>null $ takeWhile (==0) $ reverse [d1,d2,...,dn]</pre></li></ol><p>The last property means that the coefficient will be normalized, i.e. doesn't
contain trailing zeros.</p></div></div><h1 id="g:6">Normalization</h1><div class="top"><p class="src"><a name="v:normalize" class="def">normalize</a> :: <a href="Data-Scientific.html#t:Scientific">Scientific</a> -> <a href="Data-Scientific.html#t:Scientific">Scientific</a> <a href="src/Data-Scientific.html#normalize" class="link">Source</a></p><div class="doc"><p>Normalize a scientific number by dividing out powers of 10 from the
<code><a href="Data-Scientific.html#v:coefficient">coefficient</a></code> and incrementing the <code><a href="Data-Scientific.html#v:base10Exponent">base10Exponent</a></code> each time.</p><p>You should rarely have a need for this function since scientific numbers are
automatically normalized when pretty-printed and in <code><a href="Data-Scientific.html#v:toDecimalDigits">toDecimalDigits</a></code>.</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.1</p></div></body></html>
|