Skip to content

Compare a SignificantNumber with a PreciseNumber through Equals [minor] - #144

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/143-equals-precise-number
Nov 4, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/143-equals-precise-number

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Summary

sig.Equals(precise) bound to the record struct's synthesized Equals(object). That boxed the PreciseNumber, failed the is SignificantNumber check, and returned false, while ==, CompareTo(object) and precise.Equals(sig) all reported the values as equal.

  • Adds public bool Equals(PreciseNumber other) => Value.Equals(other);, so s.Equals(p), p.Equals(s) and s == p give the same answer.
  • The XML remarks document the case that can't be fixed: a PreciseNumber boxed as object and passed to Equals(object) still compares unequal, because a record struct's Equals(object) can't be customised, even though CompareTo(object) returns 0.

This adds public API, hence [minor].

Tests

  • EqualsPreciseNumber_AgreesInBothArgumentOrdersAndWithOperator covers equal values (including 1.50 vs 1.5, zero and a negative) and unequal values in both orders, and checks the result against == and CompareTo(object).
  • EqualsObject_BoxedPreciseNumber_IsFalseEvenWhenEqual pins the documented boxed case.
  • With the fix reverted, the equal-value rows of the first test fail at s.Equals(p). With the fix, the whole suite passes locally (197/197, net10.0).

Fixes #143


Generated by Claude Code

sig.Equals(precise) bound to the record struct's Equals(object), which boxed
the PreciseNumber and returned false, while ==, CompareTo and
precise.Equals(sig) all reported the values as equal. Add
Equals(PreciseNumber) so both argument orders and == agree, and document
that a boxed PreciseNumber passed to Equals(object) still compares unequal.

Fixes #143

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5i3pXEZd4rgcVGix1
Move Equals(PreciseNumber) below the last CompareTo overload, which Sonar
rule S4136 flagged after it landed between two of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5i3pXEZd4rgcVGix1
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit a85aae0 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/143-equals-precise-number branch November 4, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sig.Equals(precise) returns false for equal values while sig == precise, precise.Equals(sig) and CompareTo all say they're equal

2 participants