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). The result of the conversion
231 is undefined if, after truncation, the number is outside the range [
232 Int32.min_int , Int32.max_int ].
233
234
235
236 val to_float : int32 -> float
237
238 Convert the given 32-bit integer to a floating-point number.
239
240
241
242 val of_string : string -> int32
243
244 Convert the given string to a 32-bit integer. The string is read in
245 decimal (by default, or if the string begins with 0u ) or in hexadeci‐
246 mal, octal or binary if the string begins with 0x , 0o or 0b respec‐
247 tively.
248
249 The 0u prefix reads the input as an unsigned integer in the range [0,
250 2*Int32.max_int+1] . If the input exceeds Int32.max_int it is con‐
251 verted to the signed integer Int32.min_int + input - Int32.max_int - 1
252 .
253
254 The _ (underscore) character can appear anywhere in the string and is
255 ignored.
256
257
258 Raises Failure if the given string is not a valid representation of an
259 integer, or if the integer represented exceeds the range of integers
260 representable in type int32 .
261
262
263
264 val of_string_opt : string -> int32 option
265
266 Same as of_string , but return None instead of raising.
267
268
269 Since 4.05
270
271
272
273 val to_string : int32 -> string
274
275 Return the string representation of its argument, in signed decimal.
276
277
278
279 val bits_of_float : float -> int32
280
281 Return the internal representation of the given float according to the
282 IEEE 754 floating-point 'single format' bit layout. Bit 31 of the re‐
283 sult represents the sign of the float; bits 30 to 23 represent the (bi‐
284 ased) exponent; bits 22 to 0 represent the mantissa.
285
286
287
288 val float_of_bits : int32 -> float
289
290 Return the floating-point number whose internal representation, accord‐
291 ing to the IEEE 754 floating-point 'single format' bit layout, is the
292 given int32 .
293
294
295 type t = int32
296
297
298 An alias for the type of 32-bit integers.
299
300
301
302 val compare : t -> t -> int
303
304 The comparison function for 32-bit integers, with the same specifica‐
305 tion as compare . Along with the type t , this function compare allows
306 the module Int32 to be passed as argument to the functors Set.Make and
307 Map.Make .
308
309
310
311 val unsigned_compare : t -> t -> int
312
313 Same as Int32.compare , except that arguments are interpreted as un‐
314 signed 32-bit integers.
315
316
317 Since 4.08.0
318
319
320
321 val equal : t -> t -> bool
322
323 The equal function for int32s.
324
325
326 Since 4.03.0
327
328
329
330 val min : t -> t -> t
331
332 Return the smaller of the two arguments.
333
334
335 Since 4.13.0
336
337
338
339 val max : t -> t -> t
340
341 Return the greater of the two arguments.
342
343
344 Since 4.13.0
345
346
347
348
349
350OCamldoc 2022-02-04 Int32(3)