View Source Measurements.Unit (Measurements v0.1.2)
Documentation for Measurements.Unit
.
A unit is represented by an atom. Ref: https://en.wikipedia.org/wiki/International_System_of_Units
There exist multiple submodules defining the various units:
Time
- TODO !!
Internally, a unit relies on Scale
and Dimension
to determine:
- which conversion is allowed or not.
- which unit is better suited to a value.
But a user does not need to know about it, it will be managed automatically, to minimize loss of precision, and keep the Measurement value in the integer range as much as possible.
examples
Examples
iex> Measurements.Unit.time(:second)
{:ok, :second}
iex> Measurements.Unit.min(:second, :nanosecond)
{:ok, :nanosecond}
iex> {:ok, converter} = Measurements.Unit.convert(:second, :millisecond)
iex> converter.(42)
42_000
Link to this section Summary
Functions
Conversion algorithm from a unit to another.
The dimension of the unit
Normalizes a custom length unit to a known one
finds out, for two units of the same dimension, which unit is more (in scale) than the other. This means the returned unit will be the least precise
finds out, for two units of the same dimension, which unit is less (in scale) than the other. This means the returned unit will be the most precise
Returns the module where this unit is defined.
Normalizes a known unit, of any dimension
Normalizes a custom time unit to a known one.
Link to this section Types
Link to this section Functions
Conversion algorithm from a unit to another.
Will find out which dimension the unnit belongs to, and if a conversion is possible.
The dimension of the unit
Normalizes a custom length unit to a known one
finds out, for two units of the same dimension, which unit is more (in scale) than the other. This means the returned unit will be the least precise
finds out, for two units of the same dimension, which unit is less (in scale) than the other. This means the returned unit will be the most precise
Returns the module where this unit is defined.
Indicates which implementation to call for normalization, conversion, etc.
Normalizes a known unit, of any dimension
@spec scale(atom()) :: {:ok, Measurements.Scale.t()} | {:error, term()}
Normalizes a custom time unit to a known one.