mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-16 15:56:21 -05:00
3 lines
No EOL
20 KiB
HTML
3 lines
No EOL
20 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Targetint (ocaml.Targetint)</title><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> – <a href="../index.html">ocaml</a> » Targetint</nav><header class="odoc-preamble"><h1>Module <code><span>Targetint</span></code></h1><p>Target processor-native integers.</p><p>This module provides operations on the type of signed 32-bit integers (on 32-bit target platforms) or signed 64-bit integers (on 64-bit target platforms). This integer type has exactly the same width as that of a pointer type in the C compiler. All arithmetic operations over are taken modulo 2<sup>32</sup> or 2<sup>64</sup> depending on the word size of the target architecture.</p><p><b>Warning:</b> this module is unstable and part of <span class="xref-unresolved">compiler-libs</span>.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span></code></div><div class="spec-doc"><p>The type of target integers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-zero"><a href="#val-zero" class="anchor"></a><code><span><span class="keyword">val</span> zero : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The target integer 0.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-one"><a href="#val-one" class="anchor"></a><code><span><span class="keyword">val</span> one : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The target integer 1.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-minus_one"><a href="#val-minus_one" class="anchor"></a><code><span><span class="keyword">val</span> minus_one : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The target integer -1.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-neg"><a href="#val-neg" class="anchor"></a><code><span><span class="keyword">val</span> neg : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Unary negation.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add"><a href="#val-add" class="anchor"></a><code><span><span class="keyword">val</span> add : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Addition.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-sub"><a href="#val-sub" class="anchor"></a><code><span><span class="keyword">val</span> sub : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Subtraction.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mul"><a href="#val-mul" class="anchor"></a><code><span><span class="keyword">val</span> mul : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Multiplication.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-div"><a href="#val-div" class="anchor"></a><code><span><span class="keyword">val</span> div : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Integer division. Raise <code>Division_by_zero</code> if the second argument is zero. This division rounds the real quotient of its arguments towards zero, as specified for <a href="../Stdlib/index.html#val-(/)"><code>Stdlib.(/)</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-unsigned_div"><a href="#val-unsigned_div" class="anchor"></a><code><span><span class="keyword">val</span> unsigned_div : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Same as <a href="#val-div"><code>div</code></a>, except that arguments and result are interpreted as <em>unsigned</em> integers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rem"><a href="#val-rem" class="anchor"></a><code><span><span class="keyword">val</span> rem : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Integer remainder. If <code>y</code> is not zero, the result of <code>Targetint.rem x y</code> satisfies the following properties: <code>Targetint.zero <= Nativeint.rem x y < Targetint.abs y</code> and <code>x = Targetint.add (Targetint.mul (Targetint.div x y) y)
|
||
(Targetint.rem x y)</code>. If <code>y = 0</code>, <code>Targetint.rem x y</code> raises <code>Division_by_zero</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-unsigned_rem"><a href="#val-unsigned_rem" class="anchor"></a><code><span><span class="keyword">val</span> unsigned_rem : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Same as <a href="#val-rem"><code>rem</code></a>, except that arguments and result are interpreted as <em>unsigned</em> integers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-succ"><a href="#val-succ" class="anchor"></a><code><span><span class="keyword">val</span> succ : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Successor. <code>Targetint.succ x</code> is <code>Targetint.add x Targetint.one</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pred"><a href="#val-pred" class="anchor"></a><code><span><span class="keyword">val</span> pred : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Predecessor. <code>Targetint.pred x</code> is <code>Targetint.sub x Targetint.one</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-abs"><a href="#val-abs" class="anchor"></a><code><span><span class="keyword">val</span> abs : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>abs x</code> is the absolute value of <code>x</code>. On <code>min_int</code> this is <code>min_int</code> itself and thus remains negative.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-size"><a href="#val-size" class="anchor"></a><code><span><span class="keyword">val</span> size : int</span></code></div><div class="spec-doc"><p>The size in bits of a target native integer.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-max_int"><a href="#val-max_int" class="anchor"></a><code><span><span class="keyword">val</span> max_int : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The greatest representable target integer, either 2<sup>31</sup> - 1 on a 32-bit platform, or 2<sup>63</sup> - 1 on a 64-bit platform.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-min_int"><a href="#val-min_int" class="anchor"></a><code><span><span class="keyword">val</span> min_int : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The smallest representable target integer, either -2<sup>31</sup> on a 32-bit platform, or -2<sup>63</sup> on a 64-bit platform.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-logand"><a href="#val-logand" class="anchor"></a><code><span><span class="keyword">val</span> logand : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Bitwise logical and.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-logor"><a href="#val-logor" class="anchor"></a><code><span><span class="keyword">val</span> logor : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Bitwise logical or.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-logxor"><a href="#val-logxor" class="anchor"></a><code><span><span class="keyword">val</span> logxor : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Bitwise logical exclusive or.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lognot"><a href="#val-lognot" class="anchor"></a><code><span><span class="keyword">val</span> lognot : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Bitwise logical negation.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-shift_left"><a href="#val-shift_left" class="anchor"></a><code><span><span class="keyword">val</span> shift_left : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>Targetint.shift_left x y</code> shifts <code>x</code> to the left by <code>y</code> bits. The result is unspecified if <code>y < 0</code> or <code>y >= bitsize</code>, where <code>bitsize</code> is <code>32</code> on a 32-bit platform and <code>64</code> on a 64-bit platform.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-shift_right"><a href="#val-shift_right" class="anchor"></a><code><span><span class="keyword">val</span> shift_right : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>Targetint.shift_right x y</code> shifts <code>x</code> to the right by <code>y</code> bits. This is an arithmetic shift: the sign bit of <code>x</code> is replicated and inserted in the vacated bits. The result is unspecified if <code>y < 0</code> or <code>y >= bitsize</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-shift_right_logical"><a href="#val-shift_right_logical" class="anchor"></a><code><span><span class="keyword">val</span> shift_right_logical : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>Targetint.shift_right_logical x y</code> shifts <code>x</code> to the right by <code>y</code> bits. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of <code>x</code>. The result is unspecified if <code>y < 0</code> or <code>y >= bitsize</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_int"><a href="#val-of_int" class="anchor"></a><code><span><span class="keyword">val</span> of_int : <span>int <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Convert the given integer (type <code>int</code>) to a target integer (type <code>t</code>), module the target word size.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_int_exn"><a href="#val-of_int_exn" class="anchor"></a><code><span><span class="keyword">val</span> of_int_exn : <span>int <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Convert the given integer (type <code>int</code>) to a target integer (type <code>t</code>). Raises a fatal error if the conversion is not exact.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_int"><a href="#val-to_int" class="anchor"></a><code><span><span class="keyword">val</span> to_int : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p>Convert the given target integer (type <code>t</code>) to an integer (type <code>int</code>). The high-order bit is lost during the conversion.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_float"><a href="#val-of_float" class="anchor"></a><code><span><span class="keyword">val</span> of_float : <span>float <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Convert the given floating-point number to a target integer, discarding the fractional part (truncate towards 0). The result of the conversion is undefined if, after truncation, the number is outside the range [<a href="#val-min_int"><code>Targetint.min_int</code></a>, <a href="#val-max_int"><code>Targetint.max_int</code></a>].</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_float"><a href="#val-to_float" class="anchor"></a><code><span><span class="keyword">val</span> to_float : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> float</span></code></div><div class="spec-doc"><p>Convert the given target integer to a floating-point number.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_int32"><a href="#val-of_int32" class="anchor"></a><code><span><span class="keyword">val</span> of_int32 : <span>int32 <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Convert the given 32-bit integer (type <code>int32</code>) to a target integer.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_int32"><a href="#val-to_int32" class="anchor"></a><code><span><span class="keyword">val</span> to_int32 : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int32</span></code></div><div class="spec-doc"><p>Convert the given target integer to a 32-bit integer (type <code>int32</code>). On 64-bit platforms, the 64-bit native integer is taken modulo 2<sup>32</sup>, i.e. the top 32 bits are lost. On 32-bit platforms, the conversion is exact.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_int64"><a href="#val-of_int64" class="anchor"></a><code><span><span class="keyword">val</span> of_int64 : <span>int64 <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Convert the given 64-bit integer (type <code>int64</code>) to a target integer.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_int64"><a href="#val-to_int64" class="anchor"></a><code><span><span class="keyword">val</span> to_int64 : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int64</span></code></div><div class="spec-doc"><p>Convert the given target integer to a 64-bit integer (type <code>int64</code>).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_string"><a href="#val-of_string" class="anchor"></a><code><span><span class="keyword">val</span> of_string : <span>string <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Convert the given string to a target integer. The string is read in decimal (by default) or in hexadecimal, octal or binary if the string begins with <code>0x</code>, <code>0o</code> or <code>0b</code> respectively. Raise <code>Failure "int_of_string"</code> if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in type <code>nativeint</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_string"><a href="#val-to_string" class="anchor"></a><code><span><span class="keyword">val</span> to_string : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> string</span></code></div><div class="spec-doc"><p>Return the string representation of its argument, in decimal.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span><span class="keyword">val</span> compare : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p>The comparison function for target integers, with the same specification as <a href="../Stdlib/index.html#val-compare"><code>Stdlib.compare</code></a>. Along with the type <code>t</code>, this function <code>compare</code> allows the module <code>Targetint</code> to be passed as argument to the functors <code>Set</code>.Make and <code>Map</code>.Make.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-unsigned_compare"><a href="#val-unsigned_compare" class="anchor"></a><code><span><span class="keyword">val</span> unsigned_compare : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p>Same as <a href="#val-compare"><code>compare</code></a>, except that arguments are interpreted as <em>unsigned</em> integers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-equal"><a href="#val-equal" class="anchor"></a><code><span><span class="keyword">val</span> equal : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p>The equal function for target ints.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-repr"><a href="#type-repr" class="anchor"></a><code><span><span class="keyword">type</span> repr</span><span> = </span></code><ol><li id="type-repr.Int32" class="def variant constructor anchored"><a href="#type-repr.Int32" class="anchor"></a><code><span>| </span><span><span class="constructor">Int32</span> <span class="keyword">of</span> int32</span></code></li><li id="type-repr.Int64" class="def variant constructor anchored"><a href="#type-repr.Int64" class="anchor"></a><code><span>| </span><span><span class="constructor">Int64</span> <span class="keyword">of</span> int64</span></code></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-repr"><a href="#val-repr" class="anchor"></a><code><span><span class="keyword">val</span> repr : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <a href="#type-repr">repr</a></span></code></div><div class="spec-doc"><p>The concrete representation of a native integer.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-print"><a href="#val-print" class="anchor"></a><code><span><span class="keyword">val</span> print : <span><a href="../Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a> <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Print a target integer to a formatter.</p></div></div></div></body></html> |