Quantify.NET 0.0.0-preview-002

This is a prerelease version of Quantify.NET.
dotnet add package Quantify.NET --version 0.0.0-preview-002
                    
NuGet\Install-Package Quantify.NET -Version 0.0.0-preview-002
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Quantify.NET" Version="0.0.0-preview-002" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Quantify.NET" Version="0.0.0-preview-002" />
                    
Directory.Packages.props
<PackageReference Include="Quantify.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Quantify.NET --version 0.0.0-preview-002
                    
#r "nuget: Quantify.NET, 0.0.0-preview-002"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Quantify.NET@0.0.0-preview-002
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Quantify.NET&version=0.0.0-preview-002&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Quantify.NET&version=0.0.0-preview-002&prerelease
                    
Install as a Cake Tool

alt text

Quantify.NET

A library to make usages of quantities easier and safer.

Key Features

  • Strongly typed quantities and units: Quantify.NET uses a strongly typed approach to quantities and units. This means, for example, that you can't pass a length to a mass parameter. Reducing the risk of errors in your code.
  • Extensive quantity support: Quantify.NET supports more than 100 quantities out-of-the-box. This includes common quantities like length, mass, time, temperature, and many more. See the supported quantities section for a complete list.
  • Extensive unit support: Quantify.NET supports almost all imaginable units for each supported quantity. This includes common units like meter, kilogram, second, and many more. Using the unit builders, almost all units can dynamically be build. Still missing a unit? Just create a new unit by calling for example LengthUnit.CreateCustomUnit and pass the unit name and the conversion factor to the base unit. Or alternatively create an issue to add the unit to the library.
  • Complex unit builders: Quantify.NET supports building complex units. For example, the SI unit of Power can be described as kg * m^2 / s^-3 and can be build using Quantify.NET using PowerUnit.Kilo.Gram.Meter.Squared.Per.Second.Cubed.
  • Unit conversion: Quantify.NET can convert quantities to other units. This is done by using the ConvertTo method.
  • Parsing: Quantify.NET supports parsing of quantities and units. This can be done using the Parse or TryParse methods.
  • Arithmetic operations: Quantities support arithmetic operations on quantities. This includes addition, subtraction, multiplication and division.
  • Comparison: Quantities can be compared with each other with respect to units. (e.g. 5 cm == 0.05 m)

Installation

NuGet

Install-Package Quantify.NET

Usage

Basic usage

using Quantify.Quantities;
using Quantify.Quantities.Units;

// Create a new quantity
Length meters = Length.Of(5, LengthUnit.Meter);

// Convert the quantity to another unit
Length lengthInFeet = meters.ConvertTo(LengthUnit.Foot);

More complex units


using Quantify.Quantities;
using Quantify.Quantities.Units;

// Create more complex units (1 Watt == 1 kg * m^2 / s^3))
Power power = Power.Of(5, PowerUnit.Kilo.Gram.Meter.Squared.Per.Second.Cubed);

// Convert the quantity to another unit (in logarithmic scale for example)
Power powerInDecibelMilliwatts = power.ConvertTo(PowerUnit.DecibelMilliwatt);

Parsing

using Quantify.Quantities;
using Quantify.Quantities.Units;

// Parse a quantity
Length length = Length.Parse("5 m");

// Parse a unit
LengthUnit lengthUnit = LengthUnit.Parse("cm");
PowerUnit powerUnit = PowerUnit.Parse("kg.m².s⁻³");

Arithmetic operations


using Quantify.Quantities;
using Quantify.Quantities.Units;

// Create a new quantity
Length length1 = Length.Of(500, LengthUnit.Mile);
Length length2 = Length.Of(10, LengthUnit.Meter);

// Add two quantities
Length length3 = length1 + length2;

// Subtract two quantities
Length length4 = length1 - length2;

// Substract or add non-absolute quantities
Temperature t = Temperature.Of(10, TemperatureUnit.Celsius) + TemperatureDifference.Of(32, TemperatureDifferenceUnit.Fahrenheit);

// Multiply a quantity with a scalar
Length length5 = length1 * 5;

// Divide a quantity by a scalar
Length length6 = length1 / 5;

