2020-12-27 23:08:12 +01:00
|
|
|
(* This type should be used for all charges in the program (electrons, nuclei,...). *)
|
2018-01-02 22:02:01 +01:00
|
|
|
type t = float
|
|
|
|
|
2024-01-17 10:30:24 +01:00
|
|
|
(** Conversions *)
|
2018-03-16 00:23:47 +01:00
|
|
|
external of_float : float -> t = "%identity"
|
|
|
|
external to_float : t -> float = "%identity"
|
|
|
|
|
2020-12-27 13:43:55 +01:00
|
|
|
let of_int = float_of_int
|
|
|
|
let to_int = int_of_float
|
|
|
|
|
2024-01-17 10:30:24 +01:00
|
|
|
let of_string = float_of_string
|
2018-01-02 22:02:01 +01:00
|
|
|
|
2024-01-17 10:30:24 +01:00
|
|
|
let to_string x =
|
2020-12-27 13:43:55 +01:00
|
|
|
if x > 0. then
|
2018-01-02 22:02:01 +01:00
|
|
|
Printf.sprintf "+%f" x
|
2020-12-27 13:43:55 +01:00
|
|
|
else if x < 0. then
|
2018-01-02 22:02:01 +01:00
|
|
|
Printf.sprintf "%f" x
|
2024-01-17 10:30:24 +01:00
|
|
|
else
|
2020-12-27 13:43:55 +01:00
|
|
|
"0.0"
|
|
|
|
|
2024-01-17 10:30:24 +01:00
|
|
|
(** Simple operations *)
|
2020-12-27 13:43:55 +01:00
|
|
|
let gen_op op =
|
|
|
|
fun a b ->
|
|
|
|
op (to_float a) (to_float b)
|
|
|
|
|> of_float
|
|
|
|
|
|
|
|
let ( + ) = gen_op ( +. )
|
|
|
|
let ( - ) = gen_op ( -. )
|
|
|
|
let ( * ) = gen_op ( *. )
|
|
|
|
let ( / ) = gen_op ( /. )
|
2021-01-01 11:46:11 +01:00
|
|
|
|
|
|
|
let is_null t = t == 0.
|
2020-12-27 13:43:55 +01:00
|
|
|
|
2024-01-17 10:30:24 +01:00
|
|
|
(** Printers *)
|
|
|
|
let pp ppf x =
|
2021-01-01 11:46:11 +01:00
|
|
|
Format.fprintf ppf "@[%s@]" (to_string x)
|