diff --git a/core/CCFloat.ml b/core/CCFloat.ml index 4f6fd329..793544c5 100644 --- a/core/CCFloat.ml +++ b/core/CCFloat.ml @@ -1,5 +1,5 @@ (* -copyright (c) 2013-2014, simon cruanes +copyright (c) 2014, Carmelo Piccione all rights reserved. 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 fpclass = Pervasives.fpclass let nan = Pervasives.nan @@ -36,6 +36,8 @@ let min_value = neg_infinity let max_finite_value = Pervasives.max_float +let epsilon = Pervasives.epsilon_float + let is_nan x = (x : t) <> x let add = (+.) @@ -80,3 +82,7 @@ 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 +let equal_precision ~epsilon a b = abs_float (a-.b) < epsilon + +let classify = Pervasives.classify_float + diff --git a/core/CCFloat.mli b/core/CCFloat.mli index cba7903e..5e91191e 100644 --- a/core/CCFloat.mli +++ b/core/CCFloat.mli @@ -1,5 +1,5 @@ (* -copyright (c) 2013-2014, simon cruanes +copyright (c) 2014, Carmelo Piccione all rights reserved. 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} *) type t = float +type fpclass val nan : t @@ -34,6 +35,8 @@ val min_value : t val max_finite_value : t +val epsilon : float + val is_nan : t -> bool val add : t -> t -> t @@ -75,3 +78,9 @@ val of_int : int -> t val to_string : t -> string 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