Skip to content

Commit 103011d

Browse files
committed
CCFloat(cleanup): remove function always present on 4.08
1 parent da45e33 commit 103011d

File tree

3 files changed

+7
-128
lines changed

3 files changed

+7
-128
lines changed

src/core/CCFloat.ml

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

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

125
module Infix = struct
136
let ( = ) : t -> t -> bool = Stdlib.( = )
@@ -27,47 +20,11 @@ include Infix
2720

2821
[@@@ocaml.warning "-32"]
2922

30-
let nan = Stdlib.nan
31-
let infinity = Stdlib.infinity
32-
let neg_infinity = Stdlib.neg_infinity
3323
let max_value = infinity
3424
let min_value = neg_infinity
3525
let max_finite_value = Stdlib.max_float
36-
let epsilon = Stdlib.epsilon_float
37-
let pi = 0x1.921fb54442d18p+1
38-
let is_nan x = Stdlib.(classify_float x = Stdlib.FP_nan)
39-
let add = ( +. )
40-
let sub = ( -. )
41-
let mul = ( *. )
42-
let div = ( /. )
43-
let neg = ( ~-. )
44-
let abs = Stdlib.abs_float
4526
let scale = ( *. )
4627

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

7330
type 'a printer = Format.formatter -> 'a -> unit
@@ -91,22 +48,7 @@ let sign_exn (a : float) =
9148
else
9249
compare a 0.
9350

94-
let round x =
95-
let low = floor x in
96-
let high = ceil x in
97-
if x -. low > high -. x then
98-
high
99-
else
100-
low
101-
102-
let to_int (a : float) = Stdlib.int_of_float a
103-
let of_int (a : int) = Stdlib.float_of_int a
104-
let to_string (a : float) = Stdlib.string_of_float a
10551
let of_string_exn (a : string) = Stdlib.float_of_string a
106-
107-
let of_string_opt (a : string) =
108-
try Some (Stdlib.float_of_string a) with Failure _ -> None
109-
11052
let random n st = Random.State.float st n
11153
let random_small = random 100.0
11254
let random_range i j st = i +. random (j -. i) st

src/core/CCFloat.mli

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33
(** Basic operations on floating-point numbers
44
@since 0.6.1 *)
55

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

189
val max_value : t
1910
(** [max_value] is Positive infinity. Equal to {!Stdlib.infinity}. *)
@@ -24,50 +15,13 @@ val min_value : t
2415
val max_finite_value : t
2516
(** [max_finite_value] is the largest finite float value. Equal to {!Stdlib.max_float}. *)
2617

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

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

6924
val pp : t printer
70-
val hash : t -> int
7125
val random : t -> t random_gen
7226
val random_small : t random_gen
7327
val random_range : t -> t -> t random_gen
@@ -76,11 +30,6 @@ val fsign : t -> t
7630
(** [fsign x] is one of [-1., -0., +0., +1.], or [nan] if [x] is NaN.
7731
@since 0.7 *)
7832

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

8635
val sign_exn : t -> int
@@ -89,23 +38,11 @@ val sign_exn : t -> int
8938
Note that infinities have defined signs in OCaml.
9039
@since 0.7 *)
9140

92-
val to_int : t -> int
93-
(** Alias to {!int_of_float}.
94-
Unspecified if outside of the range of integers. *)
95-
96-
val of_int : int -> t
97-
(** Alias to {!float_of_int}. *)
98-
99-
val to_string : t -> string
100-
10141
val of_string_exn : string -> t
10242
(** Alias to {!float_of_string}.
10343
@raise Failure in case of failure.
10444
@since 1.2 *)
10545

106-
val of_string_opt : string -> t option
107-
(** @since 3.0 *)
108-
10946
val equal_precision : epsilon:t -> t -> t -> bool
11047
(** Equality with allowed error up to a non negative epsilon value. *)
11148

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)