~ubuntu-branches/ubuntu/karmic/ocaml-doc/karmic

« back to all changes in this revision

Viewing changes to ocaml.html/manual051.html

  • Committer: Bazaar Package Importer
  • Author(s): Vanicat Rémi
  • Date: 2002-02-05 10:51:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020205105143-a061tunf8tev07ne
Tags: 3.04-4
* New debian maintainer
* Split doc-base file
* Move to non-free
* Change the copyright file to the copyright of the documentation
* remove FAQs (their license prohibit their redistribution)
* corrected the examples

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 
2
            "http://www.w3.org/TR/REC-html40/loose.dtd">
 
3
<HTML>
 
4
<HEAD>
 
5
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 
6
<META name="GENERATOR" content="hevea 1.05">
 
7
<TITLE>
 
8
 Module Nativeint: processor-native integers
 
9
</TITLE>
 
10
</HEAD>
 
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>
 
15
<HR>
 
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>
 
21
</TR></TABLE><BR>
 
22
<A NAME="s:Nativeint"></A>
 
23
<A NAME="@manual479"></A><BR>
 
24
<BLOCKQUOTE>
 
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>
 
32
<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. 
 
38
</BLOCKQUOTE>
 
39
<PRE>
 
40
val zero: nativeint
 
41
val one: nativeint
 
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. 
 
45
</BLOCKQUOTE>
 
46
<PRE>
 
47
val neg: nativeint -&gt; nativeint
 
48
</PRE><A NAME="@manual483"></A><BLOCKQUOTE>
 
49
Unary negation. 
 
50
</BLOCKQUOTE>
 
51
<PRE>
 
52
val add: nativeint -&gt; nativeint -&gt; nativeint
 
53
</PRE><A NAME="@manual484"></A><BLOCKQUOTE>
 
54
Addition. 
 
55
</BLOCKQUOTE>
 
56
<PRE>
 
57
val sub: nativeint -&gt; nativeint -&gt; nativeint
 
58
</PRE><A NAME="@manual485"></A><BLOCKQUOTE>
 
59
Subtraction. 
 
60
</BLOCKQUOTE>
 
61
<PRE>
 
62
val mul: nativeint -&gt; nativeint -&gt; nativeint
 
63
</PRE><A NAME="@manual486"></A><BLOCKQUOTE>
 
64
Multiplication. 
 
65
</BLOCKQUOTE>
 
66
<PRE>
 
67
val div: nativeint -&gt; nativeint -&gt; nativeint
 
68
</PRE><A NAME="@manual487"></A><BLOCKQUOTE>
 
69
Integer division. Raise <CODE>Division_by_zero</CODE> if the second 
 
70
argument is zero. 
 
71
</BLOCKQUOTE>
 
72
<PRE>
 
73
val rem: nativeint -&gt; nativeint -&gt; nativeint
 
74
</PRE><A NAME="@manual488"></A><BLOCKQUOTE>
 
75
Integer remainder. If <CODE>x &gt;= 0</CODE> and <CODE>y &gt; 0</CODE>, the result
 
76
of <CODE>Nativeint.rem x y</CODE> satisfies the following properties:
 
77
<CODE>0 &lt;= Nativeint.rem x y &lt; 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 &lt; 0</CODE> or <CODE>y &lt; 0</CODE>, the result of <CODE>Nativeint.rem x y</CODE> is
 
81
not specified and depends on the platform. 
 
82
</BLOCKQUOTE>
 
83
<PRE>
 
84
val succ: nativeint -&gt; nativeint
 
85
</PRE><A NAME="@manual489"></A><BLOCKQUOTE>
 
86
Successor.
 
87
<CODE>Nativeint.succ x</CODE> is <CODE>Nativeint.add x Nativeint.one</CODE>. 
 
88
</BLOCKQUOTE>
 
89
<PRE>
 
90
val pred: nativeint -&gt; nativeint
 
91
</PRE><A NAME="@manual490"></A><BLOCKQUOTE>
 
92
Predecessor.
 
93
<CODE>Nativeint.pred x</CODE> is <CODE>Nativeint.sub x Nativeint.one</CODE>. 
 
