Skip to content

OnixLabs.Numerics.NumberInfoEqualityComparer

matthew edited this page May 27, 2026 · 1 revision

NumberInfoEqualityComparer Class

Represents an abstract base class for equality comparers that compare NumberInfo values. Two concrete strategies are available as static fields: Strict and Semantic. The class is abstract with a private constructor; the only instances are the two pre-built fields.

Namespace OnixLabs.Numerics
Assembly OnixLabs.Numerics.dll (NuGet)
Inheritance object → NumberInfoEqualityComparer
Implements IEqualityComparer<NumberInfo>, IEqualityComparer

Definition

public abstract class NumberInfoEqualityComparer : IEqualityComparer<NumberInfo>, IEqualityComparer

Remarks

NumberInfoEqualityComparer is the abstract base for the two built-in equality strategies. The constructor is private, so only the two pre-built instances (Strict and Semantic) are available; the class cannot be subclassed externally.

Pass an instance to NumberInfo.Equals(NumberInfo, NumberInfoEqualityComparer) or the static NumberInfo.Equals(NumberInfo, NumberInfo, NumberInfoEqualityComparer) to select the comparison strategy explicitly.

  • Strict — two values are equal only when both UnscaledValue and Scale are identical. The hash code combines UnscaledValue and Scale.
  • Semantic — two values are equal when they represent the same mathematical quantity, regardless of trailing zeros or scale. Equality is delegated to NumberInfoOrdinalityComparer.Default. The hash code combines Significand and Exponent.

Fields

Member Type Description
Strict NumberInfoEqualityComparer An equality comparer that compares both UnscaledValue and Scale.
Semantic NumberInfoEqualityComparer An equality comparer that treats numerically equivalent values as equal regardless of scale.

Strict

public static readonly NumberInfoEqualityComparer Strict;

A NumberInfoEqualityComparer that strictly compares NumberInfo values, including their scale. Two values are equal only when both UnscaledValue and Scale are identical. The hash code combines UnscaledValue and Scale.


Semantic

public static readonly NumberInfoEqualityComparer Semantic;

A NumberInfoEqualityComparer that semantically compares NumberInfo values, treating numerically equivalent values as equal regardless of scale. Equality is determined by NumberInfoOrdinalityComparer.Default. The hash code combines Significand and Exponent.

Methods

Method Returns Description
Equals(NumberInfo, NumberInfo) bool Determines whether two NumberInfo values are equal (abstract).
GetHashCode(NumberInfo) int Returns a hash code for a NumberInfo value (abstract).
Equals(object?, object?) bool Determines whether two objects are equal NumberInfo values.
GetHashCode(object) int Returns a hash code for an object.

Equals(NumberInfo, NumberInfo)

public abstract bool Equals(NumberInfo x, NumberInfo y)

Determines whether two NumberInfo values are equal according to the concrete comparer's strategy.

Parameter Type Description
x NumberInfo The first value to compare.
y NumberInfo The second value to compare.

Returns — true if x and y are equal; otherwise, false.


GetHashCode(NumberInfo)

public abstract int GetHashCode(NumberInfo obj)

Returns a hash code for the specified NumberInfo value according to the concrete comparer's strategy.

Parameter Type Description
obj NumberInfo The value for which to compute a hash code.

Returns — A 32-bit signed integer hash code.


Equals(object?, object?)

public new bool Equals(object? x, object? y)

Determines whether two objects are equal. Returns true only when both x and y are NumberInfo values that are equal according to the concrete comparer's strategy.

Parameter Type Description
x object? The first object to compare.
y object? The second object to compare.

Returns — true if both objects are NumberInfo values that are equal; otherwise, false.


GetHashCode(object)

public int GetHashCode(object obj)

Returns a hash code for the specified object. When obj is a NumberInfo value, delegates to GetHashCode(NumberInfo); otherwise falls back to object.GetHashCode().

Parameter Type Description
obj object The object for which to compute a hash code.

Returns — A 32-bit signed integer hash code.

See Also

ONIXLabs .NET Library


Clone this wiki locally