<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Nativeint.html"> <link rel="next" href="Obj.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Arg" rel="Chapter" href="Arg.html"> <link title="Arith_status" rel="Chapter" href="Arith_status.html"> <link title="Array" rel="Chapter" href="Array.html"> <link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html"> <link title="Big_int" rel="Chapter" href="Big_int.html"> <link title="Bigarray" rel="Chapter" href="Bigarray.html"> <link title="Buffer" rel="Chapter" href="Buffer.html"> <link title="Callback" rel="Chapter" href="Callback.html"> <link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html"> <link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html"> <link title="Char" rel="Chapter" href="Char.html"> <link title="Complex" rel="Chapter" href="Complex.html"> <link title="Condition" rel="Chapter" href="Condition.html"> <link title="Dbm" rel="Chapter" href="Dbm.html"> <link title="Digest" rel="Chapter" href="Digest.html"> <link title="Dynlink" rel="Chapter" href="Dynlink.html"> <link title="Event" rel="Chapter" href="Event.html"> <link title="Filename" rel="Chapter" href="Filename.html"> <link title="Format" rel="Chapter" href="Format.html"> <link title="Gc" rel="Chapter" href="Gc.html"> <link title="Genlex" rel="Chapter" href="Genlex.html"> <link title="Graphics" rel="Chapter" href="Graphics.html"> <link title="GraphicsX11" rel="Chapter" href="GraphicsX11.html"> <link title="Hashtbl" rel="Chapter" href="Hashtbl.html"> <link title="Int32" rel="Chapter" href="Int32.html"> <link title="Int64" rel="Chapter" href="Int64.html"> <link title="Lazy" rel="Chapter" href="Lazy.html"> <link title="Lexing" rel="Chapter" href="Lexing.html"> <link title="List" rel="Chapter" href="List.html"> <link title="ListLabels" rel="Chapter" href="ListLabels.html"> <link title="Map" rel="Chapter" href="Map.html"> <link title="Marshal" rel="Chapter" href="Marshal.html"> <link title="MoreLabels" rel="Chapter" href="MoreLabels.html"> <link title="Mutex" rel="Chapter" href="Mutex.html"> <link title="Nativeint" rel="Chapter" href="Nativeint.html"> <link title="Num" rel="Chapter" href="Num.html"> <link title="Obj" rel="Chapter" href="Obj.html"> <link title="Oo" rel="Chapter" href="Oo.html"> <link title="Parsing" rel="Chapter" href="Parsing.html"> <link title="Pervasives" rel="Chapter" href="Pervasives.html"> <link title="Printexc" rel="Chapter" href="Printexc.html"> <link title="Printf" rel="Chapter" href="Printf.html"> <link title="Queue" rel="Chapter" href="Queue.html"> <link title="Random" rel="Chapter" href="Random.html"> <link title="Scanf" rel="Chapter" href="Scanf.html"> <link title="Set" rel="Chapter" href="Set.html"> <link title="Sort" rel="Chapter" href="Sort.html"> <link title="Stack" rel="Chapter" href="Stack.html"> <link title="StdLabels" rel="Chapter" href="StdLabels.html"> <link title="Str" rel="Chapter" href="Str.html"> <link title="Stream" rel="Chapter" href="Stream.html"> <link title="String" rel="Chapter" href="String.html"> <link title="StringLabels" rel="Chapter" href="StringLabels.html"> <link title="Sys" rel="Chapter" href="Sys.html"> <link title="Thread" rel="Chapter" href="Thread.html"> <link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html"> <link title="Tk" rel="Chapter" href="Tk.html"> <link title="Unix" rel="Chapter" href="Unix.html"> <link title="UnixLabels" rel="Chapter" href="UnixLabels.html"> <link title="Weak" rel="Chapter" href="Weak.html"><link title="Arithmetic operations" rel="Section" href="#6_Arithmeticoperations"> <link title="Coercions with strings" rel="Section" href="#6_Coercionswithstrings"> <link title="Coercions between numerical types" rel="Section" href="#6_Coercionsbetweennumericaltypes"> <link title="Comparisons between numbers" rel="Subsection" href="#7_Comparisonsbetweennumbers"> <title>Num</title> </head> <body> <div class="navbar"><a href="Nativeint.html">Previous</a> <a href="index.html">Up</a> <a href="Obj.html">Next</a> </div> <center><h1>Module <a href="type_Num.html">Num</a></h1></center> <br> <pre><span class="keyword">module</span> Num: <code class="code"><span class="keyword">sig</span></code> <a href="Num.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>Operation on arbitrary-precision numbers. <p> Numbers (type <code class="code">num</code>) are arbitrary-precision rational numbers, plus the special elements <code class="code">1/0</code> (infinity) and <code class="code">0/0</code> (undefined).<br> <hr width="100%"> <br><code><span class="keyword">type</span> <a name="TYPEnum"></a><code class="type"></code>num = </code><table class="typetable"> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Int</span> <span class="keyword">of</span> <code class="type">int</code></code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Big_int</span> <span class="keyword">of</span> <code class="type"><a href="Big_int.html#TYPEbig_int">Big_int.big_int</a></code></code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Ratio</span> <span class="keyword">of</span> <code class="type">Ratio.ratio</code></code></td> </tr></table> <div class="info"> The type of numbers.<br> </div> <br> <a name="6_Arithmeticoperations"></a> <h6>Arithmetic operations</h6><br> <pre><span class="keyword">val</span> <a name="VAL(+/)"></a>(+/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Same as <a href="Num.html#VALadd_num"><code class="code"><span class="constructor">Num</span>.add_num</code></a>.<br> </div> <pre><span class="keyword">val</span> <a name="VALadd_num"></a>add_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Addition<br> </div> <pre><span class="keyword">val</span> <a name="VALminus_num"></a>minus_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Unary negation.<br> </div> <pre><span class="keyword">val</span> <a name="VAL(-/)"></a>(-/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Same as <a href="Num.html#VALsub_num"><code class="code"><span class="constructor">Num</span>.sub_num</code></a>.<br> </div> <pre><span class="keyword">val</span> <a name="VALsub_num"></a>sub_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Subtraction<br> </div> <pre><span class="keyword">val</span> <a name="VAL(*/)"></a>(*/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Same as <a href="Num.html#VALmult_num"><code class="code"><span class="constructor">Num</span>.mult_num</code></a>.<br> </div> <pre><span class="keyword">val</span> <a name="VALmult_num"></a>mult_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Multiplication<br> </div> <pre><span class="keyword">val</span> <a name="VALsquare_num"></a>square_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Squaring<br> </div> <pre><span class="keyword">val</span> <a name="VAL(//)"></a>(//) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Same as <a href="Num.html#VALdiv_num"><code class="code"><span class="constructor">Num</span>.div_num</code></a>.<br> </div> <pre><span class="keyword">val</span> <a name="VALdiv_num"></a>div_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Division<br> </div> <pre><span class="keyword">val</span> <a name="VALquo_num"></a>quo_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Euclidean division: quotient.<br> </div> <pre><span class="keyword">val</span> <a name="VALmod_num"></a>mod_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Euclidean division: remainder.<br> </div> <pre><span class="keyword">val</span> <a name="VAL(**/)"></a>(**/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Same as <a href="Num.html#VALpower_num"><code class="code"><span class="constructor">Num</span>.power_num</code></a>.<br> </div> <pre><span class="keyword">val</span> <a name="VALpower_num"></a>power_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Exponentiation<br> </div> <pre><span class="keyword">val</span> <a name="VALabs_num"></a>abs_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Absolute value.<br> </div> <pre><span class="keyword">val</span> <a name="VALsucc_num"></a>succ_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> <code class="code">succ n</code> is <code class="code">n+1</code><br> </div> <pre><span class="keyword">val</span> <a name="VALpred_num"></a>pred_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> <code class="code">pred n</code> is <code class="code">n-1</code><br> </div> <pre><span class="keyword">val</span> <a name="VALincr_num"></a>incr_num : <code class="type"><a href="Num.html#TYPEnum">num</a> <a href="Pervasives.html#TYPEref">ref</a> -> unit</code></pre><div class="info"> <code class="code">incr r</code> is <code class="code">r:=!r+1</code>, where <code class="code">r</code> is a reference to a number.<br> </div> <pre><span class="keyword">val</span> <a name="VALdecr_num"></a>decr_num : <code class="type"><a href="Num.html#TYPEnum">num</a> <a href="Pervasives.html#TYPEref">ref</a> -> unit</code></pre><div class="info"> <code class="code">decr r</code> is <code class="code">r:=!r-1</code>, where <code class="code">r</code> is a reference to a number.<br> </div> <pre><span class="keyword">val</span> <a name="VALis_integer_num"></a>is_integer_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> bool</code></pre><div class="info"> Test if a number is an integer<br> </div> <br> The four following functions approximate a number by an integer :<br> <pre><span class="keyword">val</span> <a name="VALinteger_num"></a>integer_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> <code class="code">integer_num n</code> returns the integer closest to <code class="code">n</code>. In case of ties, rounds towards zero.<br> </div> <pre><span class="keyword">val</span> <a name="VALfloor_num"></a>floor_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> <code class="code">floor_num n</code> returns the largest integer smaller or equal to <code class="code">n</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALround_num"></a>round_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> <code class="code">round_num n</code> returns the integer closest to <code class="code">n</code>. In case of ties, rounds off zero.<br> </div> <pre><span class="keyword">val</span> <a name="VALceiling_num"></a>ceiling_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> <code class="code">ceiling_num n</code> returns the smallest integer bigger or equal to <code class="code">n</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALsign_num"></a>sign_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> int</code></pre><div class="info"> Return <code class="code">-1</code>, <code class="code">0</code> or <code class="code">1</code> according to the sign of the argument.<br> </div> <br> <a name="7_Comparisonsbetweennumbers"></a> <div class="h7">Comparisons between numbers</div><br> <pre><span class="keyword">val</span> <a name="VAL(=/)"></a>(=/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VAL(</)"></a>(</) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VAL(>/)"></a>(>/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VAL(<=/)"></a>(<=/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VAL(>=/)"></a>(>=/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VAL(<>/)"></a>(<>/) : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VALeq_num"></a>eq_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VALlt_num"></a>lt_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VALle_num"></a>le_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VALgt_num"></a>gt_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VALge_num"></a>ge_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> bool</code></pre><pre><span class="keyword">val</span> <a name="VALcompare_num"></a>compare_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> int</code></pre><div class="info"> Return <code class="code">-1</code>, <code class="code">0</code> or <code class="code">1</code> if the first argument is less than, equal to, or greater than the second argument.<br> </div> <pre><span class="keyword">val</span> <a name="VALmax_num"></a>max_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Return the greater of the two arguments.<br> </div> <pre><span class="keyword">val</span> <a name="VALmin_num"></a>min_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Return the smaller of the two arguments.<br> </div> <br> <a name="6_Coercionswithstrings"></a> <h6>Coercions with strings</h6><br> <pre><span class="keyword">val</span> <a name="VALstring_of_num"></a>string_of_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> string</code></pre><div class="info"> Convert a number to a string, using fractional notation.<br> </div> <pre><span class="keyword">val</span> <a name="VALapprox_num_fix"></a>approx_num_fix : <code class="type">int -> <a href="Num.html#TYPEnum">num</a> -> string</code></pre><div class="info"> See <a href="Num.html#VALapprox_num_exp"><code class="code"><span class="constructor">Num</span>.approx_num_exp</code></a>.<br> </div> <pre><span class="keyword">val</span> <a name="VALapprox_num_exp"></a>approx_num_exp : <code class="type">int -> <a href="Num.html#TYPEnum">num</a> -> string</code></pre><div class="info"> Approximate a number by a decimal. The first argument is the required precision. The second argument is the number to approximate. <a href="Num.html#VALapprox_num_fix"><code class="code"><span class="constructor">Num</span>.approx_num_fix</code></a> uses decimal notation; the first argument is the number of digits after the decimal point. <code class="code">approx_num_exp</code> uses scientific (exponential) notation; the first argument is the number of digits in the mantissa.<br> </div> <pre><span class="keyword">val</span> <a name="VALnum_of_string"></a>num_of_string : <code class="type">string -> <a href="Num.html#TYPEnum">num</a></code></pre><div class="info"> Convert a string to a number.<br> </div> <br> <a name="6_Coercionsbetweennumericaltypes"></a> <h6>Coercions between numerical types</h6><br> <pre><span class="keyword">val</span> <a name="VALint_of_num"></a>int_of_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> int</code></pre><pre><span class="keyword">val</span> <a name="VALnum_of_int"></a>num_of_int : <code class="type">int -> <a href="Num.html#TYPEnum">num</a></code></pre><pre><span class="keyword">val</span> <a name="VALnat_of_num"></a>nat_of_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> Nat.nat</code></pre><pre><span class="keyword">val</span> <a name="VALnum_of_nat"></a>num_of_nat : <code class="type">Nat.nat -> <a href="Num.html#TYPEnum">num</a></code></pre><pre><span class="keyword">val</span> <a name="VALnum_of_big_int"></a>num_of_big_int : <code class="type"><a href="Big_int.html#TYPEbig_int">Big_int.big_int</a> -> <a href="Num.html#TYPEnum">num</a></code></pre><pre><span class="keyword">val</span> <a name="VALbig_int_of_num"></a>big_int_of_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> <a href="Big_int.html#TYPEbig_int">Big_int.big_int</a></code></pre><pre><span class="keyword">val</span> <a name="VALratio_of_num"></a>ratio_of_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> Ratio.ratio</code></pre><pre><span class="keyword">val</span> <a name="VALnum_of_ratio"></a>num_of_ratio : <code class="type">Ratio.ratio -> <a href="Num.html#TYPEnum">num</a></code></pre><pre><span class="keyword">val</span> <a name="VALfloat_of_num"></a>float_of_num : <code class="type"><a href="Num.html#TYPEnum">num</a> -> float</code></pre></body></html>