94
</BLOCKQUOTE>
 
95
<PRE>
 
96
val abs: nativeint -&gt; nativeint
 
97
</PRE><A NAME="@manual491"></A><BLOCKQUOTE>
 
98
Return the absolute value of its argument. 
 
99
</BLOCKQUOTE>
 
100
<PRE>
 
101
val size: int
 
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. 
 
105
</BLOCKQUOTE>
 
106
<PRE>
 
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. 
 
112
</BLOCKQUOTE>
 
113
<PRE>
 
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. 
 
119
</BLOCKQUOTE>
 
120
<PRE>
 
121
val logand: nativeint -&gt; nativeint -&gt; nativeint
 
122
</PRE><A NAME="@manual495"></A><BLOCKQUOTE>
 
123
Bitwise logical and. 
 
124
</BLOCKQUOTE>
 
125
<PRE>
 
126
val logor: nativeint -&gt; nativeint -&gt; nativeint
 
127
</PRE><A NAME="@manual496"></A><BLOCKQUOTE>
 
128
Bitwise logical or. 
 
129
</BLOCKQUOTE>
 
130
<PRE>
 
131
val logxor: nativeint -&gt; nativeint -&gt; nativeint
 
132
</PRE><A NAME="@manual497"></A><BLOCKQUOTE>
 
133
Bitwise logical exclusive or. 
 
134
</BLOCKQUOTE>
 
135
<PRE>
 
136
val lognot: nativeint -&gt; nativeint
 
137
</PRE><A NAME="@manual498"></A><BLOCKQUOTE>
 
138
Bitwise logical negation 
 
139
</BLOCKQUOTE>
 
140
<PRE>
 
141
val shift_left: nativeint -&gt; int -&gt; 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 &lt; 0</CODE> or <CODE>y &gt;= 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. 
 
147
</BLOCKQUOTE>
 
148
<PRE>
 
149
val shift_right: nativeint -&gt; int -&gt; 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 &lt; 0</CODE> or <CODE>y &gt;= bitsize</CODE>. 
 
155
</BLOCKQUOTE>
 
156
<PRE>
 
157
val shift_right_logical: nativeint -&gt; int -&gt; 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 &lt; 0</CODE> or <CODE>y &gt;= bitsize</CODE>. 
 
164
</BLOCKQUOTE>
 
165
<PRE>
 
166
val of_int: int -&gt; 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>). 
 
170
</BLOCKQUOTE>
 
171
<PRE>
 
172
val to_int: nativeint -&gt; 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
 
176
the conversion. 
 
177
</BLOCKQUOTE>
 
178
<PRE>
 
179
val of_float : float -&gt; 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>. 
 
186
</BLOCKQUOTE>
 
187
<PRE>
 
188
val to_float : nativeint -&gt; float
 
189
</PRE><A NAME="@manual505"></A><BLOCKQUOTE>
 
190
Convert the given native integer to a floating-point number. 
 
191
</BLOCKQUOTE>
 
192
<PRE>
 
193
val of_int32: int32 -&gt; nativeint
 
194
</PRE><A NAME="@manual506"></A><BLOCKQUOTE>
 
195
Convert the given 32-bit integer (type <CODE>int32</CODE>)
 
196
to a native integer. 
 
197
</BLOCKQUOTE>
 
198
<PRE>
 
199
val to_int32: nativeint -&gt; 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. 
 
206
</BLOCKQUOTE>
 
207
<PRE>
 
208
val of_string: string -&gt; 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>
 
213
respectively.
 
214
Raise <CODE>Failure "int_of_string"</CODE> if the given string is not
 
215
a valid representation of an integer. 
 
216
</BLOCKQUOTE>
 
217
<PRE>
 
218
val to_string: nativeint -&gt; string
 
219
</PRE><A NAME="@manual509"></A><BLOCKQUOTE>
 
220
Return the string representation of its argument, in decimal. 
 
221
</BLOCKQUOTE>
 
222
<PRE>
 
223
val format : string -&gt; nativeint -&gt; 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, 
 
230
</BLOCKQUOTE>
 
231
 
 
232
<HR>
 
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>
 
236
</BODY>
 
237
</HTML>