~ubuntu-branches/ubuntu/precise/ocaml-batteries/precise

« back to all changes in this revision

Viewing changes to src/core/extlib/extInt32.mli

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2010-03-06 16:03:38 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100306160338-spvwiv3uc4jr28hw
Tags: 1.1.0-1
* New upstream release
  - major changes, "diet" version of the library
  - fix old FTBFS error, due to major code changes (Closes: #569455)
* Revamp packaging
  - adapt to new stuff shipped by upstream
  - switch from CDBS to dh
  - adapt dependencies (generally: reduce them)
* debian/patches/
  - remove old debian/patches/{debian-specific-installation-paths,
    debian-specific-info-on-doc-availability} as obsolete
  - new patch 0001-install-fix-for-bytecode-only-build: avoid
    installing *.a files with bytecode only compilation
* debian/libbatteries-ocaml-dev.links: remove file, shortend
  /usr/bin/ocaml-batteries to the top-level no longer exists
* remove debian/README.Debian (previous content is now obsolete)
* bump Standards-Version to 3.8.4 (no changes needed)
* debian/watch: update to match new upstream version convention
* debian/libbatteries-ocaml-{dev,doc}.{docs,examples}: ship only doc
  file from the root dir, other stuff is currently out of date
  (Closes: #514265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(* 
2
 
 * ExtInt32 - Extended 32-bit integers
3
 
 * Copyright (C) 1996 Xavier Leroy 
4
 
 *               2007 Bluestorm <bluestorm dot dylc on-the-server gmail dot com>
5
 
 *               2008 David Teller
6
 
 * 
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.
12
 
 *
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.
17
 
 *
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
21
 
 *)
22
 
 
23
 
(** 32-bit integers.
24
 
 
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
29
 
    modulo 2{^32}.
30
 
 
31
 
    Any integer literal followed by [l] is taken to be an [int32].
32
 
    For instance, [1l] is {!Int32.one}.
33
 
 
34
 
 
35
 
 
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. 
40
 
 
41
 
    @documents Int32
42
 
    
43
 
    @author Xavier Leroy (base module)
44
 
    @author Gabriel Scherer
45
 
    @author David Teller
46
 
*)
47
 
module Int32 :
48
 
  sig
49
 
 
50
 
    type t = int32
51
 
 
52
 
    val zero : int32
53
 
      (** The 32-bit integer 0. *)
54
 
      
55
 
    val one : int32
56
 
      (** The 32-bit integer 1. *)
57
 
 
58
 
    val minus_one : int32
59
 
      (** The 32-bit integer -1. *)
60
 
 
61
 
    external neg : int32 -> int32 = "%int32_neg"
62
 
      (** Unary negation. *)
63
 
 
64
 
    external add : int32 -> int32 -> int32 = "%int32_add"
65
 
      (** Addition. *)
66
 
 
67
 
    external sub : int32 -> int32 -> int32 = "%int32_sub"
68
 
      (** Subtraction. *)
69
 
 
70
 
    external mul : int32 -> int32 -> int32 = "%int32_mul"
71
 
      (** Multiplication. *)
72
 
 
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.(/)}. *)
77
 
      
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]. *)
83
 
      
84
 
 
85
 
    val modulo : int32 -> int32 -> int32
86
 
    val pow  : int32 -> int32 -> int32
87
 
    val min_num : int32
88
 
    val max_num : int32
89
 
 
90
 
    val succ : int32 -> int32
91
 
      (** Successor.  [Int32.succ x] is [Int32.add x Int32.one]. *)
92
 
      
93
 
    val pred : int32 -> int32
94
 
      (** Predecessor.  [Int32.pred x] is [Int32.sub x Int32.one]. *)
95
 
      
96
 
    val abs : int32 -> int32
97
 
      (** Return the absolute value of its argument. *)
98
 
      
99
 
    val max_int : int32
100
 
      (** The greatest representable 32-bit integer, 2{^31} - 1. *)
101
 
      
102
 
    val min_int : int32
103
 
      (** The smallest representable 32-bit integer, -2{^31}. *)
104
 
      
105
 
      
106
 
    external logand : int32 -> int32 -> int32 = "%int32_and"
107
 
      (** Bitwise logical and. *)
108
 
      
109
 
    external logor : int32 -> int32 -> int32 = "%int32_or"
110
 
      (** Bitwise logical or. *)
111
 
      
112
 
    external logxor : int32 -> int32 -> int32 = "%int32_xor"
113
 
      (** Bitwise logical exclusive or. *)
114
 
      
115
 
    val lognot : int32 -> int32
116
 
      (** Bitwise logical negation *)
117
 
      
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]. *)
121
 
      
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]. *)
127
 
      
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]. *)
133
 
 
134
 
    val ( -- ) : t -> t -> t Enum.t
135
 
      (** Enumerate an interval.
136
 
          
137
 
          [5l -- 10l] is the enumeration 5l,6l,7l,8l,9l,10l.
138
 
          [10l -- 5l] is the empty enumeration*)
139
 
 
140
 
    val ( --- ) : t -> t -> t Enum.t
141
 
      (** Enumerate an interval.
142
 
          
143
 
          [5l -- 10l] is the enumeration 5l,6l,7l,8l,9l,10l.
144
 
          [10l -- 5l] is the enumeration 10l,9l,8l,7l,6l,5l.*)
145
 
      
146
 
    external of_int : int -> int32 = "%int32_of_int"
147
 
      (** Convert the given integer (type [int]) to a 32-bit integer
148
 
          (type [int32]). *)
149
 
      
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
155
 
          is exact. *)
156
 
      
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}\]. *)
162
 
      
163
 
    external to_float : int32 -> float = "caml_int32_to_float"
164
 
      (** Convert the given 32-bit integer to a floating-point number. *)
165
 
      
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]
170
 
          respectively.
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]. *)
174
 
      
175
 
    val to_string : int32 -> string
176
 
      (** Return the string representation of its argument, in signed decimal. *)
177
 
      
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. *)
184
 
      
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]. *)
189
 
 
190
 
        
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}. *)
196
 
      
197
 
    (**/**)
198
 
      
199
 
    (** {6 Deprecated functions} *)
200
 
      
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
207
 
          instead. *)
208
 
 
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
221
 
 
222
 
 
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
227
 
 
228
 
    (** {7 Printing}*)
229
 
    val print: 'a InnerIO.output -> t -> unit
230
 
    val t_printer : t Value_printer.t
231
 
  end