feat(float): add of_string_opt

This commit is contained in:
Fardale 2020-01-06 16:15:05 +01:00
parent 5143e28ce8
commit 1dcc529623
2 changed files with 6 additions and 0 deletions

View file

@ -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 to_string (a:float) = Stdlib.string_of_float a
let of_string_exn (a:string) = Stdlib.float_of_string 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 (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 let random n st = Random.State.float st n

View file

@ -104,6 +104,9 @@ val of_string : string -> t
@raise Failure in case of failure. *) @raise Failure in case of failure. *)
[@@ocaml.deprecated "use of_string_exn instead"] [@@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 val equal_precision : epsilon:t -> t -> t -> bool
(** Equality with allowed error up to a non negative epsilon value. *) (** Equality with allowed error up to a non negative epsilon value. *)