<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.9">
<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></span><span class="kr">signature</span> <span class="nn">MLTON_INT_INF</span> <span class="p">=</span>
   <span class="kr">sig</span>
      <span class="kr">type</span> <span class="kt">t</span> <span class="p">=</span> <span class="nn">IntInf</span><span class="p">.</span><span class="n">int</span>

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

      <span class="kr">structure</span> <span class="nn">BigWord</span> <span class="p">:</span> <span class="n">WORD</span>
      <span class="kr">structure</span> <span class="nn">SmallInt</span> <span class="p">:</span> <span class="n">INTEGER</span>
      <span class="kr">datatype</span> <span class="kt">rep</span> <span class="p">=</span>
         <span class="nc">Big</span> <span class="kr">of</span> <span class="nn">BigWord</span><span class="p">.</span><span class="n">word</span> <span class="n">vector</span>
       <span class="p">|</span> <span class="nc">Small</span> <span class="kr">of</span> <span class="nn">SmallInt</span><span class="p">.</span><span class="n">int</span>
      <span class="kr">val</span> <span class="nv">rep</span><span class="p">:</span> <span class="n">t</span> <span class="p">-&gt;</span> <span class="n">rep</span>
      <span class="kr">val</span> <span class="nv">fromRep</span> <span class="p">:</span> <span class="n">rep</span> <span class="p">-&gt;</span> <span class="n">t</span>
   <span class="kr">end</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>
