Skip to content

Commit 24b57f9

Browse files
committed
CCFloat(cleanup): remove function always present on 4.08
1 parent d3b389b commit 24b57f9

File tree

3 files changed

+6
-131
lines changed

3 files changed

+6
-131
lines changed

src/core/CCFloat.ml

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
(* This file is free software, part of containers. See file "license" for more details. *)
22

3-
4-
5-
type t = float
6-
7-
type fpclass = Stdlib.fpclass =
8-
| FP_normal
9-
| FP_subnormal
10-
| FP_zero
11-
| FP_infinite
12-
| FP_nan
3+
include Float
134

145
module Infix = struct
156
let ( = ) : t -> t -> bool = Stdlib.( = )
@@ -29,47 +20,11 @@ include Infix
2920

3021
[@@@ocaml.warning "-32"]
3122

32-
let nan = Stdlib.nan
33-
let infinity = Stdlib.infinity
34-
let neg_infinity = Stdlib.neg_infinity
3523
let max_value = infinity
3624
let min_value = neg_infinity
3725
let max_finite_value = Stdlib.max_float
38-
let epsilon = Stdlib.epsilon_float
39-
let pi = 0x1.921fb54442d18p+1
40-
let is_nan x = Stdlib.(classify_float x = Stdlib.FP_nan)
41-
let add = ( +. )
42-
let sub = ( -. )
43-
let mul = ( *. )
44-
let div = ( /. )
45-
let neg = ( ~-. )
46-
let abs = Stdlib.abs_float
4726
let scale = ( *. )
4827

49-
let min (x : t) y =
50-
match Stdlib.classify_float x, Stdlib.classify_float y with
51-
| FP_nan, _ -> y
52-
| _, FP_nan -> x
53-
| _ ->
54-
if x < y then
55-
x
56-
else
57-
y
58-
59-
let max (x : t) y =
60-
match Stdlib.classify_float x, Stdlib.classify_float y with
61-
| FP_nan, _ -> y
62-
| _, FP_nan -> x
63-
| _ ->
64-
if x > y then
65-
x
66-
else
67-
y
68-
69-
let equal (a : float) b = a = b
70-
let hash : t -> int = Hashtbl.hash
71-
let compare (a : float) b = Stdlib.compare a b
72-
7328
[@@@ocaml.warning "+32"]
7429

7530
type 'a printer = Format.formatter -> 'a -> unit
@@ -93,22 +48,8 @@ let sign_exn (a : float) =
9348
else
9449
compare a 0.
9550

96-
let round x =
97-
let low = floor x in
98-
let high = ceil x in
99-
if x -. low > high -. x then
100-
high
101-
else
102-
low
103-
104-
let to_int (a : float) = Stdlib.int_of_float a
105-
let of_int (a : int) = Stdlib.float_of_int a
106-
let to_string (a : float) = Stdlib.string_of_float a
10751
let of_string_exn (a : string) = Stdlib.float_of_string a
10852

109-
let of_string_opt (a : string) =
110-
try Some (Stdlib.float_of_string a) with Failure _ -> None
111-
11253
let random n st = Random.State.float st n
11354
let random_small = random 100.0
11455
let random_range i j st = i +. random (j -. i) st

src/core/CCFloat.mli

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,7 @@
33
(** Basic operations on floating-point numbers
44
@since 0.6.1 *)
55

6-
7-
8-
type t = float
9-
10-
type fpclass = Stdlib.fpclass =
11-
| FP_normal
12-
| FP_subnormal
13-
| FP_zero
14-
| FP_infinite
15-
| FP_nan
16-
17-
val nan : t
18-
(** [nan] is Not a Number (NaN). Equal to {!Stdlib.nan}. *)
6+
include module type of Float
197

208
val max_value : t
219
(** [max_value] is Positive infinity. Equal to {!Stdlib.infinity}. *)
@@ -26,50 +14,13 @@ val min_value : t
2614
val max_finite_value : t
2715
(** [max_finite_value] is the largest finite float value. Equal to {!Stdlib.max_float}. *)
2816