// Arithmetics between two quantities can result in a new quantity type
Area area = length1 * length2;
Velocity velocity = length1 / Time.Of(10, TimeUnit.Minute);

Comparison


using Quantify.Quantities;
using Quantify.Quantities.Units;

// Create quantities
var length1 = Length.Of(5, LengthUnit.Meter);
var length2 = Length.Of(5, LengthUnit.Centi.Meter);

// Compare two quantities with respect of the unit
var isLength1GreaterThanLength2 = length1 > length2; // true
var isLength1LessThanLength2 = length1 < length2; // false
var isLength1EqualToLength2 = length1 == length2; // false

Supported quantities

Quantity SI unit Description Link
Absackle m.s^6 Absackle is the sixth time-integral of displacement link
Abseleration m.s^3 Abseleration is the third time-integral of displacement link
Absement m.s Absement is the first time-integral of displacement link
Abserk m.s^4 Abserk is the fourth time-integral of displacement link
Absity m.s^2 Absity is the second time-integral of displacement link
Absnap m.s^5 Absnap is the fifth time-integral of displacement link
Absop m.s^7 Absop is the seventh time-integral of displacement link
AbsorbedDose Gy Absorbed dose represents the energy per unit of mass deposited by ionizing radiation in living matter link
AbsorbedDoseRate Gy.s^-1 Absorbed dose rate is the absorbed dose per unit of time link
Acceleration m.s^-2 Acceleration is the rate of change of the velocity of an object with respect to time. link
Action J/Hz Action is a quantity that describes how the balance of kinetic versus potential energy of a physical system changes with trajectory. link
AmountOfSubstance mol Represents the quantity of amount of substance, the number of particles in a sample. link
Angle rad The ratio of circular arc length to radius link
AngularAcceleration rad.s^-2 The time rate of change of angular velocity link
AngularFrequency rad.s^-1 Angular frequency is the change of an angle per unit of time. link
AngularMomentum kg.m^2.s^-1 Angular momentum describes the rotary intertia of an object or system about an axis. link
AngularVelocity rad.s^-1 Angular velocity is the rate of change of angular displacement with respect to time. link
Area m^2 Area is the quantity that expresses the extent of a two-dimensional surface or shape in the plane. link
AreaDensity kg.m^-2 Area density is the mass per unit area. link
Capacitance F Capacitance is the ability of a body to store an electrical charge. link
CentrifugalForce N.rad Centrifugal force is a fictitious force that appears to act on an object moving in a circular path. link
ChemicalPotential J.mol^-1 Chemical potential is a measure of the energy that is stored in a substance due to the arrangement of its atoms or molecules. link
Compressibility Pa^-1 Compressibility is a measure of the relative volume change of a fluid or solid as a response to a pressure (or mean stress) change. link
Crackle m.s^-5 Crackle is the fifth time derivative of position link
DeltaTemperature K The difference in temperature link
Density kg.m^-3 Density is a measure of the amount of mass in a given volume. link
DynamicViscosity Pa.s Dynamic viscosity is a measure of a fluid's resistance to deformation. link
ElectricalConductance S The electrical conductance of an object is a measure of its ability to conduct an electric current. link
ElectricalConductivity S.m^-1 The electrical conductance of an object is a measure of its ability to conduct an electric current per unit of length. link
ElectricalResistance Ω The electrical resistance of an object is a measure of its opposition to the flow of electric current. link
ElectricalResistivity Ω.m The electrical resistivity of an object is a measure of its opposition to the flow of electric current per unit of length. link
ElectricCharge C Electric charge is a physical property of matter that causes it to experience a force when placed in an electromagnetic field link
ElectricChargeDensity C.m^-3 The electric charge density is a measure of the electric charge per unit volume. link
ElectricCurrent A Electric current is the rate of flow of electric charge past a point or region. link
ElectricCurrentDensity A.m^-2 Electric current density is the electric current per unit area. link
ElectricDipoleMoment C.m The electric dipole moment is a measure of the separation of positive and negative electrical charges within a system: that is, a measure of the system's overall polarity. link
ElectricDisplacementField C.m^-2 The electric displacement field, also called electric flux density, is a vector field that appears in Maxwell's equations. It accounts for the electromagnetic effects of polarization and that of an electric field, combining the two in an auxiliary field. link
ElectricPotential V Electric potential is defined as the amount of work/energy needed per unit of electric charge to move the charge from a reference point to a specific point in an electric field. link
ElectricPotentialDifference (Voltage) V Electric potential difference is the difference in electric potential between two points link
ElectricFieldStrength V.m^-1 The electric field strength is a measure of the electric force per unit charge. link
Energy J Energy is the capacity to do work, where work is the action of a force through a distance. link
EnergyDensity J.m^-3 Energy density is the amount of energy stored in a given system or region of space per unit volume. link
Entropy J.K^-1 Entropy is a scientific concept, most commonly associated with states of disorder, randomness, or uncertainty. It is a measure of the amount of energy in a physical system that is not available to do work. link
EquivalentDose Sv Equivalent dose is a measure of the biological effect of ionizing radiation. link
Force N Force is the push or pull exerted on an object to change its motion. link
Frequency Hz Frequency is the number of occurrences of a repeating event per unit of time. link
HalfLife s Half-life is the time required for a quantity to reduce to half its initial value. link
Heat J Heat is a form of energy that is transferred between systems or objects with different temperatures (or energy states) and is often referred to as thermal energy. link
HeatCapacity J.K^-1 Heat capacity is the amount of heat energy required to raise the temperature of a substance by a certain amount. link
HeatFlux W.m^-2 The heat flux is the rate of heat energy transfer through a surface per unit area. link
Illuminance lx description TODO
Impedance Ω description TODO
Impulse N.s description TODO
Inductance H description TODO
Intensity W.m^-2 description TODO
Irradiance W.m^-2 description TODO
Jerk m.s^-3 description TODO
KinematicViscosity m^2.s^-1 description TODO
Length m Length is a measure of distance between two points. link
LinearDensity kg.m^-1 description TODO
LuminousFlux lm description TODO
LuminousIntensity cd Luminous intensity is a measure of the wavelength-weighted power emitted by a light source in a particular direction per unit solid angle, based on the luminosity function, a standardized model of the sensitivity of the human eye. link
MagneticFieldStrength A.m^-1 description TODO
MagneticFlux Wb description TODO
MagneticFluxDensity T description TODO
MagneticMoment A.m^2 description TODO
MagneticReluctance H^-1 description TODO
Magnetization A.m^-1 description TODO
Mass kg Mass is a measure of the amount of matter in an object. link
MassConcentration kg/kg description link
MassFlow kg.s^-1 description link
MolarConcentration mol.m^-3 description TODO
MolarEnergy J.mol^-1 description TODO
MolarEntropy J.K^-1.mol description TODO
MolarHeatCapacity J.K^-1.mol^-1 description TODO
MomentOfInertia kg.m^2 description TODO
Momentum kg.m.s^-1 description TODO
OpticalPower dpt description TODO
Permeability H.m^-1 description TODO
Permittivity F.m^-1 description TODO
Pop m.s^-6 description TODO
Power W Power is the rate at which work is done or energy is transferred. link
Pressure Pa Pressure is the force applied perpendicular to the surface of an object per unit area over which that force is distributed. link
PressureGradient Pa.m^-1 description TODO
Radiance W.sr^-1.m^-2 description TODO
RadiantIntensity W.sr^-1 description TODO
Radioactivity Bq description TODO
ReactionRate mol.m^-3.s^-1 description TODO
Snap m.s^-4 description TODO
SolidAngle sr description TODO
SpecificHeatCapacity J.K^-1.kg^-1 description TODO
Temperature K Temperature is a physical quantity that quantitatively expresses the attribute of hotness or coldness. It reflects the average kinetic energy of the vibrating and colliding atoms making up a substance. link
TemperatureGradient K.m^-1 description TODO
ThermalConductivity W.m^-1.K^-1 description TODO
ThermalInsulance m^2.K.W^-1 description TODO
ThermalResistance K.W^-1 description TODO
ThermalResistivity K.m.W^-1 description TODO
Time s Time is the indefinite continued progress of existence and events that occur in an apparently irreversible succession from the past, through the present, into the future. link
Torque N.m description TODO
Velocity m.s^-1 Velocity is the rate of change of the position of an object with respect to a frame of reference. link
Volume m^3 Volume is the quantity that expresses the three-dimensional space occupied by a substance or enclosed by a surface. link
VolumeConcentration m^3/m^3 description TODO
VolumeFlow m^3^.s^-1^ description TODO
Weight N description TODO
Work J description TODO

