mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-11-18 20:12:26 +01:00
2.1 KiB
2.1 KiB
(org-babel-tangle)
Charge
Type
This type should be used for all charges in the program (electrons, nuclei,…).
type t
type t = float
Conversions
of_float
/ to_float
val of_float : float -> t
val to_float : t -> float
external of_float : float -> t = "%identity"
external to_float : t -> float = "%identity"
of_int
/ to_int
val of_int : int -> t
val to_int : t -> int
let of_int = float_of_int
let to_int = int_of_float
of_string
/ to_string
val of_string: string -> t
val to_string: t -> string
let of_string = float_of_string
let to_string x =
if x > 0. then
Printf.sprintf "+%f" x
else if x < 0. then
Printf.sprintf "%f" x
else
"0.0"
Simple operations
val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
val ( * ) : t -> float -> t
val ( / ) : t -> float -> t
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 ( /. )
Printers
val pp : Format.formatter -> t -> unit
let pp ppf x =
Format.fprintf ppf "@[+%s@]" (to_string x)