(** {2 Operators}
- It is recommended to do [open Int63.Operators] in your code
- so that you get the operators [+^], [-^] .. and the type [int63]
- directly, and can still use the less frequent functions
- as [Int63.logand] etc.
+ It is recommended to do:
+
+{[
+open Int63.Operators
+]}
+
+ in your code so that you get the operators [+^], [-^] .. and the
+ type [int63] directly, and can still use the less frequent
+ functions as {!Int63.logand} etc.
*)
module Operators : sig
type int63 = t
+ (* For the gory details of the rules of operators, see:
+ * http://caml.inria.fr/pub/docs/manual-ocaml/lex.html
+ *)
+
val ( +^ ) : t -> t -> t
val ( -^ ) : t -> t -> t
val ( *^ ) : t -> t -> t
val ( /^ ) : t -> t -> t
- (** Arithmetic operators. *)
+ val ( %^ ) : t -> t -> t
+ (** Infix arithmetic operators. eg. [a +^ b -^ c] *)
+
+ val ( <^< ) : t -> int -> t
+ val ( >^> ) : t -> int -> t
+ (** Infix shift left and logical shift right.
+ eg. [~^1 <^< 62]
+
+ NB: We cannot use two less-than signs or two greater-than signs
+ in a row because that clashes with the symbols used for
+ camlp4 quotations. *)
- val ( <<^ ) : t -> int -> t
- val ( >>^ ) : t -> int -> t
- (** Shift left and logical shift right. *)
+ val ( &&^ ) : t -> t -> t
+ val ( ||^ ) : t -> t -> t
+ val ( ^^^ ) : t -> t -> t
+ (** Infix logical and, or and xor operators.
+ eg. [bits &&^ mask] *)
val ( ~^ ) : int -> t
- (** Constant, eg. [~^0] is the constant zero. *)
+ (** Small integer constants,
+ eg. [~^0] is the constant zero and [~^1] is the constant one. *)
val ( ~^~ ) : int -> t
- (** Negative constant, eg. [~^~1] is the constant minus one. *)
+ (** Small negative integer constants,
+ eg. [~^~1] is the constant minus one. *)
end
(** {2 Functions}
(** Absolute value. *)
val max_int : t
- (** The constant [2{^62}-1]. *)
+ (** The constant 2{^62}-1. *)
val min_int : t
- (** The constant [-2{^62}]. *)
+ (** The constant -2{^62}. *)
val logand : t -> t -> t
val logor : t -> t -> t
external ( -^ ) : int64 -> int64 -> int64 = "%int64_sub"
external ( *^ ) : int64 -> int64 -> int64 = "%int64_mul"
external ( /^ ) : int64 -> int64 -> int64 = "%int64_div"
- external ( <<^ ) : int64 -> int -> int64 = "%int64_lsl"
- external ( >>^ ) : int64 -> int -> int64 = "%int64_lsr"
+ external ( %^ ) : int64 -> int64 -> int64 = "%int64_mod"
+ external ( <^< ) : int64 -> int -> int64 = "%int64_lsl"
+ external ( >^> ) : int64 -> int -> int64 = "%int64_lsr"
+ external ( &&^ ) : int64 -> int64 -> int64 = "%int64_and"
+ external ( ||^ ) : int64 -> int64 -> int64 = "%int64_or"
+ external ( ^^^ ) : int64 -> int64 -> int64 = "%int64_xor"
external ( ~^ ) : int -> int64 = "%int64_of_int"
let ( ~^~ ) i = Int64.neg (Int64.of_int i)
end
external ( -^ ) : int -> int -> int = "%subint"
external ( *^ ) : int -> int -> int = "%mulint"
external ( /^ ) : int -> int -> int = "%divint"
- external ( <<^ ) : int -> int -> int = "%lslint"
- external ( >>^ ) : int -> int -> int = "%lsrint"
+ external ( %^ ) : int -> int -> int = "%modint"
+ external ( <^< ) : int -> int -> int = "%lslint"
+ external ( >^> ) : int -> int -> int = "%lsrint"
+ external ( &&^ ) : int -> int -> int = "%andint"
+ external ( ||^ ) : int -> int -> int = "%orint"
+ external ( ^^^ ) : int -> int -> int = "%xorint"
external ( ~^ ) : int -> int = "%identity"
external ( ~^~ ) : int -> int = "%negint"
end