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).  The result of the conversion
244       is undefined if, after truncation, the number is outside  the  range  [
245       Nativeint.min_int , Nativeint.max_int ].
246
247
248
249       val to_float : nativeint -> float
250
251       Convert the given native integer to a floating-point number.
252
253
254
255       val of_int32 : int32 -> nativeint
256
257       Convert the given 32-bit integer (type int32 ) to a native integer.
258
259
260
261       val to_int32 : nativeint -> int32
262
263       Convert the given native integer to a 32-bit integer (type int32 ).  On
264       64-bit platforms, the 64-bit native integer is taken modulo 2^32,  i.e.
265       the  top  32 bits are lost.  On 32-bit platforms, the conversion is ex‐
266       act.
267
268
269
270       val of_string : string -> nativeint
271
272       Convert the given string to a native integer.  The string  is  read  in
273       decimal  (by default, or if the string begins with 0u ) or in hexadeci‐
274       mal, octal or binary if the string begins with 0x , 0o  or  0b  respec‐
275       tively.
276
277       The  0u  prefix reads the input as an unsigned integer in the range [0,
278       2*Nativeint.max_int+1] .  If the input exceeds Nativeint.max_int it  is
279       converted   to   the   signed  integer  Int64.min_int  +  input  -  Na‐
280       tiveint.max_int - 1 .
281
282
283       Raises Failure if the given string is not a valid representation of  an
284       integer,  or  if  the integer represented exceeds the range of integers
285       representable in type nativeint .
286
287
288
289       val of_string_opt : string -> nativeint option
290
291       Same as of_string , but return None instead of raising.
292
293
294       Since 4.05
295
296
297
298       val to_string : nativeint -> string
299
300       Return the string representation of its argument, in decimal.
301
302
303       type t = nativeint
304
305
306       An alias for the type of native integers.
307
308
309
310       val compare : t -> t -> int
311
312       The comparison function for native integers, with the  same  specifica‐
313       tion as compare .  Along with the type t , this function compare allows
314       the module Nativeint to be passed as argument to the functors  Set.Make
315       and Map.Make .
316
317
318
319       val unsigned_compare : t -> t -> int
320
321       Same  as  Nativeint.compare  , except that arguments are interpreted as
322       unsigned native integers.
323
324
325       Since 4.08.0
326
327
328
329       val equal : t -> t -> bool
330
331       The equal function for native ints.
332
333
334       Since 4.03.0
335
336
337
338       val min : t -> t -> t
339
340       Return the smaller of the two arguments.
341
342
343       Since 4.13.0
344
345
346
347       val max : t -> t -> t
348
349       Return the greater of the two arguments.
350
351
352       Since 4.13.0
353
354
355
356
357
358OCamldoc                          2022-02-04                      Nativeint(3)
Impressum