Repository navigation
Definition syntax
<Definition> ::= <Unit> | <Scale>
<Unit> ::= 'unit'[<ValueType>] unit-name <Tags> [<Format>] '=' <Dim Expr> [ '|' <Dim Expr> ] ';'
<Scale> ::= 'scale' scale-name [<Format>] [refpoint] '=' unit-name <Num Expr> ';'
<ValueType> ::= '<double>' | '<float>' | '<decimal>'
Numeric type underlying the unit. Optional. The default is '<double>'.
unit-, scale-name ::= identifier
The identifier has to be valid both as a C# class name and a file name.
For example: Meter.
<Tags> ::= StringLiteral+
One or more (string) symbols of the unit, separated by spaces.
For example: "m" "meter".
<Format> ::= ':' StringLiteral
String to be used as a composite format parameter in ToString(format, …)
or String.Format(format, …) output methods. Optional. The default is
"{0} {1}": {0} as a value placeholder, {1} as a placeholder for
unit symbol (tag).
refpoint ::= identifier
Symbolic name (reference point identifier) to distinguish scale families
derived from the same units but bound to different reference levels.
For example: AbsoluteZero.
<Dim Expr> ::= dimensional expression
An expression build of numbers, string literals, unit names,
dimension keywords (magnitudes) and multiplicative operators (*|^, /).
It sets dimension of the unit, its conversion factor and arithmetic
(operator) relationship with other units. There might be several,
separated by the pipe symbol '|' expressions (ways) to obtain the unit.
<Magnitude> ::= '<Length>'
| '<Time>'
| '<Mass>'
| '<Temperature>'
| '<ElectricCurrent>'
| '<AmountOfSubstance>'
| '<LuminousIntensity>'
| '<Other>' | '<Money>'
| '<>' // for dimensionless quantities
<Num Expr> ::= numeric expression
An expression build of numbers, string literals and arithmetic
operators (*, /, +, -). It specifies a reference level for the
associated scale.
-
Parser makes no assumptions of any conventions applied in engineering or measurement practice. Therefore you can choose any names, symbols and expressions (relationships) for your units.
-
All numbers, regardless of their syntax, are handled as floating-point numbers of the specified
<ValueType>, with dot "." as a decimal point (invariant culture). For example:123,456.78,1.0e-10. -
String literals in
<Dim Expr>and<Num Expr>expressions are handled as numbers of unknown value. Their evaluation and syntax check is left to C# compiler. For example:"Math.PI". -
Single-line (
//) and block (/* */) comments may be used to clarify (or exclude) sections of definitions.
<Dim Expr> expressions of special importance
-
Product (or quotient) of (exactly) 2 units, i.e. expression of the form
unit * unit-
unit ^ unit(as of rel 2.0) unit / unit
generate binary (2-argument) operators. For example the definition:
unit Watt "W" = Joule / Second;would generate the following operators:
public static Watt operator /(Joule lhs, Second rhs) public static Joule operator *(Watt lhs, Second rhs) public static Joule operator *(Second lhs, Watt rhs)
-
Product (or quotient) of a unit and numeric expression, i.e. expression of the form
unit * numexprnumexpr * unitunit / numexpr
generate conversion operators. For example the definition:
unit Kilometer "km" = Meter / 1000;would generate the following conversion operators:
public static explicit operator Meter(Kilometer q) public static explicit operator Kilometer(Meter q)
Wedge operator "^"
As of release 2.0 wedge operator "^" has been introduced for multiplying units (and only units) apart from the standard star operator "*". This allows to make a distinction between scalar (*) and vector (^) products that create different units from the same factors, for example:
unit Joule "J" = Newton * Meter; /*energy*/
unit NewtonMeter "N*m" = Newton ^ Meter; /*torque*/
which translates into:
public static Joule operator *(Newton lhs, Meter rhs) { ... }
public static Joule operator *(Meter lhs, Newton rhs) { ... }
public static NewtonMeter operator ^(Newton lhs, Meter rhs) { ... }
public static NewtonMeter operator ^(Meter lhs, Newton rhs) { ... }