-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefinitions.txt
493 lines (441 loc) · 18.8 KB
/
definitions.txt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/*******************************************************************************
Units of Measurement for C# and C++ applications
Copyright (C) Marek Aniola
This program is provided to you under the terms of the license
as published at https://github.com/mangh/metrology
The definitions below (in particular conversion factors) are
based on Wikipedia at http://en.wikipedia.org/wiki/Conversion_of_units
********************************************************************************/
////////////////////////////////////////////////////////////////////////////////
//
// Primary Units
//
unit Meter "m" = <Length>;
unit Second "s" = <Time>;
unit Kilogram "kg" = <Mass>;
unit DegKelvin "K" "deg.K" = <Temperature>;
unit Ampere "A" = <ElectricCurrent>;
unit Mole "mol" = <AmountOfSubstance>;
unit Candela "cd" = <LuminousIntensity>;
unit<decimal> EUR "EUR" = <Money>; // Euro
////////////////////////////////////////////////////////////////////////////////
//
// Length
//
unit Centimeter "cm" = 100 * Meter;
unit Millimeter "mm" = 1000 * Meter;
//unit Micron "\u00B5m" "micrometer" = 1.0e6 * Meter;
//unit Nanometer "nm" "nanometer" = 1.0e9 * Meter;
//unit Angstrom "\u00C5" "angstrom" = 1.0e10 * Meter;
unit Kilometer "km" = Meter / 1000;
unit Inch "in" = Millimeter / 25.4;
unit /* international */ Foot "ft" = Inch / 12;
unit /* international */ Yard "yd" = Foot / 3;
unit /* international */ Mile "mil" = Yard / 1760;
//unit /* PostScript */ Point "pt" = 72 * Inch;
//unit Pica "pc" = Point / 12;
////////////////////////////////////////////////////////////////////////////////
//
// Time
//
unit Minute "min" = Second / 60;
unit Hour "h" = Minute / 60;
//unit Day "d" = Hour / 24;
//unit Week "wk" = Day / 7;
//unit /* full */ Month "mo" = Day / 30;
//unit /* common */ Year "yr" = Day / 365;
////////////////////////////////////////////////////////////////////////////////
//
// Mass
//
unit Gram "g" = 1000 * Kilogram;
//unit Microgram "\u03BCg" "ug" = 1.0e6 * Gram;
unit Tonne "t" = Kilogram / 1000;
unit /* avoirdupois */ Pound "lb" = Kilogram / 0.45359237;
unit /* avoirdupois */ Ounce "ou" = Pound * 16;
////////////////////////////////////////////////////////////////////////////////
//
// Temperature
//
unit DegCelsius "\u00B0C" "deg.C" = DegKelvin;
unit DegRankine "\u00B0R" "deg.R" = (9 / 5) * DegKelvin;
unit DegFahrenheit "\u00B0F" "deg.F" = (9 / 5) * DegKelvin;
scale Kelvin AbsoluteZero = DegKelvin 0.0;
scale Celsius AbsoluteZero = DegCelsius -273.15;
scale Rankine AbsoluteZero = DegRankine 0.0;
scale Fahrenheit AbsoluteZero = DegFahrenheit -273.15 * (9 / 5) + 32;
////////////////////////////////////////////////////////////////////////////////
//
// Electric Current
//
////////////////////////////////////////////////////////////////////////////////
//
// Amount of Substance
//
////////////////////////////////////////////////////////////////////////////////
//
// Luminous Intensity
//
////////////////////////////////////////////////////////////////////////////////
//
// Currencies
//
// NOTE: the rates (conversion factors) below
// are to be updated on application startup.
//
unit<decimal> USD "USD" = 1.3433 * EUR; // US Dollar
//unit<decimal> JPY "JPY" = 136.74 * EUR; // Japanese Yen
//unit<decimal> BGN "BGN" = 1.9558 * EUR; // BulgarianLev
//unit<decimal> CZK "CZK" = 27.481 * EUR; // Czech Koruna
//unit<decimal> DKK "DKK" = 7.4565 * EUR; // DanishKrone
unit<decimal> GBP "GBP" = 0.79055 * EUR; // British Pound
//unit<decimal> HUF "HUF" = 308.20 * EUR; // Hungarian Forint
//unit<decimal> LTL "LTL" = 3.4528 * EUR; // Lithuanian Litas
unit<decimal> PLN "PLN" = 4.1437 * EUR; // Polish Zloty
//unit<decimal> RON "RON" = 4.3888 * EUR; // Romanian New Lei
//unit<decimal> SEK "SEK" = 9.1523 * EUR; // SwedishKrona
//unit<decimal> CHF "CHF" = 1.2150 * EUR; // SwissFranc
//unit<decimal> NOK "NOK" = 8.3365 * EUR; // NorwegianKroner
//unit<decimal> HRK "HRK" = 7.6372 * EUR; // Croatian Kuna
//unit<decimal> RUB "RUB" = 47.5507 * EUR; // Russian Rouble
//unit<decimal> TRY "TRY" = 2.8204 * EUR; // Turkish Lira
//unit<decimal> AUD "AUD" = 1.4275 * EUR; // Australian Dollar
//unit<decimal> BRL "BRL" = 2.9952 * EUR; // Brazilian Real
//unit<decimal> CAD "CAD" = 1.4520 * EUR; // Canadian Dollar
//unit<decimal> CNY "CNY" = 8.3110 * EUR; // Chinese Yuan Renminbi
//unit<decimal> HKD "HKD" = 10.4107 * EUR; // Hong Kong Dollar
//unit<decimal> IDR "IDR" = 15550.26 * EUR; // Indonesian Rupiah
//unit<decimal> ILS "ILS" = 4.6056 * EUR; // Israeli New Shekel
//unit<decimal> INR "INR" = 80.6813 * EUR; // Indian Rupee
//unit<decimal> KRW "KRW" = 1379.01 * EUR; // South-Korean Won
//unit<decimal> MXN "MXN" = 17.4092 * EUR; // Mexican Peso
//unit<decimal> MYR "MYR" = 4.2679 * EUR; // Malaysian Ringgit
//unit<decimal> NZD "NZD" = 1.5703 * EUR; // New Zealand Dollar
//unit<decimal> PHP "PHP" = 58.246 * EUR; // Philippine Peso
//unit<decimal> SGD "SGD" = 1.6674 * EUR; // Singapore Dollar
//unit<decimal> THB "THB" = 42.720 * EUR; // Thai Baht
//unit<decimal> ZAR "ZAR" = 14.1523 * EUR; // South African Rand
////////////////////////////////////////////////////////////////////////////////
//
// Plane angle (dimensionless)
//
// NOTE: explicit format "{0}{1}" used in places
// to remove space separating {value} and {symbol}
//
// NOTE: arithmetic expressions can use string literals e.g. "Math.PI".
// In general parser blindly accepts string literals as numbers of unknown
// value leaving their evaluation and syntax check to the compiler.
//
// NOTE: the literals "Math.PI" (or "System.Math.PI") and "Math.E" (or
// "System.Math.E") are an exception to the above rule: they are recognized
// and their numeric value used to validate definitions of "units" and "scale".
//
unit Radian "rad" = <>;
unit Degree "\u00B0" "deg" : "{0}{1}" = (180 / "Math.PI") * Radian;
//unit ArcMinute "\u2032" "'" : "{0}{1}" = 60 * Degree;
//unit ArcSecond "\u2033" "\"" : "{0}{1}" = 60 * ArcMinute;
unit Grad "grad" = (200 / "Math.PI") * Radian;
unit Turn /* aka. cycle, revolution, rotation */ "tr" = Radian / (2 * "Math.PI");
///////////////////////////////////////////////////////////////////////////////
//
// Solid angle (dimensionless)
//
//unit Steradian "sr" = <>;
//unit SquareDegree "deg\u00B2" "deg2" = ((180 / "Math.PI") * (180 / "Math.PI")) * Steradian;
////////////////////////////////////////////////////////////////////////////////
//
// Frequency
//
unit Hertz "Hz" = 1 / Second;
//unit KiloHertz "kHz" = Hertz / 1000;
//unit MegaHertz "MHz" = KiloHertz / 1000;
//unit GigaHertz "GHz" = MegaHertz / 1000;
////////////////////////////////////////////////////////////////////////////////
//
// Angular Frequency (aka. Rotational Velocity)
//
// NOTE: parser tries to verify whether alternative formulas e.g.:
//
// Degree / Second
// and
// (180 / "Math.PI") * Radian_Sec
//
// in Degree_Sec definition below are consistent i.e. whether they
// produce the same conversion factor and dimension.
//
// NOTE: as a general rule, string literals in formulas are taken
// as numbers of unknown value and this prevents parser to verify
// whether the alternative formulas produce the same factor.
//
// NOTE: the literals "Math.PI" and "Math.E" are exceptions
// to this rule: parser recognizes them and uses their value
// for validation.
//
// NOTE: other literals prevents the factor check: you have to
// take care of the consistency by other means (e.g. unit tests).
//
unit Radian_Sec "rad/s" = Radian / Second | Radian * Hertz;
unit Degree_Sec "\u00B0/s" "degree/s" = Degree / Second | (180 / "Math.PI") * Radian_Sec;
unit RPM "rpm" = Turn / Minute | (30 / "Math.PI") * Radian_Sec;
////////////////////////////////////////////////////////////////////////////////
//
// Area
//
// NOTE: Foot2 (square foot) definition below (as well as many others)
// specifies conversion factor as an expression
//
// ((100/2.54)/12) * ((100/2.54)/12)
//
// rather than its approximate equivalent e.g. 10.7639104167097. The
// expression uses the same numbers as previously used in Foot definition.
// Thus it mimics calculations being made in Foot * Foot associate
// formula and ensures that both formulas are consistent. Approximate
// equivalents are very likely to produce inconsistencies.
//
// NOTE: conversion factors are consistent if they are equal (==) up to
// maximum internal precision built into C# floating-point engine
// (17 digits for doubles). No rounding is applied. However, C# displays
// up to 15 digits only on output (for doubles). Thus it may happen the
// parser will complain about inconsistent factors (unequal in 17 digits)
// but display them (using 15 digits) as equal in an error message e.g.:
//
// "Foot.Factor * Foot.Factor" == 10.7639104167097 != 10.7639104167097 == "Meter2.Factor * 10.7639104167097d"
//
// In such cases the parser is right - the factors are not consistent -
// but it cannot display them correctly.
//
unit Meter2 "m\u00B2" "m2" = Meter * Meter;
//unit Centimeter2 "cm\u00B2" "cm2" = Centimeter * Centimeter | Meter2 * 1.0e4;
//unit Kilometer2 "km\u00B2" "km2" = Kilometer * Kilometer | Meter2 / 1.0e6;
//unit Inch2 "in\u00B2" "sq in" = Inch * Inch | Meter2 * (100/2.54) * (100/2.54);
//unit Foot2 "ft\u00B2" "sq ft" = Foot * Foot | Meter2 * ((100/2.54)/12) * ((100/2.54)/12);
//unit Yard2 "yd\u00B2" "sq yd" = Yard * Yard | Meter2 * (((100/2.54)/12)/3) * (((100/2.54)/12)/3);
//unit Mile2 "mil\u00B2" "sq mil" = Mile * Mile | Meter2 * ((((100/2.54)/12)/3)/1760) * ((((100/2.54)/12)/3)/1760);
//unit Barn "b" = Meter2 / 1.0e-28;
////////////////////////////////////////////////////////////////////////////////
//
// Volume
//
unit Meter3 "m\u00B3" "m3" = Meter2 * Meter;
//unit Liter "L" = Meter3 * 1000;
//unit Centimeter3 "cm\u00B3" "cm3" = Centimeter2 * Centimeter | Meter3 * 1.0e6;
//unit Inch3 "in\u00B3" "cu in" = Inch2 * Inch | Meter3 * (100/2.54) * (100/2.54) * (100/2.54);
//unit Foot3 "ft\u00B3" "cu ft" = Foot2 * Foot | Meter3 * ((100/2.54)/12) * ((100/2.54)/12) * ((100/2.54)/12);
//unit Yard3 "yd\u00B3" "cu yd" = Yard2 * Yard | Meter3 * (((100/2.54)/12)/3) * (((100/2.54)/12)/3) * (((100/2.54)/12)/3);
////////////////////////////////////////////////////////////////////////////////
//
// Velocity
//
unit Meter_Sec "m/s" = Meter / Second;
unit Centimeter_Sec "cm/s" = Centimeter / Second | 100 * Meter_Sec;
unit Kilometer_Hour "km/h" = Kilometer / Hour | Meter_Sec * (1/1000) / ((1/60)/60);
unit MPH "mph" "mi/h" = Mile / Hour | Meter_Sec * ((((100/2.54)/12)/3)/1760) / ((1/60)/60);
////////////////////////////////////////////////////////////////////////////////
//
// Acceleration
//
unit Meter_Sec2 "m/s\u00B2" "m/s2" = Meter_Sec / Second;
////////////////////////////////////////////////////////////////////////////////
//
// Velocity squared (kinetic and potential energy subexpressions)
//
unit Meter2_Sec2 "m\u00B2/s\u00B2" "m2/s2" = Meter_Sec * Meter_Sec | Meter_Sec2 * Meter;
////////////////////////////////////////////////////////////////////////////////
//
// Kinematic viscosity (aka.
// thermal diffusivity,
// momentum diffusivity,
// specific angular momentum)
//
//unit Meter2_Sec "m\u00B2/s" "m2/s" = Meter2 / Second | Meter_Sec * Meter | Meter2_Sec2 * Second;
////////////////////////////////////////////////////////////////////////////////
//
// Linear mass density
//
//unit Gram_Meter "g/m" = Gram / Meter;
//unit Gram_Kilometer "g/km" = Gram / Kilometer | Gram_Meter * 1000;
//unit Gram_Mile "g/mi" = Gram / Mile | Gram_Meter / (1000/(25.4*12*3*1760));
//unit Microgram_Meter "\u03BCg/m" "ug/m" = Microgram / Meter | 1000000 * Gram_Meter;
////////////////////////////////////////////////////////////////////////////////
//
// Volumetric mass density (aka. specific mass, mass concentration)
//
//unit Gram_Meter3 "g/m\u00B3" "g/m3" = Gram / Meter3;
//unit Microgram_Meter3 "\u03BCg/m\u00B3" "ug/m3" = Microgram / Meter3 | 1.0e6 * Gram_Meter3;
////////////////////////////////////////////////////////////////////////////////
//
// Molar Volume
//
//unit Meter3_Mole "m\u00B3/mol" "m3/mol" = Meter3 / Mole;
////////////////////////////////////////////////////////////////////////////////
//
// Molar mass
//
//unit Gram_Mole "g/mol" = Gram / Mole | Gram_Meter3 * Meter3_Mole;
//unit Microgram_Mole "\u03BCg/mol" "ug/mol" = Microgram / Mole | Microgram_Meter3 * Meter3_Mole | 1.0e6 * Gram_Mole;
////////////////////////////////////////////////////////////////////////////////
//
// Force
//
unit Newton "N" = Kilogram * Meter_Sec2;
//unit KilogramForce "kgf" = Newton / 9.80665;
unit PoundForce "lbf" = Newton / 4.4482216152605;
unit Poundal "pdl" = Newton / 0.138254954376;
unit Dyne "dyn" = 1.0e5 * Newton;
////////////////////////////////////////////////////////////////////////////////
//
// Energy
//
unit Joule "J" = Newton * Meter | Kilogram * Meter2_Sec2;
//unit /* international */ Calorie "cal" = Joule / 4.1868;
//unit /* international */ BTU "btu" = Joule / 1055.05585262;
//unit KiloWattHour "kWh" = Joule / 3.6e6;
//unit Erg "erg" = 1.0e7 * Joule;
////////////////////////////////////////////////////////////////////////////////
//
// Power
//
unit Watt "W" = Joule / Second;
//unit KiloWatt "kW" = Watt / 1000 | KiloWattHour / Hour;
//unit /* international */ BTU_Hour "btu/h" = BTU / Hour | Watt * (1/1055.05585262) / (1/3600);
////////////////////////////////////////////////////////////////////////////////
//
// Torque (moment of force)
//
// NOTE: We can't specify:
//
// NewtonMeter ... = Newton * Meter
//
// as we have already specified
//
// Joule ... = Newton * Meter
//
// and that (as a product of 2 units), would generate operators of the same
// arguments but different return values:
//
// Joule operator *(Newton lhs, Meter rhs)
// NewtonMeter operator *(Newton lhs, Meter rhs)
//
// and the compiler wouldn't know which one to apply when it finds such product.
//
// To work around the problem you can make use of wedge product ("^" operator
// instead of star "*"):
//
// NewtonMeter "N*m" = Newton ^ Meter
//
// The resulting NewtonMeter unit would be of the same dimension as Joule but
// of different family:
//
// NewtonMeter.Sense == Joule.Sense
// NewtonMeter.Family != Joule.Family
//
unit NewtonMeter "N\u00B7m" "N*m" = Newton ^ Meter;
//unit DyneCentimeter "dyn\u00B7cm" "dyn*cm" = Dyne ^ Centimeter | NewtonMeter * 1.0e7;
//unit PoundFoot "lbf\u00B7ft" "lbf*ft" = PoundForce ^ Foot | NewtonMeter * (100/2.54/12/4.4482216152605);
//unit PoundInch "lbf\u00B7in" "lbf*in" = PoundForce ^ Inch | NewtonMeter * (100/2.54/4.4482216152605);
////////////////////////////////////////////////////////////////////////////////
//
// Heat capacity
//
unit Joule_Kelvin "J/K" = Joule / DegKelvin;
//unit Calorie_Kelvin "cal/K" = Calorie / DegKelvin | Joule_Kelvin / 4.1868;
//unit BTU_Fahrenheit "BTU/\u00B0F" "BTU/deg.F" = BTU / DegFahrenheit | Joule_Kelvin * (1 / 1055.05585262) / (9 / 5);
////////////////////////////////////////////////////////////////////////////////
//
// Specific heat capacity
//
unit Joule_Kelvin_Kilogram "J/kg/K" = Joule_Kelvin / Kilogram;
//unit Calorie_Kelvin_Gram "cal/g/K" = Calorie_Kelvin / Gram | Joule_Kelvin_Kilogram * (1 / 4.1868) / (1000);
//unit BTU_Fahrenheit_Pound "BTU/lb/\u00B0F" "BTU/lb/deg.F" = BTU_Fahrenheit / Pound | Joule_Kelvin_Kilogram * (1/1055.05585262)/(9/5) * 0.45359237;
//unit Joule_Kelvin_Mole "J/mol/K" = Joule_Kelvin / Mole;
//unit Joule_Kelvin_Meter3 "J/m3/K" = Joule_Kelvin / Meter3;
////////////////////////////////////////////////////////////////////////////////
//
// Pressure
//
unit Pascal "Pa" = Newton / Meter2;
unit Bar "bar" = Pascal / 1.0e5;
unit AtmTechnical "at" = Pascal / 9.80665e4;
unit AtmStandard "atm" = Pascal / 1.01325e5;
unit MillimeterHg "mmHg" = Pascal * (13.5951 * 9.80665);
////////////////////////////////////////////////////////////////////////////////
//
// Electric charge
//
unit Coulomb "C" = Ampere * Second;
//unit AmpereHour "A\u00B7h" "Ah" = Ampere * Hour | Coulomb / 3600;
////////////////////////////////////////////////////////////////////////////////
//
// Electric potential (voltage)
//
unit Volt "V" = Joule / Coulomb | Watt / Ampere;
////////////////////////////////////////////////////////////////////////////////
//
// Electric resistance
//
unit Ohm "\u03A9" "ohm" = Volt / Ampere;
//
// NOTE: There are many other formulas for Ohm e.g.:
//
// Ohm = Joule * Second / (Coulomb * Coulomb),
// Ohm = Watt / (Ampere * Ampere).
//
// Should you need them, then you should define some auxiliary units e.g.:
//
// unit Coulomb2 "C2" = Coulomb * Coulomb;
// unit Ampere2 "A2" = Ampere * Ampere;
// unit JouleSecond "J*s" = Joule * Second;
//
// and specify Ohm as:
//
// unit Ohm "ohm" "\u03A9" = JouleSecond / Coulomb2 | Watt / Ampere2;
//
// (Should you specify:
//
// unit Ohm "ohm" "\u03A9" = Joule * Second / (Coulomb * Coulomb) | Watt / (Ampere * Ampere);
//
// then no operators supporting these formulas would be generated but, of course,
// you could implement some helper mehods in an extension file).
//
////////////////////////////////////////////////////////////////////////////////
//
// Electric conductance
//
unit Siemens "S" = Ampere / Volt;
//
// NOTE: should the above definition specify also the formula: 1 / Ohm,
// then the following operators would be also generated (in Siemens.cs file):
//
// public static Ohm operator /(double lhs, Siemens rhs) => new(lhs / rhs.Value);
// public static double operator *(Siemens lhs, Ohm rhs) => lhs.Value * rhs.Value;
// public static double operator *(Ohm lhs, Siemens rhs) => lhs.Value * rhs.Value;
//
// which is not exactly what the formula means (i.e. the reciprocal of resitance).
// It'd be better to implement it as a pair of properties in extension files
// (e.g.: OhmEx.cs and SiemensEx.cs), for example:
//
// public partial struct Ohm
// {
// public Siemens Conductance => new(1.0 / Value);
// }
//
// public partial struct Siemens
// {
// public Ohm Resistance => new(1.0 / Value);
// }
//
////////////////////////////////////////////////////////////////////////////////
//
// Electric capacitance
//
unit Farad "F" = Coulomb / Volt | Second / Ohm;
//unit MilliFarad "mF" = 1.0e3 * Farad;
//unit MicroFarad "\u00B5F" "microF" = 1.0e6 * Farad;
//unit NanoFarad "nF" = 1.0e9 * Farad;
//unit PicoFarad "pF" = 1.0e12 * Farad;
////////////////////////////////////////////////////////////////////////////////
//
// Magnetic flux
//
unit Weber "Wb" = Joule / Ampere | Volt * Second;
//unit Maxwell "Mx" = 1.0e8 * Weber;