1 (** 63 bit signed integer type *)
2 (* (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version,
8 with the OCaml linking exception described in ../COPYING.LIB.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 (** This module deals with creating an efficient 63 bit signed integer
23 In OCaml, the basic [int] type is fast because it is unboxed, but
24 it has a different size on 32 and 64 bit platforms (31 and 63 bits
25 respectively). If we want a large integer type we can use the
26 OCaml [int64] type, but that is boxed and hence operations are
27 slow, even on 64 bit platforms.
29 This type gives us a large integer (up to 63 bits, therefore fine
30 for things involving eg. large disk file sizes), but retains
31 efficiency. On 64 bit platforms it degenerates into just a normal
32 [int], hence unboxed and fast. On 32 bit platforms it degenerates
33 to a kind of [int64], which is boxed and slow but hey 32 bit
34 platforms are going the way of all things anyway.
36 The implementation of this type is in the files [int63_on_32.ml]
37 or [int63_on_64.ml] for 32 bit and 64 bit platforms respectively.
38 The appropriate implementation is copied by the Makefile to
44 For reasons not fully understood, we need to declare this
45 type explicitly in order to get properly optimized operations.
46 This means the user of a 64 bit platform must be careful not to
47 accidentally write code which depends on [t] being an [int],
48 but should treat this as an opaque type.
55 It is recommended to do:
61 in your code so that you get the operators [+^], [-^] .. and the
62 type [int63] directly, and can still use the less frequent
63 functions such as {!Int63.abs} etc.
66 module Operators : sig
69 (* For the gory details of the rules of operators, see:
70 * http://caml.inria.fr/pub/docs/manual-ocaml/lex.html
73 val ( +^ ) : t -> t -> t
74 val ( -^ ) : t -> t -> t
75 val ( *^ ) : t -> t -> t
76 val ( /^ ) : t -> t -> t
77 val ( %^ ) : t -> t -> t
78 (** Infix arithmetic operators. eg. [a +^ b -^ c] *)
80 val ( <^< ) : t -> int -> t
81 val ( >^> ) : t -> int -> t
82 (** Infix shift left and logical shift right.
85 NB: We cannot use two less-than signs or two greater-than signs
86 in a row because that clashes with the symbols used for
89 val ( &^ ) : t -> t -> t
90 val ( |^ ) : t -> t -> t
91 val ( ^^ ) : t -> t -> t
92 (** Infix logical and, or and xor operators.
96 (** Small integer constants,
97 eg. [~^0] is the constant zero and [~^1] is the constant one. *)
98 val ( ~^~ ) : int -> t
99 (** Small negative integer constants,
100 eg. [~^~1] is the constant minus one. *)
105 These functions are analogous to the similarly named
106 functions available in the standard library [Int32] and
112 (** Some constants. *)
117 val add : t -> t -> t
118 val sub : t -> t -> t
119 val mul : t -> t -> t
120 val div : t -> t -> t
121 val rem : t -> t -> t
130 (** Absolute value. *)
133 (** The constant 2{^62}-1. *)
135 (** The constant -2{^62}. *)
137 val logand : t -> t -> t
138 val logor : t -> t -> t
139 val logxor : t -> t -> t
141 (** Bitwise logical and, or, xor and not. *)
143 val shift_left : t -> int -> t
144 (** Shift the number left by the integer number of bits. *)
145 val shift_right : t -> int -> t
146 (** Arithmetic shift the number right by the integer number of bits.
147 The sign bit is replicated into the vacated bits. *)
148 val shift_right_logical : t -> int -> t
149 (** Logical shift the number right by the integer number of bits.
150 The vacated bits are filled with bit [0] regardless of sign. *)
152 val of_int : int -> t
153 val to_int : t -> int
154 val of_float : float -> t
155 val to_float : t -> float
156 val of_int32 : int32 -> t
157 val to_int32 : t -> int32
158 val of_int64 : int64 -> t
159 val to_int64 : t -> int64
160 val of_nativeint : nativeint -> t
161 val to_nativeint : t -> nativeint
162 (** Convert between t and various standard types. *)
164 val of_string : string -> t
165 val to_string : t -> string
166 (** Convert between string. *)
168 val compare : t -> t -> int
169 (** Compare two numbers. *)