Table of Contents

Interval Class

Definition

Namespace
Bodu.Numerics
Assembly
Bodu.Numerics.dll
Package
Bodu.Numerics 1.0.0
Source
Interval{T}.Helpers.cs

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

lower T

The inclusive lower endpoint.

Returns

Interval<T>

A closed-below, upper-unbounded interval.

Type Parameters

T

The 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

upper T

The inclusive upper endpoint.

Returns

Interval<T>

A lower-unbounded, closed-above interval.

Type Parameters

T

The 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

lower T

The lower endpoint (included).

upper T

The upper endpoint (excluded).

Returns

Interval<T>

A closed-open interval over the supplied bounds.

Type Parameters

T

The 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

lower T

The lower endpoint.

upper T

The upper endpoint.

Returns

Interval<T>

A closed-closed interval over the supplied bounds.

Type Parameters

T

The 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

lower T

The exclusive lower endpoint.

Returns

Interval<T>

An open-below, upper-unbounded interval.

Type Parameters

T

The 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

upper T

The exclusive upper endpoint.

Returns

Interval<T>

A lower-unbounded, open-above interval.

Type Parameters

T

The 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

lower T

The lower endpoint (excluded).

upper T

The upper endpoint (included).

Returns

Interval<T>

An open-closed interval over the supplied bounds.

Type Parameters

T

The 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

lower T

The lower endpoint.

upper T

The upper endpoint.

Returns

Interval<T>

An open-open interval over the supplied bounds.

Type Parameters

T

The 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

value T

The single value the interval contains.

Returns

Interval<T>

A degenerate interval over the single value.

Type Parameters

T

The endpoint type, inferred at the call site.

Applies to

ProductVersions
.NET8, 10