1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
"http://www.w3.org/TR/REC-html40/loose.dtd">
5
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6
<META name="GENERATOR" content="hevea 1.05">
8
Module Nativeint: processor-native integers
11
<BODY TEXT=black BGCOLOR=white>
12
<A HREF="manual050.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
13
<A HREF="manual032.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
14
<A HREF="manual052.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
16
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
17
<TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE>
18
<TR><TD><B><FONT SIZE=5>19.19</FONT></B></TD>
19
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5> Module </FONT></B><B><FONT SIZE=5><TT>Nativeint</TT></FONT></B><B><FONT SIZE=5>: processor-native integers</FONT></B></TD>
20
</TR></TABLE></DIV></TD>
22
<A NAME="s:Nativeint"></A>
23
<A NAME="@manual479"></A><BR>
25
This module provides operations on the type <CODE>nativeint</CODE> of
26
signed 32-bit integers (on 32-bit platforms) or
27
signed 64-bit integers (on 64-bit platforms).
28
This integer type has exactly the same width as that of a <CODE>long</CODE>
29
integer type in the C compiler. All arithmetic operations over
30
<CODE>nativeint</CODE> are taken modulo 2<SUP><FONT SIZE=2>32</FONT></SUP> or 2<SUP><FONT SIZE=2>64</FONT></SUP> depending
31
on the word size of the architecture.<BR>
33
Performance notice: values of type <CODE>nativeint</CODE> occupy more memory
34
space than values of type <CODE>int</CODE>, and arithmetic operations on
35
<CODE>nativeint</CODE> are generally slower than those on <CODE>int</CODE>. Use <CODE>nativeint</CODE>
36
only when the application requires the extra bit of precision
37
over the <CODE>int</CODE> type.
42
val minus_one: nativeint
43
</PRE><A NAME="@manual480"></A><A NAME="@manual481"></A><A NAME="@manual482"></A><BLOCKQUOTE>
44
The native integers 0, 1, -1.
47
val neg: nativeint -> nativeint
48
</PRE><A NAME="@manual483"></A><BLOCKQUOTE>
52
val add: nativeint -> nativeint -> nativeint
53
</PRE><A NAME="@manual484"></A><BLOCKQUOTE>
57
val sub: nativeint -> nativeint -> nativeint
58
</PRE><A NAME="@manual485"></A><BLOCKQUOTE>
62
val mul: nativeint -> nativeint -> nativeint
63
</PRE><A NAME="@manual486"></A><BLOCKQUOTE>
67
val div: nativeint -> nativeint -> nativeint
68
</PRE><A NAME="@manual487"></A><BLOCKQUOTE>
69
Integer division. Raise <CODE>Division_by_zero</CODE> if the second
73
val rem: nativeint -> nativeint -> nativeint
74
</PRE><A NAME="@manual488"></A><BLOCKQUOTE>
75
Integer remainder. If <CODE>x >= 0</CODE> and <CODE>y > 0</CODE>, the result
76
of <CODE>Nativeint.rem x y</CODE> satisfies the following properties:
77
<CODE>0 <= Nativeint.rem x y < y</CODE> and
78
<CODE>x = Nativeint.add (Nativeint.mul (Nativeint.div x y) y) (Nativeint.rem x y)</CODE>.
79
If <CODE>y = 0</CODE>, <CODE>Nativeint.rem x y</CODE> raises <CODE>Division_by_zero</CODE>.
80
If <CODE>x < 0</CODE> or <CODE>y < 0</CODE>, the result of <CODE>Nativeint.rem x y</CODE> is
81
not specified and depends on the platform.
84
val succ: nativeint -> nativeint
85
</PRE><A NAME="@manual489"></A><BLOCKQUOTE>
87
<CODE>Nativeint.succ x</CODE> is <CODE>Nativeint.add x Nativeint.one</CODE>.
90
val pred: nativeint -> nativeint
91
</PRE><A NAME="@manual490"></A><BLOCKQUOTE>
93
<CODE>Nativeint.pred x</CODE> is <CODE>Nativeint.sub x Nativeint.one</CODE>.
96
val abs: nativeint -> nativeint
97
</PRE><A NAME="@manual491"></A><BLOCKQUOTE>
98
Return the absolute value of its argument.
102
</PRE><A NAME="@manual492"></A><BLOCKQUOTE>
103
The size in bits of a native integer. This is equal to <CODE>32</CODE>
104
on a 32-bit platform and to <CODE>64</CODE> on a 64-bit platform.
107
val max_int: nativeint
108
</PRE><A NAME="@manual493"></A><BLOCKQUOTE>
109
The greatest representable native integer,
110
either 2<SUP><FONT SIZE=2>31</FONT></SUP> - 1 on a 32-bit platform,
111
or 2<SUP><FONT SIZE=2>63</FONT></SUP> - 1 on a 64-bit platform.
114
val min_int: nativeint
115
</PRE><A NAME="@manual494"></A><BLOCKQUOTE>
116
The greatest representable native integer,
117
either -2<SUP><FONT SIZE=2>31</FONT></SUP> on a 32-bit platform,
118
or -2<SUP><FONT SIZE=2>63</FONT></SUP> on a 64-bit platform.
121
val logand: nativeint -> nativeint -> nativeint
122
</PRE><A NAME="@manual495"></A><BLOCKQUOTE>
126
val logor: nativeint -> nativeint -> nativeint
127
</PRE><A NAME="@manual496"></A><BLOCKQUOTE>
131
val logxor: nativeint -> nativeint -> nativeint
132
</PRE><A NAME="@manual497"></A><BLOCKQUOTE>
133
Bitwise logical exclusive or.
136
val lognot: nativeint -> nativeint
137
</PRE><A NAME="@manual498"></A><BLOCKQUOTE>
138
Bitwise logical negation
141
val shift_left: nativeint -> int -> nativeint
142
</PRE><A NAME="@manual499"></A><BLOCKQUOTE>
143
<CODE>Nativeint.shift_left x y</CODE> shifts <CODE>x</CODE> to the left by <CODE>y</CODE> bits.
144
The result is unspecified if <CODE>y < 0</CODE> or <CODE>y >= bitsize</CODE>,
145
where <CODE>bitsize</CODE> is <CODE>32</CODE> on a 32-bit platform and
146
<CODE>64</CODE> on a 64-bit platform.
149
val shift_right: nativeint -> int -> nativeint
150
</PRE><A NAME="@manual500"></A><BLOCKQUOTE>
151
<CODE>Nativeint.shift_right x y</CODE> shifts <CODE>x</CODE> to the right by <CODE>y</CODE> bits.
152
This is an arithmetic shift: the sign bit of <CODE>x</CODE> is replicated
153
and inserted in the vacated bits.
154
The result is unspecified if <CODE>y < 0</CODE> or <CODE>y >= bitsize</CODE>.
157
val shift_right_logical: nativeint -> int -> nativeint
158
</PRE><A NAME="@manual501"></A><BLOCKQUOTE>
159
<CODE>Nativeint.shift_right_logical x y</CODE> shifts <CODE>x</CODE> to the right
160
by <CODE>y</CODE> bits.
161
This is a logical shift: zeroes are inserted in the vacated bits
162
regardless of the sign of <CODE>x</CODE>.
163
The result is unspecified if <CODE>y < 0</CODE> or <CODE>y >= bitsize</CODE>.
166
val of_int: int -> nativeint
167
</PRE><A NAME="@manual502"></A><BLOCKQUOTE>
168
Convert the given integer (type <CODE>int</CODE>) to a native integer
169
(type <CODE>nativeint</CODE>).
172
val to_int: nativeint -> int
173
</PRE><A NAME="@manual503"></A><BLOCKQUOTE>
174
Convert the given native integer (type <CODE>nativeint</CODE>) to an
175
integer (type <CODE>int</CODE>). The high-order bit is lost during
179
val of_float : float -> nativeint
180
</PRE><A NAME="@manual504"></A><BLOCKQUOTE>
181
Convert the given floating-point number to a native integer,
182
discarding the fractional part (truncate towards 0).
183
The result of the conversion is undefined if, after truncation,
184
the number is outside the range
185
<CODE>Nativeint.min_int, Nativeint.max_int</CODE>.
188
val to_float : nativeint -> float
189
</PRE><A NAME="@manual505"></A><BLOCKQUOTE>
190
Convert the given native integer to a floating-point number.
193
val of_int32: int32 -> nativeint
194
</PRE><A NAME="@manual506"></A><BLOCKQUOTE>
195
Convert the given 32-bit integer (type <CODE>int32</CODE>)
199
val to_int32: nativeint -> int32
200
</PRE><A NAME="@manual507"></A><BLOCKQUOTE>
201
Convert the given native integer to a
202
32-bit integer (type <CODE>int32</CODE>). On 64-bit platforms,
203
the 64-bit native integer is taken modulo 2<SUP><FONT SIZE=2>32</FONT></SUP>,
204
i.e. the top 32 bits are lost. On 32-bit platforms,
205
the conversion is exact.
208
val of_string: string -> nativeint
209
</PRE><A NAME="@manual508"></A><BLOCKQUOTE>
210
Convert the given string to a native integer.
211
The string is read in decimal (by default) or in hexadecimal,
212
octal or binary if the string begins with <CODE>0x</CODE>, <CODE>0o</CODE> or <CODE>0b</CODE>
214
Raise <CODE>Failure "int_of_string"</CODE> if the given string is not
215
a valid representation of an integer.
218
val to_string: nativeint -> string
219
</PRE><A NAME="@manual509"></A><BLOCKQUOTE>
220
Return the string representation of its argument, in decimal.
223
val format : string -> nativeint -> string
224
</PRE><A NAME="@manual510"></A><BLOCKQUOTE>
225
<CODE>Nativeint.format fmt n</CODE> return the string representation of the
226
native integer <CODE>n</CODE> in the format specified by <CODE>fmt</CODE>.
227
<CODE>fmt</CODE> is a <CODE>Printf</CODE>-style format containing exactly
228
one <CODE>%d</CODE>, <CODE>%i</CODE>, <CODE>%u</CODE>, <CODE>%x</CODE>, <CODE>%X</CODE> or <CODE>%o</CODE> conversion specification.
229
See the documentation of the <CODE>Printf</CODE> module for more information,
233
<A HREF="manual050.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
234
<A HREF="manual032.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
235
<A HREF="manual052.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>