TedToolkit.Mathematics.Interval 2026.6.23.1

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

TedToolkit.Mathematics.Interval

TedToolkit.Mathematics.Interval provides explicit interval types and normalized interval sets for .NET.

Use it when your code needs correct boundary behavior instead of manually coordinating min, max, and inclusive/exclusive flags.

Installation

dotnet add package TedToolkit.Mathematics.Interval

Core Types

IntervalEnd<TData>

Represents one endpoint value together with its boundary type:

  • BoundaryType.CLOSED
  • BoundaryType.OPEN

Interval<TData>

Represents a single interval.

  • endpoints are exposed as Min and Max
  • Create(start, end, out isReversed) orders the endpoints for you
  • IsEmpty reports whether the interval contains no values
  • IsInside, Clamp, GetRelationTo, IsAdjacentTo, and ToIntervalSet expose the main operations

TData must implement IComparable<TData>.

IntervalSet<TData>

Represents a normalized set of intervals.

When you construct it from multiple intervals:

  • empty intervals are removed
  • intervals are sorted
  • overlapping or adjacent intervals are merged

It also provides Union, Intersect, and Difference.

RelationType

Represents the relationship between two operands:

  • Disjoint
  • Overlapping
  • ProperSuperset
  • ProperSubset
  • Equal

Basic Usage

using TedToolkit.Mathematics.Interval;

var closed = Interval<int>.Create(1, 5, out _);
var openLeft = Interval<int>.Create(
    new IntervalEnd<int>(1, BoundaryType.OPEN),
    new IntervalEnd<int>(5),
    out _);

Console.WriteLine(closed.IsInside(1));             // True
Console.WriteLine(openLeft.IsInside(1));           // False
Console.WriteLine(closed.GetRelationTo(openLeft)); // ProperSuperset

String formatting follows mathematical interval notation:

Console.WriteLine(closed);   // [1, 5]
Console.WriteLine(openLeft); // (1, 5]

Special cases:

  • a singleton interval prints as the value itself, for example 1
  • an empty interval prints as Ø

Interval Sets

IntervalSet<TData> normalizes overlapping or adjacent intervals automatically:

var set = new IntervalSet<int>(
    Interval<int>.Create(1, 2, out _),
    Interval<int>.Create(2, 4, out _),
    Interval<int>.Create(6, 8, out _));

Console.WriteLine(set); // [1, 4] ∪ [6, 8]

Set operations are available directly:

var left = new IntervalSet<int>(Interval<int>.Create(1, 4, out _), Interval<int>.Create(6, 8, out _));
var right = new IntervalSet<int>(Interval<int>.Create(3, 7, out _));

Console.WriteLine(left.Intersect(right)); // [3, 4] ∪ [6, 7]
Console.WriteLine(left.Union(right));     // [1, 8]

Difference preserves boundary correctness:

var current = new IntervalSet<int>(Interval<int>.Create(1, 6, out _));
var removed = new IntervalSet<int>(Interval<int>.Create(3, 4, out _));

Console.WriteLine(current.Difference(removed)); // [1, 3) ∪ (4, 6]

Notes

  • Empty intervals are represented explicitly and participate in comparisons.
  • Clamp throws InvalidOperationException for an empty interval.
  • Adjacency is value-based and takes boundary openness into account.

Target Frameworks

  • net6.0
  • net7.0
  • net8.0
  • net9.0
  • net10.0
  • net472
  • net48
  • netstandard2.0
  • netstandard2.1
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.6.23.1 126 6/23/2026
2026.6.23 119 6/23/2026