Skip to content

Conversation

@dongyuan
Copy link

@dongyuan dongyuan commented May 7, 2025

Issue:
The current diffing mechanism for Decimal types results in output that is either missing, incorrect, or displays internal implementation details (mantissa values), making it difficult to understand actual differences.

Current Behavior (Examples):

  1. Missing Output: differ(30 as Decimal, 300 as Decimal) produces no diff output, despite the values being different.
  2. Misleading Internal State: differ(1.5 as Decimal, 2.5 as Decimal) outputs a diff of the internal mantissa:
    _mantissa:
        .0:
            Received: 25
            Expected: 15
    
    This reflects the internal representation, not the user-facing numeric values "1.5" and "2.5".

Root Cause:
Swift's Decimal type has a complex internal structure. The generic diffing logic is relying on default Equatable conformance or raw struct field comparison, was inspecting these internal components instead of the interpreted numeric value. This led to comparisons of mantissas and other internal fields, rather than the semantic value of the decimal.

Changes Implemented:
This change introduces custom diffing logic for Decimal types to:

  • Numeric Comparison: Decimal values are now compared based on their actual numeric equality, ensuring that 30 and 300 are correctly identified as different.
  • Human-Readable Output: When Decimal values are part of a diff, they are now formatted as their standard string/numeric representation (e.g., "1.5", "300") instead of internal components.

@krzysztofzablocki krzysztofzablocki merged commit 1deadf0 into krzysztofzablocki:master May 8, 2025
1 check passed
@krzysztofzablocki
Copy link
Owner

awesome, thanks!

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.

2 participants