2020-12-27 23:08:12 +01:00
|
|
|
(* [[file:../non_negative_float.org::*Type][Type:2]] *)
|
|
|
|
type t = float
|
|
|
|
(* Type:2 ends here *)
|
2018-02-23 18:44:31 +01:00
|
|
|
|
2020-12-27 23:08:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* The ~of_float~ function checks that the float is non-negative.
|
|
|
|
* The unsafe variant doesn't do this check. *)
|
|
|
|
|
|
|
|
|
|
|
|
(* [[file:../non_negative_float.org::*Conversions][Conversions:2]] *)
|
2018-02-23 18:44:31 +01:00
|
|
|
let of_float x =
|
2018-02-25 00:53:09 +01:00
|
|
|
if x < 0. then invalid_arg (__FILE__^": of_float");
|
2018-02-23 18:44:31 +01:00
|
|
|
x
|
|
|
|
|
2020-12-27 23:08:12 +01:00
|
|
|
external to_float : t -> float = "%identity"
|
2018-02-24 23:57:38 +01:00
|
|
|
external unsafe_of_float : float -> t = "%identity"
|
2018-02-23 18:44:31 +01:00
|
|
|
|
|
|
|
let to_string x =
|
|
|
|
let f = to_float x in string_of_float f
|
|
|
|
|
|
|
|
let of_string x =
|
|
|
|
let f = float_of_string x in of_float f
|
2020-12-27 23:08:12 +01:00
|
|
|
(* Conversions:2 ends here *)
|