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
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 if the string begins with 0u ) or in hexadeci‐
207 mal, octal or binary if the string begins with 0x , 0o or 0b respec‐
208 tively.
209
210 The 0u prefix reads the input as an unsigned integer in the range [0,
211 2*Int32.max_int+1] . If the input exceeds Int32.max_int it is con‐
212 verted to the signed integer Int32.min_int + input - Int32.max_int - 1
213 .
214
215 The _ (underscore) character can appear anywhere in the string and is
216 ignored. Raise Failure Int32.of_string if the given string is not a
217 valid representation of an integer, or if the integer represented
218 exceeds the range of integers representable in type int32 .
219
220
221
222 val of_string_opt : string -> int32 option
223
224 Same as of_string , but return None instead of raising.
225
226
227 Since 4.05
228
229
230
231 val to_string : int32 -> string
232
233 Return the string representation of its argument, in signed decimal.
234
235
236
237 val bits_of_float : float -> int32
238
239 Return the internal representation of the given float according to the
240 IEEE 754 floating-point 'single format' bit layout. Bit 31 of the
241 result represents the sign of the float; bits 30 to 23 represent the
242 (biased) exponent; bits 22 to 0 represent the mantissa.
243
244
245
246 val float_of_bits : int32 -> float
247
248 Return the floating-point number whose internal representation, accord‐
249 ing to the IEEE 754 floating-point 'single format' bit layout, is the
250 given int32 .
251
252
253 type t = int32
254
255
256 An alias for the type of 32-bit integers.
257
258
259
260 val compare : t -> t -> int
261
262 The comparison function for 32-bit integers, with the same specifica‐
263 tion as Pervasives.compare . Along with the type t , this function
264 compare allows the module Int32 to be passed as argument to the func‐
265 tors Set.Make and Map.Make .
266
267
268
269 val equal : t -> t -> bool
270
271 The equal function for int32s.
272
273
274 Since 4.03.0
275
276
277
278
279
280OCamldoc 2019-02-02 Int32(3)