- get
N get()
Undocumented in source. Be warned that the author may not have intended to support it.
- isConsistentWith
bool isConsistentWith(Q other)
Tests wheter this quantity has the same dimensions as another one.
- opAssign
void opAssign(Q other)
Undocumented in source. Be warned that the author may not have intended to support it.
- opAssign
void opAssign(T other)
- opBinary
auto opBinary(Q other)
auto opBinary(T other)
Overloaded operators.
Only dimensionally correct operations will compile.
- opBinary
auto opBinary(T power)
Undocumented in source. Be warned that the author may not have intended to support it.
- opBinaryRight
auto opBinaryRight(T other)
Overloaded operators.
Only dimensionally correct operations will compile.
- opCast
Q opCast()
Overloaded operators.
Only dimensionally correct operations will compile.
- opCast
T opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
- opCmp
int opCmp(Q other)
int opCmp(T other)
- opEquals
bool opEquals(Q other)
bool opEquals(T other)
- opOpAssign
void opOpAssign(Q other)
void opOpAssign(T other)
- opUnary
auto opUnary()
Overloaded operators.
Only dimensionally correct operations will compile.
- rawValue
N rawValue()
Undocumented in source. Be warned that the author may not have intended to support it.
- toString
void toString(void delegate(const(char)[]) sink, FormatSpec!char fmt)
Undocumented in source. Be warned that the author may not have intended to support it.
- value
N value(Q target)
Gets the value of this quantity expressed in the given target unit.
A quantity that can be represented as the product of a number and a set of dimensions. The number is stored internally as a member of type N, which is enforced to be a built-in numeric type (isNumeric!N is true). The dimensions are stored as an associative array where keys are symbols and values are integral powers. For instance length and speed quantities can be stored as:
where "L" is the symbol for the length dimension, "T" is the symbol of the time dimensions, and 1 and -1 are the powers of those dimensions in the representation of the quantity.
Units are just instances of a Quantity struct where the value is 1 and the dimensions only contain one symbol, with the power 1. For instance, the meter unit can be defined using the template unit as:
The main quantities compliant with the international system of units (SI) are actually predefined in the module quantities.si.
Any quantity can be expressed as the product of a number (n) and a unit of the right dimensions (U). For instance:
The unit U is not actually stored along with the number in a Quantity struct, only the dimensions are. This is because the same quantity can be expressed in an infinity of different units. The value of n is stored as if the quantity was expressed in the base units of the same dimemsions. In the example above, n = 9.5 for the variable size and n = 0.120 for the variable time.
The method value can be used to extract the number n as if it was expressed in any possible unit. The user must pass this unit to the method. This way, the user makes it clear in which unit the value was expressed.
Arithmetic operators (+ - * /), as well as assignment and comparison operators, are defined when the operations are dimensionally consistent, otherwise an error occurs at compile-time:
Any kind of quantities and units can be defined with this module, not just those from the SI. When a quantity that is not predefined has to be used, instead of instantiating the Quantity template first, it is preferable to start defining a new base unit (with only one dimension) using the unit template, and then the quantity type with the typeof operator:
This means that all currencies will be defined with respect to euro.