Gapotchenko.FX.Math.Intervals
2026.3.5
Prefix Reserved
dotnet add package Gapotchenko.FX.Math.Intervals --version 2026.3.5
NuGet\Install-Package Gapotchenko.FX.Math.Intervals -Version 2026.3.5
<PackageReference Include="Gapotchenko.FX.Math.Intervals" Version="2026.3.5" />
<PackageVersion Include="Gapotchenko.FX.Math.Intervals" Version="2026.3.5" />
<PackageReference Include="Gapotchenko.FX.Math.Intervals" />
paket add Gapotchenko.FX.Math.Intervals --version 2026.3.5
#r "nuget: Gapotchenko.FX.Math.Intervals, 2026.3.5"
#:package Gapotchenko.FX.Math.Intervals@2026.3.5
#addin nuget:?package=Gapotchenko.FX.Math.Intervals&version=2026.3.5
#tool nuget:?package=Gapotchenko.FX.Math.Intervals&version=2026.3.5
Overview
The module provides data structures and primitives for working with intervals. Interval is a mathematical structure that defines a range of values in a unified and formalized way.
Interval<T>
Interval<T> type represents a continuous range of values.
For example, a human age interval for teenagers can be defined as:
using Gapotchenko.FX.Math.Intervals;
// Define an inclusive interval of years ranging from 13 to 19.
// Inclusive interval has both its ends included in the interval.
// The formal interval representation is [13,19],
// where '[' denotes the start of the interval (inclusive),
// and ']' denotes the end of the interval (inclusive).
var teenagers = Interval.Inclusive(13, 19);
Given that range, it is now possible to do various operations:
Console.Write("Enter your age: ");
var age = int.Parse(Console.ReadLine());
// Everyone of an age between 13 and 19 years (inclusive) is a teenager.
// Using the interval notation, this can be stated as: age ∈ [13,19],
// where '∈' symbol denotes the "is an element of" operation.
if (teenagers.Contains(age))
Console.WriteLine("Congrats, you are a teenager.");
else
Console.WriteLine("Congrats, you are not a teenager.");
In this simple example, the value is just a number but it can be any comparable type.
For example, it can be a System.Version, a System.DateTime, etc.
Interval Operations
The real power of intervals comes when you need to perform certain operations on them.
Overlap Detection
Interval<T>.Overlaps function returns a Boolean value indicating whether a specified interval overlaps with another:
var teenagers = Interval.Inclusive(13, 19);
// Adults are people of 18 years or older
// (the exact age of adulthood depends on a jurisdiction but we use 18 for simplicity).
// Using the interval notation, this is [18,∞),
// where ')' denotes the end of the interval (non-inclusive),
var adults = Interval.FromInclusive(18);
Console.Write(
"Can teenagers be adults? The answer is {0}."
teenagers.Overlaps(adults) ? "yes" : "no");
The snippet produces the following output:
Can teenagers be adults? The answer is yes.
Intersection
The intersection of two intervals returns an interval which has a range shared by both of them:
var teenagers = Interval.Inclusive(13, 19);
var adults = Interval.FromInclusive(18);
Console.WriteLine(
"Adult teenagers have an age of {0}",
teenagers.Intersect(adults));
The snippet produces the following output:
Adult teenagers have an age of [18,19].
Union
The union of two continuous intervals has the range that covers both of them:
var teenagers = Interval.Inclusive(13, 19);
var adults = Interval.FromInclusive(18);
Console.WriteLine(
"Adults and teenagers have an age of {0}",
teenagers.Union(adults));
The snippet produces the following output:
Adults and teenagers have an age of [13,inf).
Note the [13,inf) interval string in the output above.
This is the ASCII variant of a formal [13,∞) notation.
The ASCII notation is produced by Interval<T>.ToString() method by default.
If you want the formal Unicode notation, you can pass U format specifier as in Interval<T>.ToString("U") method call:
Console.WriteLine(
"Adults and teenagers have an age of {0:U}",
teenagers.Union(adults));
which produces the output using Unicode mathematical symbols:
Adults and teenagers have an age of [13,∞).
Interval Construction
To define an interval, you can use a set of predefined methods provided by the static Interval type:
// [10,20]
interval = Interval.Inclusive(10, 20);
// (10,20)
interval = Interval.Exclusive(10, 20);
// [10,20)
interval = Interval.InclusiveExclusive(10, 20);
// (10,20]
interval = Interval.ExclusiveInclusive(10, 20);
// [10,∞)
interval = Interval.FromInclusive(10);
// (10,∞)
interval = Interval.FromExclusive(10);
// (-∞,10]
interval = Interval.ToInclusive(10);
// (-∞,10)
interval = Interval.ToExclusive(10);
Or you can explicitly construct an interval by using an Interval<T> constructor using the notion of boundaries:
// [10,20)
interval = new Interval<int>(IntervalBoundary.Inclusive(10), IntervalBoundary.Exclusive(20));
// (10,∞)
interval = new Interval<int>(IntervalBoundary.Exclusive(10), IntervalBoundary.PositiveInfinity<int>());
Special Intervals
There are a few special intervals readily available for use:
// An empty interval ∅
interval = Interval.Empty<T>();
// An infinite interval (-∞,∞)
interval = Interval.Infinite<T>();
// A degenerate interval [x;x]
interval = Interval.Degenerate(x);
ValueInterval<T>
ValueInterval<T> type provides a similar functionality to Interval<T> but it is a structure in terms of .NET type system, while Interval<T> is a class.
The difference is that ValueInterval<T> can be allocated on stack without involving expensive GC memory operations, also it has tinier memory footprint.
All in all, ValueInterval<T> is the preferred interval type to use.
Being totally transparent and interchangeable with Interval<T>, it comes with certain restrictions.
For example, ValueInterval<T> cannot use a custom System.IComparer<T>, and thus it requires T type to always implement System.IComparable<T> interface.
This is not an obstacle for most specializing types, but this is a formal restriction that may affect your choice in favor of Interval<T>.
Another scenario where you may prefer Interval<T> type better is when you need to pass it as a reference to many places in code.
This may save some CPU time and memory in cases where T type is sufficiently large because passing the interval by reference avoids copying.
Interval Parsing
Intervals can be parsed from string representations using the standard interval notation. The parser supports both Unicode and ASCII representations of intervals.
Basic Parsing
Use Interval.Parse<T> to parse an interval from a string:
// Parse an inclusive interval [10,20]
var interval = Interval.Parse<int>("[10,20]");
// Parse an exclusive interval (5,15)
interval = Interval.Parse<int>("(5,15)");
// Parse a mixed interval [10,20)
interval = Interval.Parse<int>("[10,20)");
The parser supports both comma (,) and semicolon (;) as separators:
// Both forms are equivalent
interval = Interval.Parse<int>("[10,20]");
interval = Interval.Parse<int>("[10;20]");
Infinity
Infinite boundaries are supported using Unicode or ASCII notation:
// [10,∞) - Unicode infinity symbol
interval = Interval.Parse<int>("[10,∞)");
// [10,inf) - ASCII infinity notation
interval = Interval.Parse<int>("[10,inf)");
// (-∞,10] - Negative infinity
interval = Interval.Parse<int>("(-∞,10]");
interval = Interval.Parse<int>("(-inf,10]");
Empty and Degenerate Intervals
Empty intervals can be parsed using the empty set notation:
// Empty interval ∅
interval = Interval.Parse<int>("∅");
interval = Interval.Parse<int>("{}");
Degenerate intervals (single point) can be also parsed using set notation:
// Degenerate interval {5} which represents [5,5]
interval = Interval.Parse<int>("{5}");
TryParse
For scenarios where parsing might fail, use TryParse to avoid exceptions:
if (Interval.TryParse<int>("[10,20]", out var interval))
Console.WriteLine($"Parsed interval: {interval}");
else
Console.WriteLine("Failed to parse interval");
Culture-Specific Parsing
The parser respects culture-specific formatting when converting boundary values:
using System.Globalization;
// Parse with a specific culture
var culture = new CultureInfo("de-DE");
var interval = Interval.Parse<float>("[10,5;20,3]", culture);
ValueInterval Parsing
ValueInterval<T> also supports parsing with the same syntax:
var valueInterval = ValueInterval.Parse<int>("[10,20]");
Commonly Used Types
Gapotchenko.FX.Math.Intervals.Interval<T>Gapotchenko.FX.Math.Intervals.ValueInterval<T>
Other Modules
Let's continue with a look at some other modules provided by Gapotchenko.FX:
- Gapotchenko.FX
- Gapotchenko.FX.AppModel.Information
- Gapotchenko.FX.Collections
- Gapotchenko.FX.Console
- Gapotchenko.FX.Data
- Gapotchenko.FX.Diagnostics
- Gapotchenko.FX.IO
- Gapotchenko.FX.Linq
- Gapotchenko.FX.Math
- Gapotchenko.FX.Memory
- Gapotchenko.FX.Security.Cryptography
- Gapotchenko.FX.Text
- Gapotchenko.FX.Threading
- Gapotchenko.FX.Tuples
- Gapotchenko.FX.Versioning
Or look at the full list of modules.
| Product | Versions 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 was computed. 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 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. |
-
.NETFramework 4.7.2
- Gapotchenko.FX (>= 2026.3.5)
- Gapotchenko.FX.Math (>= 2026.3.5)
-
.NETStandard 2.0
- Gapotchenko.FX (>= 2026.3.5)
- Gapotchenko.FX.Math (>= 2026.3.5)
-
.NETStandard 2.1
- Gapotchenko.FX (>= 2026.3.5)
- Gapotchenko.FX.Math (>= 2026.3.5)
-
net10.0
- Gapotchenko.FX (>= 2026.3.5)
- Gapotchenko.FX.Math (>= 2026.3.5)
-
net8.0
- Gapotchenko.FX (>= 2026.3.5)
- Gapotchenko.FX.Math (>= 2026.3.5)
-
net9.0
- Gapotchenko.FX (>= 2026.3.5)
- Gapotchenko.FX.Math (>= 2026.3.5)
NuGet packages (8)
Showing the top 5 NuGet packages that depend on Gapotchenko.FX.Math.Intervals:
| Package | Downloads |
|---|---|
|
Gapotchenko.FX.Profiles.Math
Represents the Math profile of Gapotchenko.FX toolkit. |
|
|
Gapotchenko.FX.Math.Metrics
Provides math metrics algorithms. |
|
|
Gapotchenko.Shields.MSys2.Deployment
The deployment module of MSYS2 Shield. |
|
|
Gapotchenko.Shields.Cygwin.Deployment
The deployment module of Cygwin Shield. |
|
|
Gapotchenko.Shields.Homebrew.Deployment
Locates setup instances of Homebrew package manager. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.3.5 | 93 | 1/29/2026 |
| 2026.2.2 | 174 | 1/25/2026 |
| 2026.1.5 | 172 | 1/13/2026 |
| 2025.1.45 | 262 | 12/25/2025 |
| 2025.1.27-beta | 255 | 10/8/2025 |
| 2025.1.26-beta | 302 | 8/30/2025 |
| 2025.1.25-beta | 838 | 7/22/2025 |
| 2025.1.24-beta | 433 | 7/16/2025 |
| 2025.1.23-beta | 555 | 7/12/2025 |
| 2024.2.5 | 339 | 12/31/2024 |
| 2024.1.3 | 307 | 11/10/2024 |