-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.units
49 lines (45 loc) · 1019 Bytes
/
example.units
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package example;
// base units are declared as simple identifiers, and derived units can be expressed in terms of the base units
unit (
M;
S;
MpS = M / S;
H = S * 3600;
KM = 1000 * M;
KMpH = KM / H;
NM = 1852 * M;
KN = NM / H;
BF;
Min = 60*S;
)
// quantities are defined with a specified unit and a base type
quantity (
Scalar() float64;
Length(M) float64;
Area(M^2) float64;
Time(S) float64;
Frequency(1 / S) float64;
RPM(1 / Min) float64;
Distance(KM) float64;
Duration(H) float64;
Speed(KM/H) float64;
Beaufort(BF) int;
)
// operations are explicitly defined for each quantity
operation (
Length * Length -> Area;
Length % Length -> Length;
Beaufort % Beaufort -> Beaufort;
Length / Length -> Scalar;
Length + Length -> Length;
Length - Length -> Length;
Length * Scalar -> Length;
Time * Scalar -> Time;
Distance / Duration -> Speed;
Speed * Duration -> Distance;
Scalar / Time -> Frequency;
)
conversion (
Frequency -> RPM;
RPM -> Frequency;
)