29-
val epsilon : t
30-
(** [epsilon] is the smallest positive float x such that [1.0 +. x <> 1.0].
31-
Equal to {!Stdlib.epsilon_float}. *)
32-
33-
val pi : t
34-
(** [pi] is the constant pi. The ratio of a circumference to its diameter.
35-
@since 3.0 *)
36-
37-
val is_nan : t -> bool
38-
(** [is_nan f] returns [true] if f is NaN, [false] otherwise. *)
39-
40-
val add : t -> t -> t
41-
(** [add x y] is equal to [x +. y]. *)
42-
43-
val sub : t -> t -> t
44-
(** [sub x y] is equal to [x -. y]. *)
45-
46-
val neg : t -> t
47-
(** [neg x] is equal to [~-. x]. *)
48-
49-
val abs : t -> t
50-
(** [abs x] is the absolute value of the floating-point number [x].
51-
Equal to {!Stdlib.abs_float}. *)
52-
5317
val scale : t -> t -> t
5418
(** [scale x y] is equal to [x *. y]. *)
5519

56-
val min : t -> t -> t
57-
(** [min x y] returns the min of the two given values [x] and [y]. *)
58-
59-
val max : t -> t -> t
60-
(** [max x y] returns the max of the two given values [x] and [y]. *)
61-
62-
val equal : t -> t -> bool
63-
(** [equal x y] is [true] if [x] and [y] are the same. *)
64-
65-
val compare : t -> t -> int
66-
(** [compare x y] is {!Stdlib.compare x y}. *)
67-
6820
type 'a printer = Format.formatter -> 'a -> unit
6921
type 'a random_gen = Random.State.t -> 'a
7022

7123
val pp : t printer
72-
val hash : t -> int
7324
val random : t -> t random_gen
7425
val random_small : t random_gen
7526
val random_range : t -> t -> t random_gen
@@ -78,11 +29,6 @@ val fsign : t -> t
7829
(** [fsign x] is one of [-1., -0., +0., +1.], or [nan] if [x] is NaN.
7930
@since 0.7 *)
8031

81-
val round : t -> t
82-
(** [round x] returns the closest integer value, either above or below.
83-
For [n + 0.5], [round] returns [n].
84-
@since 0.20 *)
85-
8632
exception TrapNaN of string
8733

8834
val sign_exn : t -> int
@@ -91,23 +37,11 @@ val sign_exn : t -> int
9137
Note that infinities have defined signs in OCaml.
9238
@since 0.7 *)
9339

94-
val to_int : t -> int
95-
(** Alias to {!int_of_float}.
96-
Unspecified if outside of the range of integers. *)
97-
98-
val of_int : int -> t
99-
(** Alias to {!float_of_int}. *)
100-
101-
val to_string : t -> string
102-
10340
val of_string_exn : string -> t
10441
(** Alias to {!float_of_string}.
10542
@raise Failure in case of failure.
10643
@since 1.2 *)
10744

108-
val of_string_opt : string -> t option
109-
(** @since 3.0 *)
110-
11145
val equal_precision : epsilon:t -> t -> t -> bool
11246
(** Equality with allowed error up to a non negative epsilon value. *)
11347

tests/core/t_float.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ open CCFloat
22
module T = (val Containers_testlib.make ~__FILE__ ())
33
include T;;
44

5-
t @@ fun () -> max nan 1. = 1.;;
6-
t @@ fun () -> min nan 1. = 1.;;
7-
t @@ fun () -> max 1. nan = 1.;;
8-
t @@ fun () -> min 1. nan = 1.;;
5+
t @@ fun () -> is_nan (max nan 1.);;
6+
t @@ fun () -> is_nan (min nan 1.);;
7+
t @@ fun () -> is_nan (max 1. nan);;
8+
t @@ fun () -> is_nan (min 1. nan);;
99

1010
q
1111
Q.(pair float float)

0 commit comments

Comments
 (0)