From 1dcc5296239a5bc4988eb4147e4b4a4124cbf3ca Mon Sep 17 00:00:00 2001 From: Fardale Date: Mon, 6 Jan 2020 16:15:05 +0100 Subject: [PATCH] feat(float): add of_string_opt --- src/core/CCFloat.ml | 3 +++ src/core/CCFloat.mli | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/core/CCFloat.ml b/src/core/CCFloat.ml index 241e3228..de830785 100644 --- a/src/core/CCFloat.ml +++ b/src/core/CCFloat.ml @@ -112,6 +112,9 @@ 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 (a:string) = Stdlib.float_of_string a +let of_string_opt (a:string) = + try Some (Stdlib.float_of_string a) + with _ -> None let random n st = Random.State.float st n diff --git a/src/core/CCFloat.mli b/src/core/CCFloat.mli index 8cddeb8b..757da1ff 100644 --- a/src/core/CCFloat.mli +++ b/src/core/CCFloat.mli @@ -104,6 +104,9 @@ val of_string : string -> t @raise Failure in case of failure. *) [@@ocaml.deprecated "use of_string_exn instead"] +val of_string_opt : string -> t option +(** @since NEXT_RELEASE *) + val equal_precision : epsilon:t -> t -> t -> bool (** Equality with allowed error up to a non negative epsilon value. *)