TedToolkit.Quantities 2026.4.8

dotnet add package TedToolkit.Quantities --version 2026.4.8
                    
NuGet\Install-Package TedToolkit.Quantities -Version 2026.4.8
                    
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="TedToolkit.Quantities" Version="2026.4.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TedToolkit.Quantities" Version="2026.4.8" />
                    
Directory.Packages.props
<PackageReference Include="TedToolkit.Quantities" />
                    
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 TedToolkit.Quantities --version 2026.4.8
                    
#r "nuget: TedToolkit.Quantities, 2026.4.8"
                    
#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 TedToolkit.Quantities@2026.4.8
                    
#: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=TedToolkit.Quantities&version=2026.4.8
                    
Install as a Cake Addin
#tool nuget:?package=TedToolkit.Quantities&version=2026.4.8
                    
Install as a Cake Tool

TedToolkit.Quantities

A type-safe, source-generated quantities and units library for .NET. Define a partial struct, and the Roslyn analyzer generates unit conversions, arithmetic operators, formatting, and more — all backed by the QUDT ontology.

Features

  • Source-generated — zero reflection, zero runtime overhead; everything is produced at compile time
  • Type-safe operatorsAngle / Angle yields DimensionlessRatio, Angle * Length yields Length, etc.
  • Broad framework support — .NET 6–10, .NET Framework 4.7.2+, .NET Standard 2.0/2.1
  • QUDT-backed — units and conversion factors come from the W3C QUDT ontology
  • Multiple quantity systems — SI, CGS, Imperial, US Customary, ISQ, Planck, and more
  • Tolerance-aware comparisons — configurable precision for equality and ordering via scoped Tolerance

Quick Start

Install the package:

dotnet add package TedToolkit.Quantities

Define a Quantity

Declare a partial struct in the TedToolkit.Quantities namespace. The source generator fills in the rest:

using TedToolkit.Quantities;

[QuantityDisplayUnit<AngleUnit>(AngleUnit.Degree)]
[QuantityOperator<Angle, Angle, DimensionlessRatio>(Operator.DIVIDE)]
[QuantityOperator<Angle, Angle, Angle>(Operator.SUBTRACT)]
[QuantityOperator<Angle, Length, Length>(Operator.MULTIPLY)]
public partial struct Angle;

Create and Convert

// From a constructor
var angle = new Angle(180.0, AngleUnit.Degree);

// From a static factory
var angle2 = Angle.FromRadian(Math.PI);

// From an extension property on double
var angle3 = 90.0.Degree;

// Convert between units
double rad = angle.As(AngleUnit.Radian);   // π
double deg = angle.Degree;                  // 180.0

Arithmetic

var a = 90.0.Degree;
var b = 45.0.Degree;

Angle sum  = a + b;            // 135°
Angle diff = a - b;            // 45°
Angle half = a / 2.0;          // 45°

// Cross-quantity operators (defined via attributes)
DimensionlessRatio ratio = a / b;   // 2.0

Formatting

var angle = 45.0.Degree;

angle.ToString();                                    // "45 °"
angle.ToString(AngleUnit.Radian, "F4");              // "0.7854 rad"

Tolerance

Quantity comparisons use a scoped Tolerance so floating-point results can be compared meaningfully:

using TedToolkit.Scopes;

using (new Tolerance { Angle = 1e-9 }.FastPush())
{
    var a = Angle.FromDegree(360.0);
    var b = Angle.FromRadian(2 * Math.PI);
    Console.WriteLine(a == b);  // True
}

Attributes Reference

Attribute Purpose
QuantityDisplayUnit<TUnit>(unit) Sets the default display unit for ToString()
QuantityOperator<TLeft, TRight, TResult>(op) Generates a binary operator (+, -, *, /)
QuantityImplicitToValueType Adds implicit conversion from quantity to its value type
QuantityImplicitFromValueType Adds implicit conversion from value type to quantity

Quantity Systems

The library ships with unit data for multiple systems via QuantitySystems:

Constant System
QuantitySystems.SI International System of Units
QuantitySystems.CGS Centimetre-Gram-Second
QuantitySystems.IMPERIAL Imperial
QuantitySystems.USCS US Customary
QuantitySystems.ISQ ISO System of Quantities
QuantitySystems.Planck Planck units
QuantitySystems.ALL All available units

License

LGPL-3.0 — see COPYING and COPYING.LESSER.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 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 is compatible.  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 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  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.

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
2026.4.8 40 4/8/2026
2026.2.6.2 108 2/6/2026
2026.2.6.1 93 2/6/2026
2026.2.6 95 2/6/2026
2025.12.23.1 212 12/23/2025
2025.12.23 189 12/23/2025
2025.12.17 301 12/17/2025
2025.12.12.2 143 12/12/2025
2025.12.12.1 131 12/12/2025
2025.12.12 146 12/12/2025
2025.12.9 463 12/9/2025
2025.11.25 215 11/25/2025
2025.11.24.3 200 11/24/2025
2025.11.24.2 201 11/24/2025
2025.11.24.1 200 11/24/2025
2025.11.24 204 11/24/2025
2025.11.21 409 11/21/2025
2025.11.20.4 416 11/20/2025
2025.11.20.3 417 11/20/2025
2025.11.20.2 420 11/20/2025
Loading failed