Fix decimal comparison #41
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
The current diffing mechanism for
Decimaltypes 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):
differ(30 as Decimal, 300 as Decimal)produces no diff output, despite the values being different.differ(1.5 as Decimal, 2.5 as Decimal)outputs a diff of the internal mantissa:Root Cause:
Swift's
Decimaltype has a complex internal structure. The generic diffing logic is relying on defaultEquatableconformance 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:
Decimalvalues are now compared based on their actual numeric equality, ensuring that30and300are correctly identified as different.Decimalvalues are part of a diff, they are now formatted as their standard string/numeric representation (e.g., "1.5", "300") instead of internal components.