Tare 0.8.0-vNext.1

This is a prerelease version of Tare.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Tare --version 0.8.0-vNext.1
                    
NuGet\Install-Package Tare -Version 0.8.0-vNext.1
                    
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="Tare" Version="0.8.0-vNext.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tare" Version="0.8.0-vNext.1" />
                    
Directory.Packages.props
<PackageReference Include="Tare" />
                    
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 Tare --version 0.8.0-vNext.1
                    
#r "nuget: Tare, 0.8.0-vNext.1"
                    
#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 Tare@0.8.0-vNext.1
                    
#: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=Tare&version=0.8.0-vNext.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tare&version=0.8.0-vNext.1&prerelease
                    
Install as a Cake Tool

api documentation | contributions | changelog

Tare

A simple, dynamic library for a unit of measure value type with powerful dimensional arithmetic.

What is Tare?

Tare is a .NET library that provides a Quantity type for working with physical quantities and units of measurement. It supports:

  • Unit conversion - Convert between compatible units (inches to meters, pounds to kilograms, etc.)
  • Arithmetic operations - Add, subtract, multiply, and divide quantities with automatic unit handling
  • Composite units - Work with complex units like "m/s", "kg*m/s^2", "Nm", etc.
  • Dimensional analysis - Automatic dimension checking and unit composition
  • Type safety - Prevents invalid operations like adding length to mass

Quick Start

Basic Usage

using Tare;

// Create quantities from strings
var length1 = Quantity.Parse("1.5 m");
var length2 = Quantity.Parse("13 in");

// Add compatible units (automatic conversion)
var totalLength = length1 + length2;
Console.WriteLine(totalLength.Format("m")); // "1.8302 m"

// Compare quantities
if (length1 > length2)
    Console.WriteLine("Length 1 is greater than length 2");

// Multiply by scalars
Quantity scalar = 3;
var lengthMultiple = length1 * scalar;
Console.WriteLine(lengthMultiple.Format("ft")); // "14.7638 ft"

Dimensional Arithmetic

Tare automatically handles dimensional algebra when multiplying or dividing quantities:

// Area calculation
var width = Quantity.Parse("2.5 m");
var height = Quantity.Parse("3.0 m");
var area = width * height;  // Result: 7.5 m²
Console.WriteLine(area.Format("m^2")); // "7.5 m^2"

// Velocity from distance and time
var distance = Quantity.Parse("100 m");
var time = Quantity.Parse("9.58 s");
var velocity = distance / time;  // Result: 10.44 m/s
Console.WriteLine(velocity.Format("m/s")); // "10.44 m/s"

// Force calculation (F = ma)
var mass = Quantity.Parse("5 kg");
var acceleration = Quantity.Parse("2 m/s^2");
var force = mass * acceleration;  // Result: 10 N (Newtons)
Console.WriteLine(force.Format("N")); // "10 N"

Composite Units

Work seamlessly with composite units in your calculations:

// Create quantities with composite units
var torque = Quantity.Parse("200 Nm");  // Newton-meters
var power = Quantity.Parse("500 W");    // Watts (J/s)
var velocity = Quantity.Parse("60 km/h");

// Dimensional algebra with composites
var force = Quantity.Parse("50 N");
var distance = torque / force;  // 200 Nm ÷ 50 N = 4 m
Console.WriteLine(distance.Format("m")); // "4 m"

// Custom composite units
var customUnit = Quantity.Parse("10 lbf*in");  // pound-force inches
Console.WriteLine(customUnit.Format("Nm")); // Converts to Newton-meters

Unit Conversion

Convert between any compatible units:

var temperature = Quantity.Parse("72 °F");
Console.WriteLine(temperature.Format("°C")); // "22.2222 °C"

var pressure = Quantity.Parse("14.7 psi");
Console.WriteLine(pressure.Format("Pa")); // "101352.9 Pa"

var speed = Quantity.Parse("60 mph");
Console.WriteLine(speed.Format("m/s")); // "26.8224 m/s"

Supported Units

Tare supports a wide variety of units across many dimensions:

  • Length: m, cm, mm, km, in, ft, yd, mi, nmi
  • Mass: g, kg, lb, oz, ton
  • Time: ms, s, min, h, day, week, year
  • Temperature: °C, °F, K
  • Force: N, lbf, kgf
  • Pressure: Pa, psi, bar, atm, mmHg
  • Energy: J, Nm, kWh, BTU, cal
  • Power: W, hp, kW
  • Velocity: m/s, km/h, mph, knots
  • Area: m², cm², ft², acre
  • Volume: m³, L, mL, gal, qt, pt, cup
  • And many more...

Advanced Features

Type-Safe Operations

Tare prevents invalid operations at runtime:

var length = Quantity.Parse("5 m");
var mass = Quantity.Parse("10 kg");

// This throws InvalidOperationException - can't add different dimensions!
// var invalid = length + mass;  // Error!

Implicit Conversions

Work naturally with numeric types:

Quantity scalar = 5;  // Implicitly creates a dimensionless quantity
var result = length * 2;  // Works with integers
var result2 = length * 2.5;  // Works with doubles
var result3 = length * 2.5m;  // Works with decimals

Format Control

Control how quantities are displayed:

var distance = Quantity.Parse("1234.5 m");
Console.WriteLine(distance.Format("km")); // "1.2345 km"
Console.WriteLine(distance.Format("mi")); // "0.7672 mi"
Console.WriteLine(distance.Format("ft")); // "4050.5249 ft"

Installation

Available on NuGet: (package link to be added)

dotnet add package Tare

Documentation

For more detailed documentation, see:

References and Further Reading

For those interested in learning more about dimensional analysis and units of measure:

Product 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 is compatible.  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.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework 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 tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tare:

Package Downloads
JordanRobot.MotorDefinition

Definitions for electrical motor properties and performance data. Allows mapping of performance (torque/speed curves) per drive and voltage. Includes JSON load/save functionality and object models.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0-alpha.4 537 11/17/2025
1.1.0-alpha.0 323 11/17/2025
1.0.0 389 11/16/2025
1.0.0-alpha.215 218 11/16/2025
0.8.0-vNext.1 193 11/9/2025
0.7.0-alpha0001 371 4/17/2023
0.6.0-alpha0001 252 4/16/2023
0.5.2-alpha0001 280 4/13/2023
0.5.1-alpha0001 262 4/13/2023
0.5.0-alpha0001 276 3/29/2023
0.4.0-alpha0001 276 3/22/2023
0.3.1-alpha0001 277 3/22/2023
0.2.0-alpha0001 260 3/21/2023

Initial release. See repository page for more details.