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
139       abs x is the absolute value of x . On min_int this  is  min_int  itself
140       and thus remains negative.
141
142
143
144       val size : int
145
146       The  size in bits of a native integer.  This is equal to 32 on a 32-bit
147       platform and to 64 on a 64-bit platform.
148
149
150
151       val max_int : nativeint
152
153       The greatest representable native integer, either 2^31 - 1 on a  32-bit
154       platform, or 2^63 - 1 on a 64-bit platform.
155
156
157
158       val min_int : nativeint
159
160       The  smallest  representable  native  integer, either -2^31 on a 32-bit
161       platform, or -2^63 on a 64-bit platform.
162
163
164
165       val logand : nativeint -> nativeint -> nativeint
166
167       Bitwise logical and.
168
169
170
171       val logor : nativeint -> nativeint -> nativeint
172
173       Bitwise logical or.
174
175
176
177       val logxor : nativeint -> nativeint -> nativeint
178
179       Bitwise logical exclusive or.
180
181
182
183       val lognot : nativeint -> nativeint
184
185       Bitwise logical negation.
186
187
188
189       val shift_left : nativeint -> int -> nativeint
190
191
192       Nativeint.shift_left x y shifts x to the left by y bits.  The result is
193       unspecified  if y < 0 or y >= bitsize , where bitsize is 32 on a 32-bit
194       platform and 64 on a 64-bit platform.
195
196
197
198       val shift_right : nativeint -> int -> nativeint
199
200
201       Nativeint.shift_right x y shifts x to the right by y bits.  This is  an
202       arithmetic  shift:  the sign bit of x is replicated and inserted in the
203       vacated bits.  The result is unspecified if y < 0 or y >= bitsize .
204
205
206
207       val shift_right_logical : nativeint -> int -> nativeint
208
209
210       Nativeint.shift_right_logical x y shifts x to  the  right  by  y  bits.
211       This  is  a  logical shift: zeroes are inserted in the vacated bits re‐
212       gardless of the sign of x .  The result is unspecified if y < 0 or y >=
213       bitsize .
214
215
216
217       val of_int : int -> nativeint
218
219       Convert  the  given  integer  (type int ) to a native integer (type na‐
220       tiveint ).
221
222
223
224       val to_int : nativeint -> int
225
226       Convert the given native integer (type nativeint ) to an integer  (type
227       int ).  The high-order bit is lost during the conversion.
228
229
230
231       val unsigned_to_int : nativeint -> int option
232
233       Same  as  Nativeint.to_int , but interprets the argument as an unsigned
234       integer.  Returns None if the unsigned value of the argument cannot fit
235       into an int .
236
237
238       Since 4.08.0
239
240
241
242       val of_float : float -> nativeint
243
244       Convert the given floating-point number to a native integer, discarding
245       the fractional part (truncate towards  0).   If  the  truncated  float‐
246       ing-point  number  is  outside  the  range  [  Nativeint.min_int  , Na‐
247       tiveint.max_int ], no exception is raised, and  an  unspecified,  plat‐
248       form-dependent integer is returned.
249
250
251
252       val to_float : nativeint -> float
253
254       Convert the given native integer to a floating-point number.
255
256
257
258       val of_int32 : int32 -> nativeint
259
260       Convert the given 32-bit integer (type int32 ) to a native integer.
261
262
263
264       val to_int32 : nativeint -> int32
265
266       Convert the given native integer to a 32-bit integer (type int32 ).  On
267       64-bit platforms, the 64-bit native integer is taken modulo 2^32,  i.e.
268       the  top  32 bits are lost.  On 32-bit platforms, the conversion is ex‐
269       act.
270
271
272
273       val of_string : string -> nativeint
274
275       Convert the given string to a native integer.  The string  is  read  in
276       decimal  (by default, or if the string begins with 0u ) or in hexadeci‐
277       mal, octal or binary if the string begins with 0x , 0o  or  0b  respec‐
278       tively.
279
280       The  0u  prefix reads the input as an unsigned integer in the range [0,
281       2*Nativeint.max_int+1] .  If the input exceeds Nativeint.max_int it  is
282       converted   to   the   signed  integer  Int64.min_int  +  input  -  Na‐
283       tiveint.max_int - 1 .
284
285
286       Raises Failure if the given string is not a valid representation of  an
287       integer,  or  if  the integer represented exceeds the range of integers
288       representable in type nativeint .
289
290
291
292       val of_string_opt : string -> nativeint option
293
294       Same as of_string , but return None instead of raising.
295
296
297       Since 4.05
298
299
300
301       val to_string : nativeint -> string
302
303       Return the string representation of its argument, in decimal.
304
305
306       type t = nativeint
307
308
309       An alias for the type of native integers.
310
311
312
313       val compare : t -> t -> int
314
315       The comparison function for native integers, with the  same  specifica‐
316       tion as compare .  Along with the type t , this function compare allows
317       the module Nativeint to be passed as argument to the functors  Set.Make
318       and Map.Make .
319
320
321
322       val unsigned_compare : t -> t -> int
323
324       Same  as  Nativeint.compare  , except that arguments are interpreted as
325       unsigned native integers.
326
327
328       Since 4.08.0
329
330
331
332       val equal : t -> t -> bool
333
334       The equal function for native ints.
335
336
337       Since 4.03.0
338
339
340
341       val min : t -> t -> t
342
343       Return the smaller of the two arguments.
344
345
346       Since 4.13.0
347
348
349
350       val max : t -> t -> t
351
352       Return the greater of the two arguments.
353
354
355       Since 4.13.0
356
357
358
359
360
361OCamldoc                          2023-07-20                      Nativeint(3)
Impressum