Table of Contents

Class NullableIntEx

Namespace
Utils.Mathematics
Assembly
Utils.dll

Provides helper methods for working with nullable numeric endpoints that can represent open ranges by treating null as positive or negative infinity as needed.

public static class NullableIntEx
Inheritance
NullableIntEx
Inherited Members

Methods

CompareEndpoint<T>(T?, T?)

Compares two endpoint values where null represents +∞. Returns a negative value if left < right, zero if equal, and a positive value if left > right.

public static int CompareEndpoint<T>(T? left, T? right) where T : struct, IBinaryInteger<T>, IComparable<T>

Parameters

left T?

The left endpoint; null means +∞.

right T?

The right endpoint; null means +∞.

Returns

int

Type Parameters

T

The numeric type.

CompareStartpoint<T>(T?, T?)

Compares two startpoint values where null represents −∞. Returns a negative value if left < right, zero if equal, and a positive value if left > right.

public static int CompareStartpoint<T>(T? left, T? right) where T : struct, IBinaryInteger<T>, IComparable<T>

Parameters

left T?

The left startpoint; null means −∞.

right T?

The right startpoint; null means −∞.

Returns

int

Type Parameters

T

The numeric type.

Decrement<T>(T?)

Decrements an endpoint if finite. If already null => -∞ or +∞? We have to interpret usage.

This method is used for subtracting an interval: we want (r2.Min - 1) etc. But if r2.Min = null => that's -∞ => (r2.Min - 1) => -∞ => no difference.

public static T? Decrement<T>(this T? x) where T : struct, IBinaryInteger<T>, IMinMaxValue<T>

Parameters

x T?

Returns

T?

Type Parameters

T

GreaterOrEqual<T>(T?, T?)

Compares a >= b. Null => +∞ is always >= any finite.

public static bool GreaterOrEqual<T>(this T? a, T? b) where T : struct, IBinaryInteger<T>, IComparable<T>

Parameters

a T?
b T?

Returns

bool

Type Parameters

T

Increment<T>(T?)

Increments an endpoint if finite. If x is +∞ => stays +∞, if x is -∞ => stays -∞.

public static T? Increment<T>(this T? x) where T : struct, IBinaryInteger<T>, IMinMaxValue<T>

Parameters

x T?

Returns

T?

Type Parameters

T

LessOrEqual<T>(T?, T?)

Compares a <= b. Null is interpreted as +∞ here for convenience. If a is +∞ => then a <= b is false unless b is also +∞.

public static bool LessOrEqual<T>(this T? a, T? b) where T : struct, IBinaryInteger<T>, IComparable<T>

Parameters

a T?
b T?

Returns

bool

Type Parameters

T

Less<T>(T?, T?)

Compares a < b. Uses LessOrEqual but excludes equality.

public static bool Less<T>(this T? a, T? b) where T : struct, IBinaryInteger<T>, IComparable<T>

Parameters

a T?
b T?

Returns

bool

Type Parameters

T

MaxEndpoint<T>(T?, T?)

Returns the maximum of two end endpoints where null represents +∞. If either argument is null, the result is null (+∞ wins).

public static T? MaxEndpoint<T>(T? a, T? b) where T : struct, IBinaryInteger<T>

Parameters

a T?
b T?

Returns

T?

Type Parameters

T

MaxStartpoint<T>(T?, T?)

Returns the maximum of two start endpoints where null represents −∞. If only one argument is null, the finite value wins.

public static T? MaxStartpoint<T>(T? a, T? b) where T : struct, IBinaryInteger<T>

Parameters

a T?
b T?

Returns

T?

Type Parameters

T

MinEndpoint<T>(T?, T?)

Returns the minimum of two end endpoints where null represents +∞. If only one argument is null, the finite value wins.

public static T? MinEndpoint<T>(T? a, T? b) where T : struct, IBinaryInteger<T>

Parameters

a T?
b T?

Returns

T?

Type Parameters

T

MinStartpoint<T>(T?, T?)

Returns the minimum of two start endpoints where null represents −∞. If either argument is null, the result is null (−∞ wins).

public static T? MinStartpoint<T>(T? a, T? b) where T : struct, IBinaryInteger<T>

Parameters

a T?
b T?

Returns

T?

Type Parameters

T

Parse<T>(string)

Parses a textual token into a nullable value using the current culture, interpreting the infinity symbols "∞" and "inf" as null.

public static T? Parse<T>(string token) where T : struct, IBinaryInteger<T>, IComparable<T>, IParsable<T>

Parameters

token string

The token that represents the number.

Returns

T?

The parsed number or null for infinity.

Type Parameters

T

The numeric type to parse.

Parse<T>(string, IFormatProvider)

Parses a textual token into a nullable value using the specified IFormatProvider, interpreting the infinity symbols "∞" and "inf" as null.

public static T? Parse<T>(string token, IFormatProvider formatProvider) where T : struct, IBinaryInteger<T>, IComparable<T>, IParsable<T>

Parameters

token string

The token that represents the number.

formatProvider IFormatProvider

The culture-specific formatting information to use.

Returns

T?

The parsed number or null for infinity.

Type Parameters

T

The numeric type to parse.