fix: Fix Number comparison operator#7406
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7406 +/- ##
=======================================
Coverage 82.3% 82.3%
=======================================
Files 1011 1011
Lines 76913 76915 +2
Branches 8964 8964
=======================================
+ Hits 63336 63339 +3
+ Misses 13568 13567 -1
Partials 9 9
🚀 New features to boost your workflow:
|
gregtatcam
left a comment
There was a problem hiding this comment.
Looks good to me. I left one suggestion to consider regarding the unit-tests readability.
This reverts commit a28e577.
- Test combinatorically with a large variety of values.
- Separate the int values from the non-int values.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ut the fix" This reverts commit c42a478bb48a578aec670fc1c9ea9dc78208f935.
58cdf96 to
a489708
Compare
|
Rebased on top of the |
| friend constexpr bool | ||
| operator<(Number const& x, Number const& y) noexcept | ||
| operator<(Number const& l, Number const& r) noexcept | ||
| { |
There was a problem hiding this comment.
While I think this PR looks good, I was just wondering if it worth switching to operator<=> here to let the compiler do the job. I made a quick pr (#7410) in case you're interested
@vvysokikh1 Great suggestion and PR. Let's save it for 3.3 so it can get a more thorough looking at. |
High Level Overview of Change
In
operator<, if twoNumbers have the same exponent and the same sign, then the final determination is done by comparing the unsigned mantissas directly. If they are both negative, and not equal it returns the wrong result.Without the renames, comment changes, and test updates, this fix boils down to
Context of Change
I went through all the Number comparisons, and as far as I can determine, all of the ones related to ledger data are guaranteed to have at least one parameter that is non-negative. That means there are no negative to negative comparisons, so we're safe to fix this directly.
Fortunately, the ledger just doesn't deal with a lot of negative numbers. Even with subtraction operations, the results don't go negative (or are checked against zero).
API Impact
libxrplchange (any change that may affectlibxrplor dependents oflibxrpl)