Roadmap

License

Quantify.NET is licensed under the MIT License. See LICENSE for details.

Benchmarks


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.26100
13th Gen Intel Core i7-13700K, 1 CPU, 24 logical and 16 physical cores
.NET SDK=9.0.201
  [Host]     : .NET 9.0.3 (9.0.325.11113), X64 RyuJIT
  DefaultJob : .NET 9.0.3 (9.0.325.11113), X64 RyuJIT


Method UnitFrom unitTo Mean Error StdDev Rank Allocated
ConvertUnit J.s⁻¹ J.s⁻¹ 32.51 ns 0.273 ns 0.256 ns ******** -
ConvertUnit J.s⁻¹ W 31.49 ns 0.190 ns 0.178 ns ******* -
ConvertUnit J.s⁻¹ hp 32.43 ns 0.113 ns 0.105 ns ******** -
ConvertUnit J.s⁻¹ kg.m².s⁻³ 34.38 ns 0.159 ns 0.148 ns ********** -
ConvertUnit W J.s⁻¹ 31.56 ns 0.187 ns 0.175 ns ******* -
ConvertUnit W W 28.43 ns 0.115 ns 0.108 ns ***** -
ConvertUnit W hp 30.42 ns 0.128 ns 0.114 ns ****** -
ConvertUnit W kg.m².s⁻³ 32.95 ns 0.228 ns 0.213 ns ******** -
ConvertUnit hp J.s⁻¹ 32.16 ns 0.246 ns 0.230 ns ******** -
ConvertUnit hp W 30.12 ns 0.183 ns 0.171 ns ****** -
ConvertUnit hp hp 30.28 ns 0.171 ns 0.152 ns ****** -
ConvertUnit hp kg.m².s⁻³ 34.83 ns 0.312 ns 0.291 ns ********** -
ConvertUnit kg.m².s⁻³ J.s⁻¹ 34.76 ns 0.305 ns 0.285 ns ********** -
ConvertUnit kg.m².s⁻³ W 33.63 ns 0.114 ns 0.101 ns ********* -
ConvertUnit kg.m².s⁻³ hp 32.95 ns 0.162 ns 0.144 ns ******** -
ConvertUnit kg.m².s⁻³ kg.m².s⁻³ 36.40 ns 0.314 ns 0.294 ns *********** -
Method func str Mean Error StdDev Rank Gen 0 Allocated
ParseUnit Syste(...)Unit] [79] Gy.s⁻¹ 13.51 ns 0.140 ns 0.131 ns ****** 0.0020 32 B
ParseUnit Syste(...)Unit] [79] Gy.wk⁻¹ 14.02 ns 0.117 ns 0.103 ns ******* 0.0020 32 B
ParseUnit Syste(...)Unit] [79] J.cs⁻¹ 13.45 ns 0.117 ns 0.104 ns ****** 0.0020 32 B
ParseUnit Syste(...)Unit] [79] dat.Gpc².ns⁻¹ 13.58 ns 0.176 ns 0.165 ns ****** 0.0020 32 B
ParseUnit Syste(...)Unit] [79] kg.m².s⁻³ 13.11 ns 0.123 ns 0.115 ns ***** 0.0020 32 B
ParseUnit Syste(...)Unit] [79] r.m⁻¹ 12.74 ns 0.099 ns 0.083 ns ***** 0.0020 32 B
ParseUnit Syste(...)Unit] [79] s⁻¹ 13.20 ns 0.186 ns 0.174 ns ***** 0.0020 32 B
ParseUnit Syste(...)Unit] [79] °.s⁻¹ 12.86 ns 0.191 ns 0.179 ns ***** 0.0020 32 B
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.0-preview-002 122 5/22/2025