mirror of
https://gitlab.com/scemama/QCaml.git
synced 2025-01-08 20:33:03 +01:00
Added Charge.org
This commit is contained in:
parent
dfadaf14c1
commit
b08079c09d
@ -1,6 +1,7 @@
|
|||||||
#+TITLE: Angular Momentum
|
#+begin_src elisp tangle: no :results none
|
||||||
|
(org-babel-tangle)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
[[elisp:(org-babel-tangle)]]
|
|
||||||
|
|
||||||
* Angular Momentum
|
* Angular Momentum
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#+TITLE: Bit string
|
#+begin_src elisp tangle: no :results none
|
||||||
|
(org-babel-tangle)
|
||||||
[[elisp:(org-babel-tangle)]]
|
#+end_src
|
||||||
|
|
||||||
* Bit string
|
* Bit string
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
101
common/charge.org
Normal file
101
common/charge.org
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#+begin_src elisp tangle: no :results none
|
||||||
|
(org-babel-tangle)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
* Charge
|
||||||
|
:PROPERTIES:
|
||||||
|
:ml: lib/charge.ml
|
||||||
|
:mli: lib/charge.mli
|
||||||
|
:test-ml: test/charge.ml
|
||||||
|
:header-args: :noweb yes :comments both
|
||||||
|
:END:
|
||||||
|
|
||||||
|
** Type
|
||||||
|
|
||||||
|
This type should be used for all charges in the program (electrons, nuclei,...).
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
|
||||||
|
type t
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "ml" t)
|
||||||
|
type t = float
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Conversions
|
||||||
|
|
||||||
|
*** ~of_float~ / ~to_float~
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
|
||||||
|
val of_float : float -> t
|
||||||
|
val to_float : t -> float
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "ml" t)
|
||||||
|
external of_float : float -> t = "%identity"
|
||||||
|
external to_float : t -> float = "%identity"
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** ~of_int~ / ~to_int~
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
|
||||||
|
val of_int : int -> t
|
||||||
|
val to_int : t -> int
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "ml" t)
|
||||||
|
let of_int = float_of_int
|
||||||
|
let to_int = int_of_float
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** ~of_string~ / ~to_string~
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
|
||||||
|
val of_string: string -> t
|
||||||
|
val to_string: t -> string
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "ml" t)
|
||||||
|
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"
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Simple operations
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
|
||||||
|
val ( + ) : t -> t -> t
|
||||||
|
val ( - ) : t -> t -> t
|
||||||
|
val ( * ) : t -> float -> t
|
||||||
|
val ( / ) : t -> float -> t
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "ml" 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 ( /. )
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Printers
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
|
||||||
|
val pp : Format.formatter -> t -> unit
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ocaml :tangle (org-entry-get nil "ml" t)
|
||||||
|
let pp ppf x =
|
||||||
|
Format.fprintf ppf "@[+%s@]" (to_string x)
|
||||||
|
#+end_src
|
||||||
|
|
@ -1,32 +1,42 @@
|
|||||||
|
(* [[file:../charge.org::*Type][Type:2]] *)
|
||||||
type t = float
|
type t = float
|
||||||
|
(* Type:2 ends here *)
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*~of_float~ / ~to_float~][~of_float~ / ~to_float~:2]] *)
|
||||||
external of_float : float -> t = "%identity"
|
external of_float : float -> t = "%identity"
|
||||||
external to_float : t -> float = "%identity"
|
external to_float : t -> float = "%identity"
|
||||||
|
(* ~of_float~ / ~to_float~:2 ends here *)
|
||||||
|
|
||||||
let of_int i = float_of_int i
|
(* [[file:../charge.org::*~of_int~ / ~to_int~][~of_int~ / ~to_int~:2]] *)
|
||||||
let of_string s = float_of_string s
|
let of_int = float_of_int
|
||||||
|
let to_int = int_of_float
|
||||||
|
(* ~of_int~ / ~to_int~:2 ends here *)
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*~of_string~ / ~to_string~][~of_string~ / ~to_string~:2]] *)
|
||||||
|
let of_string = float_of_string
|
||||||
|
|
||||||
let to_int x = int_of_float x
|
|
||||||
let to_string x =
|
let to_string x =
|
||||||
if x >= 0. then
|
if x > 0. then
|
||||||
Printf.sprintf "+%f" x
|
Printf.sprintf "+%f" x
|
||||||
else
|
else if x < 0. then
|
||||||
Printf.sprintf "%f" x
|
Printf.sprintf "%f" x
|
||||||
|
else
|
||||||
|
"0.0"
|
||||||
|
(* ~of_string~ / ~to_string~:2 ends here *)
|
||||||
|
|
||||||
let ( + ) a b =
|
(* [[file:../charge.org::*Simple operations][Simple operations:2]] *)
|
||||||
(to_float a) +. (to_float b) |> of_float
|
let gen_op op =
|
||||||
|
fun a b ->
|
||||||
|
op (to_float a) (to_float b)
|
||||||
|
|> of_float
|
||||||
|
|
||||||
let ( - ) a b =
|
let ( + ) = gen_op ( +. )
|
||||||
(to_float a) -. (to_float b) |> of_float
|
let ( - ) = gen_op ( -. )
|
||||||
|
let ( * ) = gen_op ( *. )
|
||||||
let ( * ) a b =
|
let ( / ) = gen_op ( /. )
|
||||||
(to_float a) *. b |> of_float
|
(* Simple operations:2 ends here *)
|
||||||
|
|
||||||
let ( / ) a b =
|
|
||||||
(to_float a) /. b |> of_float
|
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*Printers][Printers:2]] *)
|
||||||
let pp ppf x =
|
let pp ppf x =
|
||||||
if x > 0. then
|
Format.fprintf ppf "@[+%s@]" (to_string x)
|
||||||
Format.fprintf ppf "@[+%f@]" (to_float x)
|
(* Printers:2 ends here *)
|
||||||
else
|
|
||||||
Format.fprintf ppf "@[%f@]" (to_float x)
|
|
||||||
|
@ -1,25 +1,49 @@
|
|||||||
(** This type should be used for all charges in the program (electrons, nuclei,...). *)
|
(* Type
|
||||||
|
*
|
||||||
|
* This type should be used for all charges in the program (electrons, nuclei,...). *)
|
||||||
|
|
||||||
type t
|
|
||||||
|
|
||||||
(** {2 Conversions} *)
|
(* [[file:../charge.org::*Type][Type:1]] *)
|
||||||
|
type t
|
||||||
|
(* Type:1 ends here *)
|
||||||
|
|
||||||
|
(* ~of_float~ / ~to_float~ *)
|
||||||
|
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*~of_float~ / ~to_float~][~of_float~ / ~to_float~:1]] *)
|
||||||
val of_float : float -> t
|
val of_float : float -> t
|
||||||
val of_int : int -> t
|
|
||||||
val of_string: string -> t
|
|
||||||
|
|
||||||
val to_float : t -> float
|
val to_float : t -> float
|
||||||
|
(* ~of_float~ / ~to_float~:1 ends here *)
|
||||||
|
|
||||||
|
(* ~of_int~ / ~to_int~ *)
|
||||||
|
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*~of_int~ / ~to_int~][~of_int~ / ~to_int~:1]] *)
|
||||||
|
val of_int : int -> t
|
||||||
val to_int : t -> int
|
val to_int : t -> int
|
||||||
val to_string: t -> string
|
(* ~of_int~ / ~to_int~:1 ends here *)
|
||||||
|
|
||||||
(** {2 Operations} *)
|
(* ~of_string~ / ~to_string~ *)
|
||||||
|
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*~of_string~ / ~to_string~][~of_string~ / ~to_string~:1]] *)
|
||||||
|
val of_string: string -> t
|
||||||
|
val to_string: t -> string
|
||||||
|
(* ~of_string~ / ~to_string~:1 ends here *)
|
||||||
|
|
||||||
|
(* Simple operations *)
|
||||||
|
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*Simple operations][Simple operations:1]] *)
|
||||||
val ( + ) : t -> t -> t
|
val ( + ) : t -> t -> t
|
||||||
val ( - ) : t -> t -> t
|
val ( - ) : t -> t -> t
|
||||||
val ( * ) : t -> float -> t
|
val ( * ) : t -> float -> t
|
||||||
val ( / ) : t -> float -> t
|
val ( / ) : t -> float -> t
|
||||||
|
(* Simple operations:1 ends here *)
|
||||||
|
|
||||||
(** {2 Printers } *)
|
(* Printers *)
|
||||||
|
|
||||||
|
|
||||||
|
(* [[file:../charge.org::*Printers][Printers:1]] *)
|
||||||
val pp : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
|
(* Printers:1 ends here *)
|
||||||
|
Loading…
Reference in New Issue
Block a user