add CCInt{32,64}.Infix

This commit is contained in:
Simon Cruanes 2018-02-27 21:07:01 -06:00
parent 4a317e57c1
commit 9f2ef2f461
4 changed files with 123 additions and 54 deletions

View file

@ -2,34 +2,45 @@
include Int32 include Int32
let (+) = add
let (-) = sub
let (~-) = neg
let ( * ) = mul
let (/) = div
let (mod) = rem
let (land) = logand
let (lor) = logor
let (lxor) = logxor
let lnot = lognot
let (lsl) = shift_left
let (lsr) = shift_right_logical
let (asr) = shift_right
let equal (x:t) y = Pervasives.(=) x y let equal (x:t) y = Pervasives.(=) x y
module Infix = struct
let (+) = add
let (-) = sub
let (~-) = neg
let ( * ) = mul
let (/) = div
let (mod) = rem
let (land) = logand
let (lor) = logor
let (lxor) = logxor
let lnot = lognot
let (lsl) = shift_left
let (lsr) = shift_right_logical
let (asr) = shift_right
let (=) = equal
let (<>) = Pervasives.(<>)
let (<) = Pervasives.(<)
let (<=) = Pervasives.(<=)
let (>) = Pervasives.(>)
let (>=) = Pervasives.(>=)
end
include Infix
let hash x = Pervasives.abs (to_int x) let hash x = Pervasives.abs (to_int x)
(** {2 Conversion} *) (** {2 Conversion} *)

View file

@ -9,8 +9,8 @@
32-bit wide on all platforms. All arithmetic operations over int32 are taken 32-bit wide on all platforms. All arithmetic operations over int32 are taken
modulo 2{^32}. modulo 2{^32}.
Performance notice: values of type int32 occupy more memory space than values Performance notice: values of type int32 occupy more memory space than values
of type int, and arithmetic operations on int32 are generally slower than of type int, and arithmetic operations on int32 are generally slower than
those on int. Use int32 only when the application requires exact 32-bit arithmetic. those on int. Use int32 only when the application requires exact 32-bit arithmetic.
@since NEXT_RELEASE *) @since NEXT_RELEASE *)
@ -68,6 +68,28 @@ val ( asr ) : t -> int -> t
and inserted in the vacated bits. and inserted in the vacated bits.
The result is unspecified if [y < 0] or [y >= 32]. *) The result is unspecified if [y < 0] or [y >= 32]. *)
module Infix : sig
val (+) : t -> t -> t
val (-) : t -> t -> t
val (~-) : t -> t
val ( * ) : t -> t -> t
val (/) : t -> t -> t
val (mod) : t -> t -> t
val (land) : t -> t -> t
val (lor) : t -> t -> t
val (lxor) : t -> t -> t
val lnot : t -> t
val (lsl) : t -> int -> t
val (lsr) : t -> int -> t
val (asr) : t -> int -> t
val (=) : t -> t -> bool
val (<>) : t -> t -> bool
val (>) : t -> t -> bool
val (>=) : t -> t -> bool
val (<=) : t -> t -> bool
val (<) : t -> t -> bool
end
val equal : t -> t -> bool val equal : t -> t -> bool
(** The equal function for 32-bit integers. (** The equal function for 32-bit integers.
Like {!Pervasives.(=) x y)}. *) Like {!Pervasives.(=) x y)}. *)

View file

@ -2,34 +2,46 @@
include Int64 include Int64
let (+) = add
let (-) = sub
let (~-) = neg
let ( * ) = mul
let (/) = div
let (mod) = rem
let (land) = logand
let (lor) = logor
let (lxor) = logxor
let lnot = lognot
let (lsl) = shift_left
let (lsr) = shift_right_logical
let (asr) = shift_right
let equal (x:t) y = Pervasives.(=) x y let equal (x:t) y = Pervasives.(=) x y
module Infix = struct
let (+) = add
let (-) = sub
let (~-) = neg
let ( * ) = mul
let (/) = div
let (mod) = rem
let (land) = logand
let (lor) = logor
let (lxor) = logxor
let lnot = lognot
let (lsl) = shift_left
let (lsr) = shift_right_logical
let (asr) = shift_right
let (=) = equal
let (<>) = Pervasives.(<>)
let (<) = Pervasives.(<)
let (<=) = Pervasives.(<=)
let (>) = Pervasives.(>)
let (>=) = Pervasives.(>=)
end
include Infix
let hash x = Pervasives.abs (to_int x) let hash x = Pervasives.abs (to_int x)
(** {2 Conversion} *) (** {2 Conversion} *)

View file

@ -66,6 +66,30 @@ val (asr) : t -> int -> t
and inserted in the vacated bits. and inserted in the vacated bits.
The result is unspecified if [y < 0] or [y >= 64]. *) The result is unspecified if [y < 0] or [y >= 64]. *)
(** Infix operators
@since NEXT_RELEASE *)
module Infix : sig
val (+) : t -> t -> t
val (-) : t -> t -> t
val (~-) : t -> t
val ( * ) : t -> t -> t
val (/) : t -> t -> t
val (mod) : t -> t -> t
val (land) : t -> t -> t
val (lor) : t -> t -> t
val (lxor) : t -> t -> t
val lnot : t -> t
val (lsl) : t -> int -> t
val (lsr) : t -> int -> t
val (asr) : t -> int -> t
val (=) : t -> t -> bool
val (<>) : t -> t -> bool
val (>) : t -> t -> bool
val (>=) : t -> t -> bool
val (<=) : t -> t -> bool
val (<) : t -> t -> bool
end
val equal : t -> t -> bool val equal : t -> t -> bool
(** The equal function for 64-bit integers. (** The equal function for 64-bit integers.
Like {!Pervasives.(=) x y)}. *) Like {!Pervasives.(=) x y)}. *)