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