2
* ExtInt32 - Extended 32-bit integers
3
* Copyright (C) 1996 Xavier Leroy
4
* 2007 Bluestorm <bluestorm dot dylc on-the-server gmail dot com>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version,
11
* with the special exception on linking described in file LICENSE.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
This module provides operations on the type [int32]
26
of signed 32-bit integers. Unlike the built-in [int] type,
27
the type [int32] is guaranteed to be exactly 32-bit wide on all
28
platforms. All arithmetic operations over [int32] are taken
31
Any integer literal followed by [l] is taken to be an [int32].
32
For instance, [1l] is {!Int32.one}.
36
Performance notice: values of type [int32] occupy more memory
37
space than values of type [int], and arithmetic operations on
38
[int32] are generally slower than those on [int]. Use [int32]
39
only when the application requires exact 32-bit arithmetic.
43
@author Xavier Leroy (base module)
44
@author Gabriel Scherer
53
(** The 32-bit integer 0. *)
56
(** The 32-bit integer 1. *)
59
(** The 32-bit integer -1. *)
61
external neg : int32 -> int32 = "%int32_neg"
62
(** Unary negation. *)
64
external add : int32 -> int32 -> int32 = "%int32_add"
67
external sub : int32 -> int32 -> int32 = "%int32_sub"
70
external mul : int32 -> int32 -> int32 = "%int32_mul"
71
(** Multiplication. *)
73
external div : int32 -> int32 -> int32 = "%int32_div"
74
(** Integer division. Raise [Division_by_zero] if the second
75
argument is zero. This division rounds the real quotient of
76
its arguments towards zero, as specified for {!Pervasives.(/)}. *)
78
external rem : int32 -> int32 -> int32 = "%int32_mod"
79
(** Integer remainder. If [y] is not zero, the result
80
of [Int32.rem x y] satisfies the following property:
81
[x = Int32.add (Int32.mul (Int32.div x y) y) (Int32.rem x y)].
82
If [y = 0], [Int32.rem x y] raises [Division_by_zero]. *)
85
val modulo : int32 -> int32 -> int32
86
val pow : int32 -> int32 -> int32
90
val succ : int32 -> int32
91
(** Successor. [Int32.succ x] is [Int32.add x Int32.one]. *)
93
val pred : int32 -> int32
94
(** Predecessor. [Int32.pred x] is [Int32.sub x Int32.one]. *)
96
val abs : int32 -> int32
97
(** Return the absolute value of its argument. *)
100
(** The greatest representable 32-bit integer, 2{^31} - 1. *)
103
(** The smallest representable 32-bit integer, -2{^31}. *)
106
external logand : int32 -> int32 -> int32 = "%int32_and"
107
(** Bitwise logical and. *)
109
external logor : int32 -> int32 -> int32 = "%int32_or"
110
(** Bitwise logical or. *)
112
external logxor : int32 -> int32 -> int32 = "%int32_xor"
113
(** Bitwise logical exclusive or. *)
115
val lognot : int32 -> int32
116
(** Bitwise logical negation *)
118
external shift_left : int32 -> int -> int32 = "%int32_lsl"
119
(** [Int32.shift_left x y] shifts [x] to the left by [y] bits.
120
The result is unspecified if [y < 0] or [y >= 32]. *)
122
external shift_right : int32 -> int -> int32 = "%int32_asr"
123
(** [Int32.shift_right x y] shifts [x] to the right by [y] bits.
124
This is an arithmetic shift: the sign bit of [x] is replicated
125
and inserted in the vacated bits.
126
The result is unspecified if [y < 0] or [y >= 32]. *)
128
external shift_right_logical : int32 -> int -> int32 = "%int32_lsr"
129
(** [Int32.shift_right_logical x y] shifts [x] to the right by [y] bits.
130
This is a logical shift: zeroes are inserted in the vacated bits
131
regardless of the sign of [x].
132
The result is unspecified if [y < 0] or [y >= 32]. *)
134
val ( -- ) : t -> t -> t Enum.t
135
(** Enumerate an interval.
137
[5l -- 10l] is the enumeration 5l,6l,7l,8l,9l,10l.
138
[10l -- 5l] is the empty enumeration*)
140
val ( --- ) : t -> t -> t Enum.t
141
(** Enumerate an interval.
143
[5l -- 10l] is the enumeration 5l,6l,7l,8l,9l,10l.
144
[10l -- 5l] is the enumeration 10l,9l,8l,7l,6l,5l.*)
146
external of_int : int -> int32 = "%int32_of_int"
147
(** Convert the given integer (type [int]) to a 32-bit integer
150
external to_int : int32 -> int = "%int32_to_int"
151
(** Convert the given 32-bit integer (type [int32]) to an
152
integer (type [int]). On 32-bit platforms, the 32-bit integer
153
is taken modulo 2{^31}, i.e. the high-order bit is lost
154
during the conversion. On 64-bit platforms, the conversion
157
external of_float : float -> int32 = "caml_int32_of_float"
158
(** Convert the given floating-point number to a 32-bit integer,
159
discarding the fractional part (truncate towards 0).
160
The result of the conversion is undefined if, after truncation,
161
the number is outside the range \[{!Int32.min_int}, {!Int32.max_int}\]. *)
163
external to_float : int32 -> float = "caml_int32_to_float"
164
(** Convert the given 32-bit integer to a floating-point number. *)
166
external of_string : string -> int32 = "caml_int32_of_string"
167
(** Convert the given string to a 32-bit integer.
168
The string is read in decimal (by default) or in hexadecimal,
169
octal or binary if the string begins with [0x], [0o] or [0b]
171
Raise [Failure "int_of_string"] if the given string is not
172
a valid representation of an integer, or if the integer represented
173
exceeds the range of integers representable in type [int32]. *)
175
val to_string : int32 -> string
176
(** Return the string representation of its argument, in signed decimal. *)
178
external bits_of_float : float -> int32 = "caml_int32_bits_of_float"
179
(** Return the internal representation of the given float according
180
to the IEEE 754 floating-point ``single format'' bit layout.
181
Bit 31 of the result represents the sign of the float;
182
bits 30 to 23 represent the (biased) exponent; bits 22 to 0
183
represent the mantissa. *)
185
external float_of_bits : int32 -> float = "caml_int32_float_of_bits"
186
(** Return the floating-point number whose internal representation,
187
according to the IEEE 754 floating-point ``single format'' bit layout,
188
is the given [int32]. *)
191
val compare: t -> t -> int
192
(** The comparison function for 32-bit integers, with the same specification as
193
{!Pervasives.compare}. Along with the type [t], this function [compare]
194
allows the module [Int32] to be passed as argument to the functors
195
{!Set.Make} and {!Map.Make}. *)
199
(** {6 Deprecated functions} *)
201
external format : string -> int32 -> string = "caml_int32_format"
202
(** [Int32.format fmt n] return the string representation of the
203
32-bit integer [n] in the format specified by [fmt].
204
[fmt] is a [Printf]-style format consisting of exactly
205
one [%d], [%i], [%u], [%x], [%X] or [%o] conversion specification.
206
This function is deprecated; use {!Printf.sprintf} with a [%lx] format
209
val ( + ) : t -> t -> t
210
val ( - ) : t -> t -> t
211
val ( * ) : t -> t -> t
212
val ( / ) : t -> t -> t
213
val ( ** ) : t -> t -> t
214
val ( <> ) : t -> t -> bool
215
val ( >= ) : t -> t -> bool
216
val ( <= ) : t -> t -> bool
217
val ( > ) : t -> t -> bool
218
val ( < ) : t -> t -> bool
219
val ( = ) : t -> t -> bool
220
val operations : t Number.numeric
223
(** {6 Boilerplate code}*)
224
(** {7 S-Expressions}*)
225
val t_of_sexp : Sexplib.Sexp.t -> t
226
val sexp_of_t : t -> Sexplib.Sexp.t
229
val print: 'a InnerIO.output -> t -> unit
230
val t_printer : t Value_printer.t