<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>MLtonIntInf</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>MLtonIntInf</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">signature</span><span class="w"> </span><span class="n">MLTON_INT_INF</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">IntInf</span><span class="p">.</span><span class="n">int</span><span class="w"></span>

<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">areSmall</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">gcd</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">isSmall</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>

<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">BigWord</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">WORD</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">SmallInt</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">INTEGER</span><span class="w"></span>
<span class="w">      </span><span class="k">datatype</span><span class="w"> </span><span class="n">rep</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">         </span><span class="n">Big</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">BigWord</span><span class="p">.</span><span class="n">word</span><span class="w"> </span><span class="n">vector</span><span class="w"></span>
<span class="w">       </span><span class="p">|</span><span class="w"> </span><span class="n">Small</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">SmallInt</span><span class="p">.</span><span class="n">int</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">rep</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">rep</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">fromRep</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">rep</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>MLton represents an arbitrary precision integer either as an unboxed
word with the bottom bit set to 1 and the top bits representing a
small signed integer, or as a pointer to a vector of words, where the
first word indicates the sign and the rest are the limbs of a
<a href="GnuMP">GnuMP</a> big integer.</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">type t</span>
</p>
<div class="paragraph"><p>the same as type <span class="monospaced">IntInf.int</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">areSmall (a, b)</span>
</p>
<div class="paragraph"><p>returns true iff both <span class="monospaced">a</span> and <span class="monospaced">b</span> are small.</p></div>
</li>
<li>
<p>
<span class="monospaced">gcd (a, b)</span>
</p>
<div class="paragraph"><p>uses the <a href="GnuMP">GnuMP&#8217;s</a> fast gcd implementation.</p></div>
</li>
<li>
<p>
<span class="monospaced">isSmall a</span>
</p>
<div class="paragraph"><p>returns true iff <span class="monospaced">a</span> is small.</p></div>
</li>
<li>
<p>
<span class="monospaced">BigWord : WORD</span>
</p>
<div class="paragraph"><p>representation of a big <span class="monospaced">IntInf.int</span> as a vector of words; on 32-bit
platforms, <span class="monospaced">BigWord</span> is likely to be equivalent to <span class="monospaced">Word32</span>, and on
64-bit platforms, <span class="monospaced">BigWord</span> is likely to be equivalent to <span class="monospaced">Word64</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">SmallInt : INTEGER</span>
</p>
<div class="paragraph"><p>representation of a small <span class="monospaced">IntInf.int</span> as a signed integer; on 32-bit
platforms, <span class="monospaced">SmallInt</span> is likely to be equivalent to <span class="monospaced">Int32</span>, and on
64-bit platforms, <span class="monospaced">SmallInt</span> is likely to be equivalent to <span class="monospaced">Int64</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">datatype rep</span>
</p>
<div class="paragraph"><p>the underlying representation of an <span class="monospaced">IntInf.int</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">rep i</span>
</p>
<div class="paragraph"><p>returns the underlying representation of <span class="monospaced">i</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">fromRep r</span>
</p>
<div class="paragraph"><p>converts from the underlying representation back to <span class="monospaced">i</span>.  If the input
is not identical to the result of <span class="monospaced">rep</span>, the result is undefined.</p></div>
</li>
</ul></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
