1Nativeint(3)                     OCaml library                    Nativeint(3)
2
3
4

NAME

6       Nativeint - Processor-native integers.
7

Module

9       Module   Nativeint
10

Documentation

12       Module Nativeint
13        : sig end
14
15
16       Processor-native integers.
17
18       This  module provides operations on the type nativeint of signed 32-bit
19       integers (on 32-bit platforms) or signed  64-bit  integers  (on  64-bit
20       platforms).   This integer type has exactly the same width as that of a
21       pointer type in the C compiler.  All  arithmetic  operations  over  na‐
22       tiveint are taken modulo 2^32 or 2^64 depending on the word size of the
23       architecture.
24
25       Performance notice: values of type nativeint occupy more  memory  space
26       than  values  of  type int , and arithmetic operations on nativeint are
27       generally slower than those on int .  Use nativeint only when  the  ap‐
28       plication requires the extra bit of precision over the int type.
29
30       Literals for native integers are suffixed by n:
31            let zero: nativeint = 0n
32            let one: nativeint = 1n
33            let m_one: nativeint = -1n
34
35
36
37
38
39
40
41       val zero : nativeint
42
43       The native integer 0.
44
45
46
47       val one : nativeint
48
49       The native integer 1.
50
51
52
53       val minus_one : nativeint
54
55       The native integer -1.
56
57
58
59       val neg : nativeint -> nativeint
60
61       Unary negation.
62
63
64
65       val add : nativeint -> nativeint -> nativeint
66
67       Addition.
68
69
70
71       val sub : nativeint -> nativeint -> nativeint
72
73       Subtraction.
74
75
76
77       val mul : nativeint -> nativeint -> nativeint
78
79       Multiplication.
80
81
82
83       val div : nativeint -> nativeint -> nativeint
84
85       Integer  division.  This division rounds the real quotient of its argu‐
86       ments towards zero, as specified for (/) .
87
88
89       Raises Division_by_zero if the second argument is zero.
90
91
92
93       val unsigned_div : nativeint -> nativeint -> nativeint
94
95       Same as Nativeint.div , except that arguments  and  result  are  inter‐
96       preted as     unsigned native integers.
97
98
99       Since 4.08.0
100
101
102
103       val rem : nativeint -> nativeint -> nativeint
104
105       Integer  remainder.   If y is not zero, the result of Nativeint.rem x y
106       satisfies the following properties: Nativeint.zero <= Nativeint.rem x y
107       < Nativeint.abs y and x = Nativeint.add (Nativeint.mul (Nativeint.div x
108       y) y)
109                             (Nativeint.rem x y) .  If y = 0 , Nativeint.rem x
110       y raises Division_by_zero .
111
112
113
114       val unsigned_rem : nativeint -> nativeint -> nativeint
115
116       Same  as  Nativeint.rem  ,  except that arguments and result are inter‐
117       preted as     unsigned native integers.
118
119
120       Since 4.08.0
121
122
123
124       val succ : nativeint -> nativeint
125
126       Successor.  Nativeint.succ x is Nativeint.add x Nativeint.one .
127
128
129
130       val pred : nativeint -> nativeint
131
132       Predecessor.  Nativeint.pred x is Nativeint.sub x Nativeint.one .
133
134
135
136       val abs : nativeint -> nativeint
137
138       Return the absolute value of its argument.
139
140
141
142       val size : int
143
144       The size in bits of a native integer.  This is equal to 32 on a  32-bit
145       platform and to 64 on a 64-bit platform.
146
147
148
149       val max_int : nativeint
150
151       The  greatest representable native integer, either 2^31 - 1 on a 32-bit
152       platform, or 2^63 - 1 on a 64-bit platform.
153
154
155
156       val min_int : nativeint
157
158       The smallest representable native integer, either  -2^31  on  a  32-bit
159       platform, or -2^63 on a 64-bit platform.
160
161
162
163       val logand : nativeint -> nativeint -> nativeint
164
165       Bitwise logical and.
166
167
168
169       val logor : nativeint -> nativeint -> nativeint
170
171       Bitwise logical or.
172
173
174
175       val logxor : nativeint -> nativeint -> nativeint
176
177       Bitwise logical exclusive or.
178
179
180
181       val lognot : nativeint -> nativeint
182
183       Bitwise logical negation.
184
185
186
187       val shift_left : nativeint -> int -> nativeint
188
189
190       Nativeint.shift_left x y shifts x to the left by y bits.  The result is
191       unspecified if y < 0 or y >= bitsize , where bitsize is 32 on a  32-bit
192       platform and 64 on a 64-bit platform.
193
194
195
196       val shift_right : nativeint -> int -> nativeint
197
198
199       Nativeint.shift_right  x y shifts x to the right by y bits.  This is an
200       arithmetic shift: the sign bit of x is replicated and inserted  in  the
201       vacated bits.  The result is unspecified if y < 0 or y >= bitsize .
202
203
204
205       val shift_right_logical : nativeint -> int -> nativeint
206
207
208       Nativeint.shift_right_logical  x  y  shifts  x  to the right by y bits.
209       This is a logical shift: zeroes are inserted in the  vacated  bits  re‐
210       gardless of the sign of x .  The result is unspecified if y < 0 or y >=
211       bitsize .
212
213
214
215       val of_int : int -> nativeint
216
217       Convert the given integer (type int ) to a  native  integer  (type  na‐
218       tiveint ).
219
220
221
222       val to_int : nativeint -> int
223
224       Convert  the given native integer (type nativeint ) to an integer (type
225       int ).  The high-order bit is lost during the conversion.
226
227
228
229       val unsigned_to_int : nativeint -> int option
230
231       Same as Nativeint.to_int , but interprets the argument as  an  unsigned
232       integer.  Returns None if the unsigned value of the argument cannot fit
233       into an int .
234
235
236       Since 4.08.0
237
238
239
240       val of_float : float -> nativeint
241
242       Convert the given floating-point number to a native integer, discarding
243       the  fractional  part  (truncate  towards  0).  If the truncated float‐
244       ing-point number  is  outside  the  range  [  Nativeint.min_int  ,  Na‐
245       tiveint.max_int  ],  no  exception is raised, and an unspecified, plat‐
246       form-dependent integer is returned.
247
248
249
250       val to_float : nativeint -> float
251
252       Convert the given native integer to a floating-point number.
253
254
255
256       val of_int32 : int32 -> nativeint
257
258       Convert the given 32-bit integer (type int32 ) to a native integer.
259
260
261
262       val to_int32 : nativeint -> int32
263
264       Convert the given native integer to a 32-bit integer (type int32 ).  On
265       64-bit  platforms, the 64-bit native integer is taken modulo 2^32, i.e.
266       the top 32 bits are lost.  On 32-bit platforms, the conversion  is  ex‐
267       act.
268
269
270
271       val of_string : string -> nativeint
272
273       Convert  the  given  string to a native integer.  The string is read in
274       decimal (by default, or if the string begins with 0u ) or in  hexadeci‐
275       mal,  octal  or  binary if the string begins with 0x , 0o or 0b respec‐
276       tively.
277
278       The 0u prefix reads the input as an unsigned integer in the  range  [0,
279       2*Nativeint.max_int+1]  .  If the input exceeds Nativeint.max_int it is
280       converted  to  the  signed  integer  Int64.min_int  +   input   -   Na‐
281       tiveint.max_int - 1 .
282
283
284       Raises  Failure if the given string is not a valid representation of an
285       integer, or if the integer represented exceeds the  range  of  integers
286       representable in type nativeint .
287
288
289
290       val of_string_opt : string -> nativeint option
291
292       Same as of_string , but return None instead of raising.
293
294
295       Since 4.05
296
297
298
299       val to_string : nativeint -> string
300
301       Return the string representation of its argument, in decimal.
302
303
304       type t = nativeint
305
306
307       An alias for the type of native integers.
308
309
310
311       val compare : t -> t -> int
312
313       The  comparison  function for native integers, with the same specifica‐
314       tion as compare .  Along with the type t , this function compare allows
315       the  module Nativeint to be passed as argument to the functors Set.Make
316       and Map.Make .
317
318
319
320       val unsigned_compare : t -> t -> int
321
322       Same as Nativeint.compare , except that arguments  are  interpreted  as
323       unsigned native integers.
324
325
326       Since 4.08.0
327
328
329
330       val equal : t -> t -> bool
331
332       The equal function for native ints.
333
334
335       Since 4.03.0
336
337
338
339       val min : t -> t -> t
340
341       Return the smaller of the two arguments.
342
343
344       Since 4.13.0
345
346
347
348       val max : t -> t -> t
349
350       Return the greater of the two arguments.
351
352
353       Since 4.13.0
354
355
356
357
358
359OCamldoc                          2022-07-22                      Nativeint(3)
Impressum