mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
classify, equal_precision added to CCFloat
Changed author name in CCFloat licenses, added epsilon constant for Pervasives.epsilon_float
This commit is contained in:
parent
da3a1e5afc
commit
7a328425b5
2 changed files with 18 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
(*
|
(*
|
||||||
copyright (c) 2013-2014, simon cruanes
|
copyright (c) 2014, Carmelo Piccione
|
||||||
all rights reserved.
|
all rights reserved.
|
||||||
|
|
||||||
redistribution and use in source and binary forms, with or without
|
redistribution and use in source and binary forms, with or without
|
||||||
|
|
@ -24,7 +24,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*)
|
*)
|
||||||
|
|
||||||
type t = float
|
type t = float
|
||||||
|
type fpclass = Pervasives.fpclass
|
||||||
|
|
||||||
let nan = Pervasives.nan
|
let nan = Pervasives.nan
|
||||||
|
|
||||||
|
|
@ -36,6 +36,8 @@ let min_value = neg_infinity
|
||||||
|
|
||||||
let max_finite_value = Pervasives.max_float
|
let max_finite_value = Pervasives.max_float
|
||||||
|
|
||||||
|
let epsilon = Pervasives.epsilon_float
|
||||||
|
|
||||||
let is_nan x = (x : t) <> x
|
let is_nan x = (x : t) <> x
|
||||||
|
|
||||||
let add = (+.)
|
let add = (+.)
|
||||||
|
|
@ -80,3 +82,7 @@ let random n st = Random.State.float st n
|
||||||
let random_small = random 100.0
|
let random_small = random 100.0
|
||||||
let random_range i j st = i +. random (j-.i) st
|
let random_range i j st = i +. random (j-.i) st
|
||||||
|
|
||||||
|
let equal_precision ~epsilon a b = abs_float (a-.b) < epsilon
|
||||||
|
|
||||||
|
let classify = Pervasives.classify_float
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(*
|
(*
|
||||||
copyright (c) 2013-2014, simon cruanes
|
copyright (c) 2014, Carmelo Piccione
|
||||||
all rights reserved.
|
all rights reserved.
|
||||||
|
|
||||||
redistribution and use in source and binary forms, with or without
|
redistribution and use in source and binary forms, with or without
|
||||||
|
|
@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
(** {1 Basic Float functions} *)
|
(** {1 Basic Float functions} *)
|
||||||
|
|
||||||
type t = float
|
type t = float
|
||||||
|
type fpclass
|
||||||
|
|
||||||
val nan : t
|
val nan : t
|
||||||
|
|
||||||
|
|
@ -34,6 +35,8 @@ val min_value : t
|
||||||
|
|
||||||
val max_finite_value : t
|
val max_finite_value : t
|
||||||
|
|
||||||
|
val epsilon : float
|
||||||
|
|
||||||
val is_nan : t -> bool
|
val is_nan : t -> bool
|
||||||
|
|
||||||
val add : t -> t -> t
|
val add : t -> t -> t
|
||||||
|
|
@ -75,3 +78,9 @@ val of_int : int -> t
|
||||||
|
|
||||||
val to_string : t -> string
|
val to_string : t -> string
|
||||||
val of_string : string -> t
|
val of_string : string -> t
|
||||||
|
|
||||||
|
|
||||||
|
val equal_precision : epsilon:t -> t -> t -> bool
|
||||||
|
(** Equality with allowed error up to a non negative epsilon value *)
|
||||||
|
|
||||||
|
val classify : float -> fpclass
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue