mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
feat(int): add elements of Int module from the std
This commit is contained in:
parent
5dd90edafa
commit
8f5c7c8fe9
2 changed files with 128 additions and 3 deletions
|
|
@ -6,6 +6,30 @@ open CCShims_
|
||||||
type t = int
|
type t = int
|
||||||
type 'a iter = ('a -> unit) -> unit
|
type 'a iter = ('a -> unit) -> unit
|
||||||
|
|
||||||
|
let zero = 0
|
||||||
|
|
||||||
|
let one = 1
|
||||||
|
|
||||||
|
let minus_one = -1
|
||||||
|
|
||||||
|
let add = (+)
|
||||||
|
|
||||||
|
let sub = (-)
|
||||||
|
|
||||||
|
let mul = ( * )
|
||||||
|
|
||||||
|
let div = (/)
|
||||||
|
|
||||||
|
let succ = succ
|
||||||
|
|
||||||
|
let pred = pred
|
||||||
|
|
||||||
|
let abs = abs
|
||||||
|
|
||||||
|
let max_int = max_int
|
||||||
|
|
||||||
|
let min_int = min_int
|
||||||
|
|
||||||
let equal (a:int) b = Stdlib.(=) a b
|
let equal (a:int) b = Stdlib.(=) a b
|
||||||
|
|
||||||
let compare (a:int) b = compare a b
|
let compare (a:int) b = compare a b
|
||||||
|
|
@ -211,6 +235,8 @@ let of_string s =
|
||||||
|
|
||||||
let of_string_exn = Stdlib.int_of_string
|
let of_string_exn = Stdlib.int_of_string
|
||||||
|
|
||||||
|
let to_float = float_of_int
|
||||||
|
|
||||||
let of_float = int_of_float
|
let of_float = int_of_float
|
||||||
|
|
||||||
(*$=
|
(*$=
|
||||||
|
|
@ -359,3 +385,17 @@ let popcount (b:int) : int =
|
||||||
);
|
);
|
||||||
true)
|
true)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
let logand = (land)
|
||||||
|
|
||||||
|
let logor = (lor)
|
||||||
|
|
||||||
|
let logxor = (lxor)
|
||||||
|
|
||||||
|
let lognot = lnot
|
||||||
|
|
||||||
|
let shift_left = (lsl)
|
||||||
|
|
||||||
|
let shift_right = (asr)
|
||||||
|
|
||||||
|
let shift_right_logical = (lsr)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,55 @@
|
||||||
|
|
||||||
type t = int
|
type t = int
|
||||||
|
|
||||||
|
val zero : t
|
||||||
|
(** [zero] is the integer [0].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val one : t
|
||||||
|
(** [one] is the integer [1].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val minus_one : t
|
||||||
|
(** [minus_one] is the integer [-1].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val add : t -> t -> t
|
||||||
|
(** [add x y] is [x + y].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val sub : t -> t -> t
|
||||||
|
(** [sub x y] is [x - y].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val mul : t -> t -> t
|
||||||
|
(** [mul x y] is [x * y].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val div : t -> t -> t
|
||||||
|
(** [div x y] is [x / y]
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val succ : t -> t
|
||||||
|
(** [succ x] is [x + 1].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val pred : t -> t
|
||||||
|
(** [pred x] is [x - 1].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val abs : t -> t
|
||||||
|
(** [abs x] is the absolute value of [x]. It is [x] if [x] is positive
|
||||||
|
and [neg x] otherwise.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val max_int : t
|
||||||
|
(** [max_int] is the maximum integer.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val min_int : t
|
||||||
|
(** [min_int] is the minimum integer.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val compare : t -> t -> int
|
val compare : t -> t -> int
|
||||||
(** [compare x y] is the comparison function for integers
|
(** [compare x y] is the comparison function for integers
|
||||||
with the same specification as {!Stdlib.compare}. *)
|
with the same specification as {!Stdlib.compare}. *)
|
||||||
|
|
@ -51,6 +100,14 @@ val random_range : int -> int -> t random_gen
|
||||||
val pp : t printer
|
val pp : t printer
|
||||||
(** [pp ppf x] prints the integer [x] on [ppf]. *)
|
(** [pp ppf x] prints the integer [x] on [ppf]. *)
|
||||||
|
|
||||||
|
val to_float : t -> float
|
||||||
|
(** [to_float] is the same as [float_of_int]
|
||||||
|
@since NEXT_RELEASE*)
|
||||||
|
|
||||||
|
val of_float : float -> t
|
||||||
|
(** [to_float] is the same as [int_of_float]
|
||||||
|
@since NEXT_RELEASE*)
|
||||||
|
|
||||||
val to_string : t -> string
|
val to_string : t -> string
|
||||||
(** [to_string x] returns the string representation of the integer [x], in signed decimal.
|
(** [to_string x] returns the string representation of the integer [x], in signed decimal.
|
||||||
@since 0.13 *)
|
@since 0.13 *)
|
||||||
|
|
@ -109,6 +166,34 @@ val popcount : t -> int
|
||||||
(** Number of bits set to 1
|
(** Number of bits set to 1
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val logand : t -> t -> t
|
||||||
|
(** [logand] is the same as [(land)].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val logor : t -> t -> t
|
||||||
|
(** [logand] is the same as [(lor)].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val logxor : t -> t -> t
|
||||||
|
(** [logxor] is the same as [(lxor)].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val lognot : t -> t
|
||||||
|
(** [logand] is the same as [lnot].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val shift_left : t -> int -> t
|
||||||
|
(** [shift_left] is the same as [(lsl)].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val shift_right : t -> int -> t
|
||||||
|
(** [shift_right] is the same as [(asr)].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val shift_right_logical : t -> int -> t
|
||||||
|
(** [shift_right_logical] is the same as [(lsr)].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
(** {2 Infix Operators}
|
(** {2 Infix Operators}
|
||||||
|
|
||||||
@since 0.17 *)
|
@since 0.17 *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue