1Int32(3) OCamldoc 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
19 integers. Unlike the built-in int type, the type int32 is guaranteed
20 to 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
26 requires exact 32-bit arithmetic.
27
28
29
30
31
32
33 val zero : int32
34
35 The 32-bit integer 0.
36
37
38
39 val one : int32
40
41 The 32-bit integer 1.
42
43
44
45 val minus_one : int32
46
47 The 32-bit integer -1.
48
49
50
51 val neg : int32 -> int32
52
53 Unary negation.
54
55
56
57 val add : int32 -> int32 -> int32
58
59 Addition.
60
61
62
63 val sub : int32 -> int32 -> int32
64
65 Subtraction.
66
67
68
69 val mul : int32 -> int32 -> int32
70
71 Multiplication.
72
73
74
75 val div : int32 -> int32 -> int32
76
77 Integer division. Raise Division_by_zero if the second argument is
78 zero. This division rounds the real quotient of its arguments towards
79 zero, as specified for Pervasives.(/) .
80
81
82
83 val rem : int32 -> int32 -> int32
84
85 Integer remainder. If y is not zero, the result of Int32.rem x y sat‐
86 isfies the following property: x = Int32.add (Int32.mul (Int32.div x y)
87 y) (Int32.rem x y) . If y = 0 , Int32.rem x y raises Division_by_zero
88 .
89
90
91
92 val succ : int32 -> int32
93
94 Successor. Int32.succ x is Int32.add x Int32.one .
95
96
97
98 val pred : int32 -> int32
99
100 Predecessor. Int32.pred x is Int32.sub x Int32.one .
101
102
103
104 val abs : int32 -> int32
105
106 Return the absolute value of its argument.
107
108
109
110 val max_int : int32
111
112 The greatest representable 32-bit integer, 2^{31 - 1.
113
114
115
116 val min_int : int32
117
118 The smallest representable 32-bit integer, -2^{31.
119
120
121
122 val logand : int32 -> int32 -> int32
123
124 Bitwise logical and.
125
126
127
128 val logor : int32 -> int32 -> int32
129
130 Bitwise logical or.
131
132
133
134 val logxor : int32 -> int32 -> int32
135
136 Bitwise logical exclusive or.
137
138
139
140 val lognot : int32 -> int32
141
142 Bitwise logical negation
143
144
145
146 val shift_left : int32 -> int -> int32
147
148
149 Int32.shift_left x y shifts x to the left by y bits. The result is
150 unspecified if y < 0 or y >= 32 .
151
152
153
154 val shift_right : int32 -> int -> int32
155
156
157 Int32.shift_right x y shifts x to the right by y bits. This is an
158 arithmetic shift: the sign bit of x is replicated and inserted in the
159 vacated bits. The result is unspecified if y < 0 or y >= 32 .
160
161
162
163 val shift_right_logical : int32 -> int -> int32
164
165
166 Int32.shift_right_logical x y shifts x to the right by y bits. This is
167 a logical shift: zeroes are inserted in the vacated bits regardless of
168 the sign of x . The result is unspecified if y < 0 or y >= 32 .
169
170
171
172 val of_int : int -> int32
173
174 Convert the given integer (type int ) to a 32-bit integer (type int32
175 ).
176
177
178
179 val to_int : int32 -> int
180
181 Convert the given 32-bit integer (type int32 ) to an integer (type int
182 ). On 32-bit platforms, the 32-bit integer is taken modulo 2^{31, i.e.
183 the high-order bit is lost during the conversion. On 64-bit platforms,
184 the conversion is exact.
185
186
187
188 val of_float : float -> int32
189
190 Convert the given floating-point number to a 32-bit integer, discarding
191 the fractional part (truncate towards 0). The result of the conversion
192 is undefined if, after truncation, the number is outside the range [
193 Int32.min_int , Int32.max_int ].
194
195
196
197 val to_float : int32 -> float
198
199 Convert the given 32-bit integer to a floating-point number.
200
201
202
203 val of_string : string -> int32
204
205 Convert the given string to a 32-bit integer. The string is read in
206 decimal (by default) or in hexadecimal, octal or binary if the string
207 begins with 0x , 0o or 0b respectively. Raise Failure int_of_string if
208 the given string is not a valid representation of an integer, or if the
209 integer represented exceeds the range of integers representable in type
210 int32 .
211
212
213
214 val of_string_opt : string -> int32 option
215
216 Same as of_string , but return None instead of raising.
217
218
219 Since 4.05
220
221
222
223 val to_string : int32 -> string
224
225 Return the string representation of its argument, in signed decimal.
226
227
228
229 val bits_of_float : float -> int32
230
231 Return the internal representation of the given float according to the
232 IEEE 754 floating-point 'single format' bit layout. Bit 31 of the
233 result represents the sign of the float; bits 30 to 23 represent the
234 (biased) exponent; bits 22 to 0 represent the mantissa.
235
236
237
238 val float_of_bits : int32 -> float
239
240 Return the floating-point number whose internal representation, accord‐
241 ing to the IEEE 754 floating-point 'single format' bit layout, is the
242 given int32 .
243
244
245 type t = int32
246
247
248 An alias for the type of 32-bit integers.
249
250
251
252 val compare : t -> t -> int
253
254 The comparison function for 32-bit integers, with the same specifica‐
255 tion as Pervasives.compare . Along with the type t , this function
256 compare allows the module Int32 to be passed as argument to the func‐
257 tors Set.Make and Map.Make .
258
259
260
261 val equal : t -> t -> bool
262
263 The equal function for int32s.
264
265
266 Since 4.03.0
267
268
269
270
271
2722018-04-14 source: Int32(3)