Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Temperature.cs
1using System;
2
4{
9 {
13 public Temperature()
14 {
15 }
16
20 public string Name => "Temperature";
21
25 public AtomicUnit ReferenceUnit => referenceUnit;
26
30 public Unit Reference => reference;
31
32 private static readonly AtomicUnit referenceUnit = new AtomicUnit("K");
33 private static readonly Unit reference = new Unit(referenceUnit);
34
38 public string[] BaseUnits
39 {
40 get
41 {
42 return new string[]
43 {
44 "°C",
45 //"C", // To avoid confusion with the Coulomb unit C
46 "°F",
47 //"F", // To avoid confusion with the Faraday unit F
48 "K"
49 };
50 }
51 }
52
61 public bool ToReferenceUnit(ref double Magnitude, ref double NrDecimals, string BaseUnit, int Exponent)
62 {
63 if (Exponent == 1)
64 {
65 switch (BaseUnit)
66 {
67 case "°C":
68 //case "C": // To avoid confusion with the Coulomb unit C
69 Magnitude += 273.15;
70 return true;
71
72 case "°F":
73 //case "F": // To avoid confusion with the Faraday unit F
74 Magnitude = (Magnitude - 32) / 1.8 + 273.15;
75 NrDecimals += log10_1p8;
76 return true;
77
78 case "K":
79 return true;
80 }
81 }
82
83 return false;
84 }
85
86 private static readonly double log10_1p8 = Math.Log10(1.8);
87
96 public bool FromReferenceUnit(ref double Magnitude, ref double NrDecimals, string BaseUnit, int Exponent)
97 {
98 if (Exponent == 1)
99 {
100 switch (BaseUnit)
101 {
102 case "°C":
103 //case "C": // To avoid confusion with the Coulomb unit C
104 Magnitude -= 273.15;
105 return true;
106
107 case "°F":
108 //case "F": // To avoid confusion with the Faraday unit F
109 Magnitude = (Magnitude - 273.15) * 1.8 + 32;
110 NrDecimals -= log10_1p8;
111 return true;
112
113 case "K":
114 return true;
115 }
116 }
117
118 return false;
119 }
120
121 }
122}
Represents an atomic unit.
Definition: AtomicUnit.cs:7
A temperature is an objective comparative measure of hot or cold.
Definition: Temperature.cs:9
string Name
Name of base quantity.
Definition: Temperature.cs:20
AtomicUnit ReferenceUnit
Reference unit of base quantity.
Definition: Temperature.cs:25
bool ToReferenceUnit(ref double Magnitude, ref double NrDecimals, string BaseUnit, int Exponent)
Tries to convert a magnitude from a specified base unit, to the reference unit.
Definition: Temperature.cs:61
string[] BaseUnits
Base Units supported.
Definition: Temperature.cs:39
bool FromReferenceUnit(ref double Magnitude, ref double NrDecimals, string BaseUnit, int Exponent)
Tries to convert a magnitude to a specified base unit, from the reference unit.
Definition: Temperature.cs:96
Unit Reference
Reference unit of category.
Definition: Temperature.cs:30
Temperature()
A temperature is an objective comparative measure of hot or cold.
Definition: Temperature.cs:13
Represents a unit.
Definition: Unit.cs:15
Interface for physical base quantities
Definition: IBaseQuantity.cs:7