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

NAME

6       Int32 - 32-bit integers.
7

Module

9       Module   Int32
10

Documentation

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