Module SIunits.Value


module Value: sig .. end
Creation and conversion of numerical quantities.

type t 
The abstract value type, which encapsulates both the units and the numerical value.

Exceptions


exception Invalid_conversion of t * SIunits.Unit.d
The exception that is raised by SIunits.Value.scale_to and SIunits.Value.convert when a value cannot be converted into the given units.
exception Invalid_units of t * t * string
The exception that is raised by SIunits.Value.(+:), SIunits.Value.(-:) and SIunits.Value.(<-:) when two values cannot be combined due to incompatible units. The string argument identifies which function/operator raised the exception.

Value creation


val value : float -> SIunits.Unit.t -> t
Create a value that encapsulates the given numerical value and units.
val (%<) : float -> SIunits.Unit.t -> t
Create a value that encapsulates the given numerical value and units.

Value properties


val units_of : t -> SIunits.Unit.t
Return the units associated with the value.

Floating-point comparison


val (=.) : float -> float -> bool
Compare two floating-point values for equality, with a relative error tolerance of 10-15 and an absolute error tolerance of 10-200.

The algorithm is described in these articles by Alberto Squassabia and Bruce Dawson (older version here).

val (=!.) : float -> float -> bool
Compare two floating-point values for inequality (negation of SIunits.Value.(=.)).
val float_eq : ?rel:float -> ?abs:float -> unit -> float -> float -> bool
Define a custom comparison function for floating-point values.
rel : The relative error tolerance (default = 10-15).
abs : The absolute error tolerance (default = 10-200).

Value comparison


val eq : t -> t -> bool
Compare both units and numerical values for equality.
val (=:) : t -> t -> bool
Compare both units and numerical values for equality.
val eq_units : t -> t -> bool
Compare units for equivalence.
val (=?:) : t -> t -> bool
Compare units for equivalence.

Value assignment


val assign : t Pervasives.ref -> t -> unit
Assign a numerical value to a value reference. This action conserves the multiplicative scaling factor of the value reference.
Raises Invalid_units (v1, v2, "assign") if the units of the two values (v1 and v2) are not compatible.
val (<-:) : t Pervasives.ref -> t -> unit
Assign a numerical value to a value reference. This action preserves the units of the reference.
Raises Invalid_units (v1, v2, "<-:") if the units of the two values (v1 and v2) are not compatible.
val get : t Pervasives.ref -> float
Return the value in terms of the original units.
val (!:) : t Pervasives.ref -> float
Return the value in terms of the original units.

Value conversion


val scale_to : t -> SIunits.Unit.t -> float
Scale the given value to a specific set of units and return the numerical value.
Raises Invalid_conversion (v, d) if the value v and units d are not compatible.
val (%>) : t -> SIunits.Unit.t -> float
Scale the given value to a specific set of units and return the numerical value.
Raises Invalid_conversion (v, d) if the value v and units d are not compatible.
val convert : value:float -> from:SIunits.Unit.t -> into:SIunits.Unit.t -> float
Convert a numerical value from one set of units to another. This is equivalent to scale_to (create value from) into or value %< from %>into.
Raises Invalid_conversion (v, d) if the numerical value and source units v are not compatible with the destination units d.

Arithmetic operations


val (+:) : t -> t -> t
The addition of two values.
Raises Invalid_units (v1, v2, "+:") if the units of the two values (v1 and v2) are not compatible.
val (-:) : t -> t -> t
The subtraction of one value from another.
Raises Invalid_units (v1, v2, "-:") if the units of the two values (v1 and v2) are not compatible.
val ( *: ) : t -> t -> t
The multiplication of two values.
val (/:) : t -> t -> t
The division of one value by another.
val ( *:. ) : t -> float -> t
Scalar multiplication.
val (/:.) : t -> float -> t
Scalar division.
val (/.:) : float -> t -> t
Scalar reciprocal.