utte.numberset 2.0.0

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

NumberSet

Generic sets for numbers or numberlike objects and Union, Intersection and Difference for them. The sets track if they contain their endpoints and thus wether they are Open, Closed or neither.

Content

Three interfaces are included:

  • IBoundedSet<T> - Interface for building sets of numberlike objects of type T. The sets are immutable and every operation on them creates new sets, T has to implement IAdditionOperators<T, T, T>, ISubtractionOperators<T, T, T>, IComparisonOperators<T, T, bool> The structure of the sets are INumberSet<T> which contains a collection of INumberSetElement<T> A single T instance is considered a point

  • INumberSetElement<T> - Interface implementing IBoundedSet<T> for constructing elements of a set which is a set in itself. The interface is used as part of INumberSet. T has to implement IAdditionOperators<T, T, T>, ISubtractionOperators<T, T, T>, IComparisonOperators<T, T, bool>

  • INumberSet<T> - Interface implementing IBoundedSet<T> for constructing sets of numberlike objects of type T. It is built of a collection of INumberSetElement and is immutable. Every INumberSetElement in the collection should be disjunct and sorted in order. T has to implement IAdditionOperators<T, T, T>, ISubtractionOperators<T, T, T>, IComparisonOperators<T, T, bool>

Two classes are included:

  • NumberSetElement<T> - Implementation of INumberSetElement<T>

  • NumberSet<T> - Implementation of INumberSet<T>

Usage

Sets can be created by casts, parse string or the Create method. At creation it should be specified wether each NumberSetElement should contain its boundaries. A ( or ) means the boundary is not included while a [ or ] means it is for casts/parsing. In the Create method it is set using a boolean.

NumberSet<double> set1 = "(0.3, 2.1]";
NumberSet<double> set2 = "(1.8, 3.6]";

Console.WriteLine("Set1: " + set1.ToString());

Console.WriteLine("Set2: " + set2.ToString());

var unionSet = set1.Union(set2);

Console.WriteLine("Union: " + unionSet.ToString());

var intersectionSet = set1.Intersection(set2);

Console.WriteLine("Intersection: " + intersectionSet.ToString());

var differenceSet = set1.Difference(set2);

Console.WriteLine("Difference: " + differenceSet.ToString());

This code will print the following to the console:

Set1: (0.3, 2.1]
Set2: (1.8, 3.6]
Union: (0.3, 3.6]
Intersection: (1.8, 2.1]
Difference: (0.3, 1.8]

A NumberSet can contain several NumberSetElement by simply writing them in the string like "(0.3, 2.1]; (1.8, 3.6]". Each will be unioned and ordered as appropriate.

Additional documentation

The code can be found here: NumberSet repository.

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
2.0.1 118 6/27/2025
2.0.0 148 6/19/2025
1.0.2 145 6/16/2025
1.0.1 279 6/10/2025
1.0.0 292 3/6/2023

Update to .net 8.0.