-
Notifications
You must be signed in to change notification settings - Fork 3
Definitions explained
Primary units
unit Meter "m" = <Length>;
unit Second "s" = <Time>;
The above definitions specify: Meter as a length unit (of symbol "m") and Second as a time unit (of symbol "s") correspondingly; each unit of (implicit) conversion factor 1.0. They do not specify, either explicitly or implicitly, any relationship with other units. Units defined this way can be considered as primary.
Conversion relationship
unit Centimeter "cm" = 100 * Meter;
It defines Centimeter in terms of (previously defined) Meter, as a unit that can be obtained (among others) from Meter by conversion. It has symbol "cm", dimension length (inherited from Meter) and (explicit) conversion factor 100.0, meaning:
(length in Centimeters) = 100.0 * (length in Meters).
The conversion relationships would be implemented as explicit conversion operators in Meter and Centimeter classes:
public static explicit operator Meter(Centimeter q) // in Meter.cs
public static explicit operator Centimeter(Meter q) // in Centimeter.csArithmetic (product or quotient) relationship
unit Meter_Sec "m/s" = Meter / Second;
It derives Meter_Sec unit as a quotient of Meter and Second units. It has symbol "m/s", dimension velocity (length/time as derived from underlying units) and conversion factor 1.0 (calculated from underlying units). The relationship Meter_Sec = Meter / Second between (quantities of type) Meter, Second and Meter_Sec would be implemented as arithmetic operators:
public static Meter_Sec operator /(Meter lhs, Second rhs) // in Meter.cs: Meter_Sec = Meter / Second
public static Second operator /(Meter lhs, Meter_Sec rhs) // in Meter.cs: Second = Meter / Meter_Sec
public static Meter operator *(Meter_Sec lhs, Second rhs) // in Meter_Sec.cs: Meter = Meter_Sec * Second
public static Meter operator *(Second lhs, Meter_Sec rhs) // in Meter_Sec.cs: Meter = Second * Meter_SecMultiple relationships
unit Kilometer_Hour "km/h" = Kilometer / Hour | Meter_Sec * (1/1000) / ((1/60)/60);
The Kilometer_Hour unit (specified in terms of previously defined Kilometer, Hour and Meter_Sec units) can be obtained both as a quotient Kilometer / Hour and by conversion from Meter_Sec.
It has symbol "km/h" and dimension velocity. Its conversion factor is calculated from conversion factors of defining units via (quotient and conversion) expressions given in the definition. Note that both expressions must produce the same dimension and conversion factor. Otherwise the definition would be rejected.
The quotient relationship Kilometer_Hour = Kilometer / Hour would be implemented as arithmetic operators:
public static Kilometer_Hour operator /(Kilometer lhs, Hour rhs) // Kilometer.cs
public static Hour operator /(Kilometer lhs, Kilometer_Hour rhs) // Kilometer.cs
public static Kilometer operator *(Kilometer_Hour lhs, Hour rhs) // Kilometer_Hour.cs
public static Kilometer operator *(Hour lhs, Kilometer_Hour rhs) // Kilometer_Hour.csThe conversion relationship would be implemented as:
public static explicit operator Kilometer_Hour(Meter_Sec q) // Kilometer_Hour.cs
public static explicit operator Meter_Sec(Kilometer_Hour q) // Meter_Sec.csThe weird factor (1/1000) / ((1/60)/60) uses the same numbers and in the same role (numerator, denominator) as previously used in the definition of Kilometer and Hour units (and units underlying them). This way it ensures consistent conversion factors produced by both expressions in the definition i.e. factors equal up to maximum internal precision built into C# floating-point engine.