![]() |
VOOZH | about |
dotnet add package Gapotchenko.FX.Math.Intervals --version 2026.7.2
NuGet\Install-Package Gapotchenko.FX.Math.Intervals -Version 2026.7.2
<PackageReference Include="Gapotchenko.FX.Math.Intervals" Version="2026.7.2" />
<PackageVersion Include="Gapotchenko.FX.Math.Intervals" Version="2026.7.2" />Directory.Packages.props
<PackageReference Include="Gapotchenko.FX.Math.Intervals" />Project file
paket add Gapotchenko.FX.Math.Intervals --version 2026.7.2
#r "nuget: Gapotchenko.FX.Math.Intervals, 2026.7.2"
#:package Gapotchenko.FX.Math.Intervals@2026.7.2
#addin nuget:?package=Gapotchenko.FX.Math.Intervals&version=2026.7.2Install as a Cake Addin
#tool nuget:?package=Gapotchenko.FX.Math.Intervals&version=2026.7.2Install as a Cake Tool
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> 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.
The real power of intervals comes when you need to perform certain operations on them.
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.
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].
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,∞).
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>());
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> 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.
Intervals can be parsed from string representations using the standard interval notation. The parser supports both Unicode and ASCII representations of intervals.
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]");
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 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}");
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");
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<T> also supports parsing with the same syntax:
var valueInterval = ValueInterval.Parse<int>("[10,20]");
Gapotchenko.FX.Math.Intervals.Interval<T>Gapotchenko.FX.Math.Intervals.ValueInterval<T>Let's continue with a look at some other modules provided by Gapotchenko.FX:
Or look at the full list of modules.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
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. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.7.2 | 192 | 5/16/2026 |
| 2026.6.2 | 208 | 3/29/2026 |
| 2026.5.3 | 195 | 2/24/2026 |
| 2026.4.2 | 204 | 2/4/2026 |
| 2026.3.5 | 207 | 1/29/2026 |
| 2026.2.2 | 210 | 1/25/2026 |
| 2026.1.5 | 206 | 1/13/2026 |
| 2025.1.45 | 305 | 12/25/2025 |
| 2025.1.27-beta | 288 | 10/8/2025 |
| 2025.1.26-beta | 337 | 8/30/2025 |
| 2025.1.25-beta | 979 | 7/22/2025 |
| 2025.1.24-beta | 460 | 7/16/2025 |
| 2025.1.23-beta | 584 | 7/12/2025 |
| 2024.2.5 | 447 | 12/31/2024 |
| 2024.1.3 | 340 | 11/10/2024 |