Interval Class
Definition
Provides type-inferring factory methods for Interval<T>.
public static class Interval
- Inheritance
-
Interval
- Inherited Members
Examples
using Bodu.Numerics;
// Type inferred from the int literals.
var ints = Interval.ClosedOpen(0, 100); // Interval<int>
// Type inferred from the decimal-suffixed literals.
var prices = Interval.OpenClosed(1000m, 10_000m); // Interval<decimal>
// Type inferred from the local variable.
double low = 1.5, high = 2.5;
var span = Interval.Closed(low, high); // Interval<double>
Remarks
The methods on this class mirror the static factories declared on Interval<T> but accept the endpoint
values directly, letting the compiler infer the endpoint type from the arguments. This avoids the need to repeat the
generic parameter at the call site: Interval.Closed(1, 5) compiles to a Interval<T> over
int without an explicit type argument, and Interval.ClosedOpen(0m, 100m) picks
decimal from the literal suffixes.
Prefer the non-generic helpers when the endpoint type is obvious from the arguments - typical for literals, local variables, and expressions that already carry the type - and use Interval<T>'s own static factories (e.g. Closed(T, T)) when the call site needs an explicit type to disambiguate, when the endpoint type comes from a generic context, or when the factory is being held as a method group.
Methods
AtLeast<T>(T)
Creates the lower-bounded interval [lower, +∞) with T inferred from the
argument.
public static Interval<T> AtLeast<T>(T lower) where T : INumber<T>
Parameters
lowerTThe inclusive lower endpoint.
Returns
- Interval<T>
A closed-below, upper-unbounded interval.
Type Parameters
TThe endpoint type, inferred at the call site.
AtMost<T>(T)
Creates the upper-bounded interval (-∞, upper] with T inferred from the
argument.
public static Interval<T> AtMost<T>(T upper) where T : INumber<T>
Parameters
upperTThe inclusive upper endpoint.
Returns
- Interval<T>
A lower-unbounded, closed-above interval.
Type Parameters
TThe endpoint type, inferred at the call site.
ClosedOpen<T>(T, T)
Creates a closed-open interval [lower, upper) with T inferred from the arguments.
public static Interval<T> ClosedOpen<T>(T lower, T upper) where T : INumber<T>
Parameters
lowerTThe lower endpoint (included).
upperTThe upper endpoint (excluded).
Returns
- Interval<T>
A closed-open interval over the supplied bounds.
Type Parameters
TThe endpoint type, inferred at the call site.
Closed<T>(T, T)
Creates a closed-closed interval [lower, upper] with T inferred from the
arguments.
public static Interval<T> Closed<T>(T lower, T upper) where T : INumber<T>
Parameters
lowerTThe lower endpoint.
upperTThe upper endpoint.
Returns
- Interval<T>
A closed-closed interval over the supplied bounds.
Type Parameters
TThe endpoint type, inferred at the call site.
GreaterThan<T>(T)
Creates the lower-bounded interval (lower, +∞) with T inferred from the
argument.
public static Interval<T> GreaterThan<T>(T lower) where T : INumber<T>
Parameters
lowerTThe exclusive lower endpoint.
Returns
- Interval<T>
An open-below, upper-unbounded interval.
Type Parameters
TThe endpoint type, inferred at the call site.
LessThan<T>(T)
Creates the upper-bounded interval (-∞, upper) with T inferred from the
argument.
public static Interval<T> LessThan<T>(T upper) where T : INumber<T>
Parameters
upperTThe exclusive upper endpoint.
Returns
- Interval<T>
A lower-unbounded, open-above interval.
Type Parameters
TThe endpoint type, inferred at the call site.
OpenClosed<T>(T, T)
Creates an open-closed interval (lower, upper] with T inferred from the
arguments.
public static Interval<T> OpenClosed<T>(T lower, T upper) where T : INumber<T>
Parameters
lowerTThe lower endpoint (excluded).
upperTThe upper endpoint (included).
Returns
- Interval<T>
An open-closed interval over the supplied bounds.
Type Parameters
TThe endpoint type, inferred at the call site.
Open<T>(T, T)
Creates an open-open interval (lower, upper) with T inferred from the arguments.
public static Interval<T> Open<T>(T lower, T upper) where T : INumber<T>
Parameters
lowerTThe lower endpoint.
upperTThe upper endpoint.
Returns
- Interval<T>
An open-open interval over the supplied bounds.
Type Parameters
TThe endpoint type, inferred at the call site.
Singleton<T>(T)
Creates a degenerate single-point interval [value, value] with T inferred from
the argument.
public static Interval<T> Singleton<T>(T value) where T : INumber<T>
Parameters
valueTThe single value the interval contains.
Returns
- Interval<T>
A degenerate interval over the single value.
Type Parameters
TThe endpoint type, inferred at the call site.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |