Skip to content

OnixLabs.Numerics.BigDecimalEqualityComparer

matthew edited this page May 27, 2026 · 1 revision

BigDecimalEqualityComparer Class

Provides equality comparison for BigDecimal 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, and all user-defined strategies are served through the comparer parameter overloads on BigDecimal.

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

Definition

public abstract class BigDecimalEqualityComparer : IEqualityComparer<BigDecimal>, IEqualityComparer

Remarks

BigDecimalEqualityComparer is the abstract base for 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 BigDecimal.Equals(BigDecimal, BigDecimalEqualityComparer) or the static BigDecimal.Equals(BigDecimal, BigDecimal, BigDecimalEqualityComparer) to select the comparison strategy explicitly. The instance Equals(BigDecimal) and GetHashCode() members on BigDecimal always use Strict.

Fields

Member Type Description
Strict BigDecimalEqualityComparer Compares both UnscaledValue and Scale; 1.20 ≠ 1.2.
Semantic BigDecimalEqualityComparer Compares by numeric value only; 1.20 == 1.2.

Strict

public static readonly BigDecimalEqualityComparer Strict;

An equality comparer that requires both UnscaledValue and Scale to be identical. Used by BigDecimal.Equals(BigDecimal), BigDecimal.GetHashCode(), and BigDecimal.Equals(BigDecimal, BigDecimal).


Semantic

public static readonly BigDecimalEqualityComparer Semantic;

An equality comparer that considers two BigDecimal values equal when they represent the same numeric value, regardless of scale. Used by operator == and operator !=.

Methods

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

Equals(BigDecimal, BigDecimal)

public abstract bool Equals(BigDecimal x, BigDecimal y)

Determines whether the two specified BigDecimal values are equal according to the comparer's strategy.

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

Returns — true if the values are equal; otherwise, false.


GetHashCode(BigDecimal)

public abstract int GetHashCode(BigDecimal obj)

Returns a hash code for the specified BigDecimal value, consistent with the comparer's equality strategy.

Parameter Type Description
obj BigDecimal 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 the two specified objects are equal. Returns true only when both x and y are BigDecimal values that are equal under this comparer's strategy.

Returns — true if both are equal BigDecimal values; otherwise, false.


GetHashCode(object)

public int GetHashCode(object obj)

Returns a hash code for the specified object. Delegates to GetHashCode(BigDecimal) when obj is a BigDecimal; otherwise delegates to object.GetHashCode().

Returns — A 32-bit signed integer hash code.

See Also

ONIXLabs .NET Library


Clone this wiki locally