UltimateTemperatureLibrary 1.1.1
See the version list below for details.
dotnet add package UltimateTemperatureLibrary --version 1.1.1
NuGet\Install-Package UltimateTemperatureLibrary -Version 1.1.1
<PackageReference Include="UltimateTemperatureLibrary" Version="1.1.1" />
paket add UltimateTemperatureLibrary --version 1.1.1
#r "nuget: UltimateTemperatureLibrary, 1.1.1"
// Install UltimateTemperatureLibrary as a Cake Addin #addin nuget:?package=UltimateTemperatureLibrary&version=1.1.1 // Install UltimateTemperatureLibrary as a Cake Tool #tool nuget:?package=UltimateTemperatureLibrary&version=1.1.1
Ultimate Temperature Library
The ultimate temperature library for .NET! One library to rule them all!
Introduction
The Ultimate Temperature Library brings complex functionality when working with temperatures to .NET world. Kelvin, Celsius, Fahrenheit, Rankine, Delisle, Newton, Réaumur and Rømer in one library!
Main features
- Implements all temperature scales
- .NET Standard 1.0 (multiplatform use)
- Well tested (+10000 UTs)
- OOP approach (type safety when manipulation is in place)
- Flexible parsing from string
- Double2Double convertor
- Thermophysical constants
- Accuracy at least to 12 decimal places, 13 decimal places mostly.
- Well documented.
Basic use
// Unit constructions
var celsius = new Celsius(); // Absolute zero is used when an empty unit constructor is called.
celsius = new Celsius(20.0); // Double value interpreted as 20 °C.
celsius = new Celsius(Constants.MeltingPointH2OInCelsius); // A thermo-physical constant used as double.
celsius = new Celsius("50.8 °C"); // String parsing with some Celsius scale value and unit...
celsius = new Celsius("-273.15 K"); // ...or any another unit that is transferred appropriately.
var celsius1 = new Celsius(celsius); // Directly from other unit...
var celsius2 = new Celsius(new Kelvin(Constants.MeltingPointH2OInKelvin)); // ...or any another unit.
var kelvin = new Kelvin(Constants.MeltingPointH2OInKelvin); // Same applies to other unit ctors...
var delisle = new Delisle("100 °Ré");
// Double value extraction from units
double celsiusAsDouble = celsius.Value; // Use Value property.
// Arithmetics(T2 = T1 +/- ΔT)
var celsius3 = celsius + celsius1; // Same unit...
var celsius4 = celsius + kelvin; // ...or any unit with any another unit.
celsius3 = celsius - celsius1; // Same for subtraction...
celsius4 = celsius - kelvin;
celsius3.Value = 20; // Direct manipulation with temperature value.
celsius4.Value = 30; // Direct manipulation with temperature value.
celsius3 += celsius4; // Compound operators are also provided...
celsius3 -= celsius4; // ... same for subtraction.
// Double-to-double conversion
double valueInFahrenheit = Converter.Ran2Fah(Constants.BoilingPointH2OInRankine);
// OOP Conversion
var fahrenheit = celsius.ToFahrenheit(); // From an instance.
var newton = Celsius.ToNewton(fahrenheit); // Static conversion.
// Extraction of converted temperature as double
var delisle = new Delisle().
double value = delisle.Value; // Absolute zero in Delisle is returned.
// Static conversion from a Rømer value as double to a Celsius instance and double extraction
var rømer = new Rømer();
double cel = Rømer.ToCelsius(rømer.Value).Value;
// Comparison
celsius3.Value = 20;
celsius4.Value = 20;
if (celsius3 == celsius4)
{
// ...
}
celsius = new Celsius(Constants.AbsoluteZeroInCelsius);
kelvin = new Kelvin(Constants.AbsoluteZeroInKelvin);
if (celsius == kelvin)
{
// ...
}
// Test for correctness when Value property is updated
celsius.Value = -500; // Throws an exception.
// And same behaviour applies to Kelvin, Celsius, Fahrenheit, Rankine, Delisle, Newton, Réaumur and Rømer.
Notes
Addition/Subtraction and temperature difference (ΔT) implementation
Temperature is the intensive quantity. A mixture of two objects or substances with same temperatures result in a mixture with same temperature, ergo it doesn’t make any sense to add two temperatures. Same applies to subtraction of two object with same temperature or two temperature itself.
On the other hand, it makes sense to add/subtract the temperature and the temperature difference.
If you add two temperatures, the second temperature unit is interpreted as ΔT and it is added to the first temperature. If the second temperature is negative, the magnitude of the second temperature is subtracted from the first temperature.
If you subtract two temperatures, you will receive the temperature difference in the corresponding unit.
ToString override
Every unit except Kelvin is denoted as [° PrimaryUnitID] by default. Kelvin is denoted as [K]. This PrimaryUnitID is stored in RegexPatterns
property and its override also ToString() behaviour.
Interface implementation
Every single temperature scale unit implements IConversionToUNIT, where UNIT stands for Kelvin, Celsius, Fahrenheit, Rankine, Delisle, Newton, Réaumur and Rømer, to be able to convert and compare with any another unit.
FAQ
Why no Addition/Subtraction with integers/double?
// Consider following code:
var celsius = new Celsius(20); // Totally OK. We're interpreting 20 as potential Celsius temperature value.
var celsius_result = celsius + celsius; // Still OK. Type safety in place.
celsius_result = celsius + 20; // Not OK. High possibility of human error. Is 20 really 20 °C?
// Use following construction instead:
celsius_result = celsius + new Celsius(20);
What is the order of unit parsing?
Strings are parsed for unit in following order and sub-order by default:
- Kelvin (K, Kel, Kelvin, kel, kelvin, KELVIN)
- Celsius (C, Cel, CEL, cel, Celsius, celsius, CELSIUS)
- Fahrenheit (F, Fahrenheit, Fah, fahrenheit, fah, FAHRENHEIT)
- Rankine (R, Ra, Ran, Rankine, ra, ran, rankine, RANKINE)
- Delisle (D, De, Delisle, DELISLE, delisle )
- Newton (N, Newton, newton, NEWTON)
- Réaumur (Re, Ré, re, ré, Réau, Reau, réau, reau, RÉAU, REAU, Réaumur, Reaumur, réaumur, reaumur, RÉAUMUR, REAUMUR)
- Rømer (Rø, rø, RØ, Rømer, rømer, RØMER, Ro, ro, Ro, Romer, romer, ROMER)
If no unit is present in string with valid float number, Kelvin unit is used.
What is ø and how to type ø?
ø is Latin Small Letter O with Stroke, see Links. You can type it as ALT+0216 for lowercase ø and ALT+0248 for the uppercase Ø but it depends on your OS character setup. See this or this link.
Why only addition and subtraction between units is implemented?
Multiplication/division doesn't really make any physical sense with temperature as an intensity quantity.
Links
Temperature Wikipedia<br> Conversion of temperature units Wikipedia<br> Kelvin scale Wikipedia<br> Celsius scale Wikipedia<br> Rankine scale Wikipedia<br> Delisle scale Wikipedia<br> Newton scale Wikipedia<br> Réaumur scale Wikipedia<br> Rømer scale Wikipedia<br> Latin Small Letter O with Stroke<br> Latin Capital Letter O with Stroke<br>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.1.1.0:
- Added some missing commentary of IEquality methods for common ancestor of all temperature scales.
v1.1.0.0:
- Removed public modifier to Regex patterns.
v1.0.0.0:
- Initial public release.