package safemoney

  1. Overview
  2. Docs
Module type
Class type
type showable = {
  1. value : string;

showable for t

val show_showable : showable -> Ppx_deriving_runtime.string
val showable_to_yojson : showable -> Yojson.Safe.t
val sexp_of_showable : showable -> Sexplib0.Sexp.t
val showable_of_sexp : Sexplib0.Sexp.t -> showable
val make : string -> t


Constructing Q by using a private type, create a Q value from string, e.g. from_str "123/456". Reason behind is to disallow a range of functions that are unsuitable for currency operations. Unsensical and undefined rational numbers are checked/excluded.In the context of safe money we want to establish a chain of proof that no lossy operations ever occurred. For convenience the function alias make_q can be used.

val one : t

Return rational value of 1: "1/1" or "1"

val neg : t -> t

Negate a Q value

val abs : t -> t

Return an absolute Q value

val signum : t -> int

Return the sign of Q value, -1, 0, or 1 when the argument is respectively negative, null, or positive.

val add : t -> t -> t

Add two Q values

val sub : t -> t -> t

Substract two Q values

val mul : t -> t -> t

Multiply two Q values

val div : t -> t -> t

Divide two Q values

val num_of_q : t -> Z.t

Get the numerator of a Q value

val den_of_q : t -> Z.t

Get the denominator of a Q value

val to_str : t -> string

Convert a Q value to string

val to_float : t -> float

Convert a Q value to float

val to_showable_json : t -> string

Convert a Q value to showable rep


Innovation. Community. Security.