diff --git a/src/core/CCArray.ml b/src/core/CCArray.ml index 00c57142d..85d498fd0 100644 --- a/src/core/CCArray.ml +++ b/src/core/CCArray.ml @@ -455,15 +455,6 @@ let pp_i ?(pp_start = fun _ () -> ()) ?(pp_stop = fun _ () -> ()) let to_string ?(sep = ", ") item_to_string a = Array.to_list a |> List.map item_to_string |> String.concat sep -let to_seq a = - let rec aux i () = - if i >= length a then - Seq.Nil - else - Seq.Cons (a.(i), aux (i + 1)) - in - aux 0 - let to_iter a k = iter k a let to_gen a = diff --git a/src/core/CCArray.mli b/src/core/CCArray.mli index d19d42523..8d9c14e52 100644 --- a/src/core/CCArray.mli +++ b/src/core/CCArray.mli @@ -240,14 +240,6 @@ val to_iter : 'a t -> 'a iter in modification of the iterator. @since 2.8 *) -val to_seq : 'a t -> 'a Seq.t -(** [to_seq a] returns a [Seq.t] of the elements of an array [a]. - The input array [a] is shared with the sequence and modification of it will result - in modification of the sequence. - Renamed from [to_std_seq] since 3.0. - @since 3.0 -*) - val to_gen : 'a t -> 'a gen (** [to_gen a] returns a [gen] of the elements of an array [a]. *) diff --git a/src/core/CCArrayLabels.mli b/src/core/CCArrayLabels.mli index 8663c7ddd..2a1f705f6 100644 --- a/src/core/CCArrayLabels.mli +++ b/src/core/CCArrayLabels.mli @@ -219,13 +219,6 @@ val fold2 : f:('acc -> 'a -> 'b -> 'acc) -> init:'acc -> 'a t -> 'b t -> 'acc @raise Invalid_argument if [a] and [b] have distinct lengths. @since 0.20 *) -val iter2 : f:('a -> 'b -> unit) -> 'a t -> 'b t -> unit -(** [iter2 ~f a b] iterates on the two arrays [a] and [b] stepwise. - It is equivalent to [f a0 b0; …; f a.(length a - 1) b.(length b - 1); ()]. - - @raise Invalid_argument if [a] and [b] have distinct lengths. - @since 0.20 *) - val shuffle : 'a t -> unit (** [shuffle a] randomly shuffles the array [a], in place. *) @@ -248,14 +241,6 @@ val to_iter : 'a t -> 'a iter in modification of the iterator. @since 2.8 *) -val to_seq : 'a t -> 'a Seq.t -(** [to_seq a] returns a [Seq.t] of the elements of an array [a]. - The input array [a] is shared with the sequence and modification of it will result - in modification of the sequence. - Renamed from [to_std_seq] since 3.0. - @since 3.0 -*) - val to_gen : 'a t -> 'a gen (** [to_gen a] returns a [gen] of the elements of an array [a]. *) @@ -286,14 +271,6 @@ val pp_i : By defaults [pp_start] and [pp_stop] does nothing and [pp_sep] defaults to (fun out -> Format.fprintf out ",@ "). *) -val map2 : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t -(** [map2 ~f a b] applies function [f] to all elements of [a] and [b], - and builds an array with the results returned by [f]: - [[| f a.(0) b.(0); …; f a.(length a - 1) b.(length b - 1)|]]. - - @raise Invalid_argument if [a] and [b] have distinct lengths. - @since 0.20 *) - val rev : 'a t -> 'a t (** [rev a] copies the array [a] and reverses it in place. @since 0.20 *) @@ -308,7 +285,7 @@ val filter_map : f:('a -> 'b option) -> 'a t -> 'b t element of [a] is discarded. *) val monoid_product : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t -(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b] +(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b] to the function [f]. @since 2.8 *) diff --git a/src/core/CCBool.ml b/src/core/CCBool.ml index 9166bd7bd..a55dad8d7 100644 --- a/src/core/CCBool.ml +++ b/src/core/CCBool.ml @@ -1,17 +1,7 @@ (* This file is free software, part of containers. See file "license" for more details. *) - -type t = bool - -let equal (a : bool) b = Stdlib.( = ) a b -let compare (a : bool) b = Stdlib.compare a b - -let to_int (x : bool) : int = - if x then - 1 - else - 0 +include Bool let of_int x : t = x <> 0 diff --git a/src/core/CCBool.mli b/src/core/CCBool.mli index 9fda5922d..b4a1473a2 100644 --- a/src/core/CCBool.mli +++ b/src/core/CCBool.mli @@ -2,17 +2,8 @@ (** Basic Bool functions *) -type t = bool - -val compare : t -> t -> int -(** [compare b1 b2] is the total ordering on booleans [b1] and [b2], similar to {!Stdlib.compare}. *) - -val equal : t -> t -> bool -(** [equal b1 b2] is [true] if [b1] and [b2] are the same. *) - -val to_int : t -> int -(** [to_int true = 1], [to_int false = 0]. - @since 2.7 *) +include module type of Bool +(** @inline *) val of_int : int -> t (** [of_int i] is the same as [i <> 0] diff --git a/src/core/CCFloat.ml b/src/core/CCFloat.ml index f0a003de7..aadfd64f2 100644 --- a/src/core/CCFloat.ml +++ b/src/core/CCFloat.ml @@ -1,15 +1,6 @@ (* This file is free software, part of containers. See file "license" for more details. *) - - -type t = float - -type fpclass = Stdlib.fpclass = - | FP_normal - | FP_subnormal - | FP_zero - | FP_infinite - | FP_nan +include Float module Infix = struct let ( = ) : t -> t -> bool = Stdlib.( = ) @@ -29,47 +20,11 @@ include Infix [@@@ocaml.warning "-32"] -let nan = Stdlib.nan -let infinity = Stdlib.infinity -let neg_infinity = Stdlib.neg_infinity let max_value = infinity let min_value = neg_infinity let max_finite_value = Stdlib.max_float -let epsilon = Stdlib.epsilon_float -let pi = 0x1.921fb54442d18p+1 -let is_nan x = Stdlib.(classify_float x = Stdlib.FP_nan) -let add = ( +. ) -let sub = ( -. ) -let mul = ( *. ) -let div = ( /. ) -let neg = ( ~-. ) -let abs = Stdlib.abs_float let scale = ( *. ) -let min (x : t) y = - match Stdlib.classify_float x, Stdlib.classify_float y with - | FP_nan, _ -> y - | _, FP_nan -> x - | _ -> - if x < y then - x - else - y - -let max (x : t) y = - match Stdlib.classify_float x, Stdlib.classify_float y with - | FP_nan, _ -> y - | _, FP_nan -> x - | _ -> - if x > y then - x - else - y - -let equal (a : float) b = a = b -let hash : t -> int = Hashtbl.hash -let compare (a : float) b = Stdlib.compare a b - [@@@ocaml.warning "+32"] type 'a printer = Format.formatter -> 'a -> unit @@ -93,22 +48,8 @@ let sign_exn (a : float) = else compare a 0. -let round x = - let low = floor x in - let high = ceil x in - if x -. low > high -. x then - high - else - low - -let to_int (a : float) = Stdlib.int_of_float a -let of_int (a : int) = Stdlib.float_of_int a -let to_string (a : float) = Stdlib.string_of_float a let of_string_exn (a : string) = Stdlib.float_of_string a -let of_string_opt (a : string) = - try Some (Stdlib.float_of_string a) with Failure _ -> None - let random n st = Random.State.float st n let random_small = random 100.0 let random_range i j st = i +. random (j -. i) st diff --git a/src/core/CCFloat.mli b/src/core/CCFloat.mli index 7a4b68f88..0781592f1 100644 --- a/src/core/CCFloat.mli +++ b/src/core/CCFloat.mli @@ -3,19 +3,7 @@ (** Basic operations on floating-point numbers @since 0.6.1 *) - - -type t = float - -type fpclass = Stdlib.fpclass = - | FP_normal - | FP_subnormal - | FP_zero - | FP_infinite - | FP_nan - -val nan : t -(** [nan] is Not a Number (NaN). Equal to {!Stdlib.nan}. *) +include module type of Float val max_value : t (** [max_value] is Positive infinity. Equal to {!Stdlib.infinity}. *) @@ -26,50 +14,13 @@ val min_value : t val max_finite_value : t (** [max_finite_value] is the largest finite float value. Equal to {!Stdlib.max_float}. *) -val epsilon : t -(** [epsilon] is the smallest positive float x such that [1.0 +. x <> 1.0]. - Equal to {!Stdlib.epsilon_float}. *) - -val pi : t -(** [pi] is the constant pi. The ratio of a circumference to its diameter. - @since 3.0 *) - -val is_nan : t -> bool -(** [is_nan f] returns [true] if f is NaN, [false] otherwise. *) - -val add : t -> t -> t -(** [add x y] is equal to [x +. y]. *) - -val sub : t -> t -> t -(** [sub x y] is equal to [x -. y]. *) - -val neg : t -> t -(** [neg x] is equal to [~-. x]. *) - -val abs : t -> t -(** [abs x] is the absolute value of the floating-point number [x]. - Equal to {!Stdlib.abs_float}. *) - val scale : t -> t -> t (** [scale x y] is equal to [x *. y]. *) -val min : t -> t -> t -(** [min x y] returns the min of the two given values [x] and [y]. *) - -val max : t -> t -> t -(** [max x y] returns the max of the two given values [x] and [y]. *) - -val equal : t -> t -> bool -(** [equal x y] is [true] if [x] and [y] are the same. *) - -val compare : t -> t -> int -(** [compare x y] is {!Stdlib.compare x y}. *) - type 'a printer = Format.formatter -> 'a -> unit type 'a random_gen = Random.State.t -> 'a val pp : t printer -val hash : t -> int val random : t -> t random_gen val random_small : t random_gen val random_range : t -> t -> t random_gen @@ -78,11 +29,6 @@ val fsign : t -> t (** [fsign x] is one of [-1., -0., +0., +1.], or [nan] if [x] is NaN. @since 0.7 *) -val round : t -> t -(** [round x] returns the closest integer value, either above or below. - For [n + 0.5], [round] returns [n]. - @since 0.20 *) - exception TrapNaN of string val sign_exn : t -> int @@ -91,23 +37,11 @@ val sign_exn : t -> int Note that infinities have defined signs in OCaml. @since 0.7 *) -val to_int : t -> int -(** Alias to {!int_of_float}. - Unspecified if outside of the range of integers. *) - -val of_int : int -> t -(** Alias to {!float_of_int}. *) - -val to_string : t -> string - val of_string_exn : string -> t (** Alias to {!float_of_string}. @raise Failure in case of failure. @since 1.2 *) -val of_string_opt : string -> t option -(** @since 3.0 *) - val equal_precision : epsilon:t -> t -> t -> bool (** Equality with allowed error up to a non negative epsilon value. *) diff --git a/src/core/CCInt.ml b/src/core/CCInt.ml index a2efe7bc6..7cf914c8c 100644 --- a/src/core/CCInt.ml +++ b/src/core/CCInt.ml @@ -2,24 +2,8 @@ include Int -type t = int 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 compare (a : int) b = compare a b - (* use FNV: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function *) let hash (n : int) : int = @@ -65,7 +49,6 @@ let range' i j yield = range i (j + 1) yield let sign i = compare i 0 -let neg i = -i let pow a b = let rec aux acc = function @@ -147,11 +130,8 @@ let random_small = random 100 let random_range i j st = i + random (j - i) st let pp fmt = Format.pp_print_int fmt let most_significant_bit = -1 lxor (-1 lsr 1) -let to_string = string_of_int let of_string s = try Some (int_of_string s) with Failure _ -> None let of_string_exn = Stdlib.int_of_string -let to_float = float_of_int -let of_float = int_of_float type output = char -> unit @@ -248,11 +228,3 @@ let popcount (b : int) : int = let b = add b (shift_right_logical b 32) in let b = logand b 0x7fL in to_int b - -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 ) diff --git a/src/core/CCInt.mli b/src/core/CCInt.mli index 65b01ef18..fb12bb900 100644 --- a/src/core/CCInt.mli +++ b/src/core/CCInt.mli @@ -5,65 +5,6 @@ include module type of Int (** @inline *) -type t = int - -val zero : t -(** [zero] is the integer [0]. - @since 3.0 *) - -val one : t -(** [one] is the integer [1]. - @since 3.0 *) - -val minus_one : t -(** [minus_one] is the integer [-1]. - @since 3.0 *) - -val add : t -> t -> t -(** [add x y] is [x + y]. - @since 3.0 *) - -val sub : t -> t -> t -(** [sub x y] is [x - y]. - @since 3.0 *) - -val mul : t -> t -> t -(** [mul x y] is [x * y]. - @since 3.0 *) - -val div : t -> t -> t -(** [div x y] is [x / y] - @since 3.0 *) - -val succ : t -> t -(** [succ x] is [x + 1]. - @since 3.0 *) - -val pred : t -> t -(** [pred x] is [x - 1]. - @since 3.0 *) - -val abs : t -> t -(** [abs x] is the absolute value of [x]. It is [x] if [x] is positive - and [neg x] otherwise. - @since 3.0 *) - -val max_int : t -(** [max_int] is the maximum integer. - @since 3.0 *) - -val min_int : t -(** [min_int] is the minimum integer. - @since 3.0 *) - -val compare : t -> t -> int -(** [compare x y] is the comparison function for integers - with the same specification as {!Stdlib.compare}. *) - -val equal : t -> t -> bool -(** [equal x y] is [true] iff [x] and [y] are equal. - Equality function for integers. *) - val hash : t -> int (** [hash x] computes the hash of [x]. *) @@ -71,11 +12,6 @@ val sign : t -> int (** [sign x] return [0] if [x = 0], [-1] if [x < 0] and [1] if [x > 0]. Same as [compare x 0].*) -val neg : t -> t -(** [neg x] is [- x]. - Unary negation. - @since 0.5 *) - val pow : t -> t -> t (** [pow base exponent] returns [base] raised to the power of [exponent]. [pow x y = x^y] for positive integers [x] and [y]. @@ -103,22 +39,6 @@ val random_range : int -> int -> t random_gen val pp : t printer (** [pp ppf x] prints the integer [x] on [ppf]. *) -val to_float : t -> float -(** [to_float] is the same as [float_of_int] - @since 3.0*) - -[@@@ocaml.warning "-32"] - -val of_float : float -> t -(** [to_float] is the same as [int_of_float] - @since 3.0*) - -[@@@ocaml.warning "+32"] - -val to_string : t -> string -(** [to_string x] returns the string representation of the integer [x], in signed decimal. - @since 0.13 *) - val of_string : string -> t option (** [of_string s] converts the given string [s] into an integer. Safe version of {!of_string_exn}. @@ -130,11 +50,6 @@ val of_string_exn : string -> t @raise Failure in case of failure. @since 3.0 *) -val of_float : float -> t -(** [of_float x] converts the given floating-point number [x] to an integer. - Alias to {!int_of_float}. - @since 3.0 *) - val pp_binary : t printer (** [pp_binary ppf x] prints [x] on [ppf]. Print as "0b00101010". @@ -173,34 +88,6 @@ val popcount : t -> int (** Number of bits set to 1 @since 3.0 *) -val logand : t -> t -> t -(** [logand] is the same as [(land)]. - @since 3.0 *) - -val logor : t -> t -> t -(** [logand] is the same as [(lor)]. - @since 3.0 *) - -val logxor : t -> t -> t -(** [logxor] is the same as [(lxor)]. - @since 3.0 *) - -val lognot : t -> t -(** [logand] is the same as [lnot]. - @since 3.0 *) - -val shift_left : t -> int -> t -(** [shift_left] is the same as [(lsl)]. - @since 3.0 *) - -val shift_right : t -> int -> t -(** [shift_right] is the same as [(asr)]. - @since 3.0 *) - -val shift_right_logical : t -> int -> t -(** [shift_right_logical] is the same as [(lsr)]. - @since 3.0 *) - (** {2 Infix Operators} @since 0.17 *) diff --git a/src/core/CCInt32.ml b/src/core/CCInt32.ml index 5a194685d..a2c7a6e79 100644 --- a/src/core/CCInt32.ml +++ b/src/core/CCInt32.ml @@ -111,7 +111,6 @@ let random_range i j st = add i (random (sub j i) st) let of_string_exn = of_string let of_string x = try Some (of_string_exn x) with Failure _ -> None -let of_string_opt = of_string let most_significant_bit = logxor (neg 1l) (shift_right_logical (neg 1l) 1) type output = char -> unit diff --git a/src/core/CCInt32.mli b/src/core/CCInt32.mli index 732ab3e5c..87b1f849a 100644 --- a/src/core/CCInt32.mli +++ b/src/core/CCInt32.mli @@ -81,9 +81,6 @@ val of_string : string -> t option (** [of_string s] is the safe version of {!of_string_exn}. Like {!of_string_exn}, but return [None] instead of raising. *) -val of_string_opt : string -> t option -(** [of_string_opt s] is an alias to {!of_string}. *) - val of_string_exn : string -> t (** [of_string_exn s] converts the given string [s] into a 32-bit integer. Alias to {!Int32.of_string}. diff --git a/src/core/CCInt64.ml b/src/core/CCInt64.ml index 818dd2775..2e4690223 100644 --- a/src/core/CCInt64.ml +++ b/src/core/CCInt64.ml @@ -128,7 +128,6 @@ let random_range i j st = add i (random (sub j i) st) let of_string_exn = of_string let of_string x = try Some (of_string_exn x) with Failure _ -> None -let of_string_opt = of_string let most_significant_bit = logxor (neg 1L) (shift_right_logical (neg 1L) 1) type output = char -> unit diff --git a/src/core/CCInt64.mli b/src/core/CCInt64.mli index bbe89d4ce..c75786741 100644 --- a/src/core/CCInt64.mli +++ b/src/core/CCInt64.mli @@ -86,10 +86,6 @@ val of_string : string -> t option (** [of_string s] is the safe version of {!of_string_exn}. Like {!of_string_exn}, but return [None] instead of raising. *) -val of_string_opt : string -> t option -(** [of_string_opt s] is an alias to {!of_string}. - @since 2.1 *) - val of_string_exn : string -> t (** [of_string_exn s] converts the given string [s] into a 64-bit integer. Alias to {!Int64.of_string}. diff --git a/tests/core/t_float.ml b/tests/core/t_float.ml index 0575b80c1..20bdda479 100644 --- a/tests/core/t_float.ml +++ b/tests/core/t_float.ml @@ -2,10 +2,10 @@ open CCFloat module T = (val Containers_testlib.make ~__FILE__ ()) include T;; -t @@ fun () -> max nan 1. = 1.;; -t @@ fun () -> min nan 1. = 1.;; -t @@ fun () -> max 1. nan = 1.;; -t @@ fun () -> min 1. nan = 1.;; +t @@ fun () -> is_nan (max nan 1.);; +t @@ fun () -> is_nan (min nan 1.);; +t @@ fun () -> is_nan (max 1. nan);; +t @@ fun () -> is_nan (min 1. nan);; q Q.(pair float float)