Skip to content

Conversation

@ximinez
Copy link
Collaborator

@ximinez ximinez commented Jan 23, 2026

High Level Overview of Change

This PR, if merged, will change the large mantissa range from [10^18, 10^19-1] to [2^63/10+1, 2^63-1]. This allows the Number class member variables to change back to a signed int64 mantissa and int exponent as they were before 3.1.0. This removes the boolean sign flag, and will thus reduce the memory footprint of all Numbers.

This is a pure refactoring. No amendment is required.

Context of Change

Type of Change

  • Refactor (non-breaking change that only restructures code)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)

@ximinez ximinez changed the title Revert "Bugfix: Adds graceful peer disconnection (#5669)" (#5855) DRAFT: Can I use an int64 range? Jan 23, 2026
@ximinez ximinez changed the base branch from develop to release-3.1 January 23, 2026 20:57
@ximinez ximinez force-pushed the ximinez/number-maxint-range branch from 3094798 to c01bfb2 Compare January 23, 2026 21:01
@ximinez ximinez added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Jan 26, 2026
@ximinez ximinez force-pushed the ximinez/number-maxint-range branch from 3934fdb to b0d8b61 Compare January 27, 2026 02:12
@ximinez ximinez added DraftRunCI Normally CI does not run on draft PRs. This opts in. and removed DraftRunCI Normally CI does not run on draft PRs. This opts in. labels Jan 27, 2026
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 98.65772% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.9%. Comparing base (0a626d9) to head (06ff774).

Files with missing lines Patch % Lines
include/xrpl/basics/Number.h 95.5% 1 Missing ⚠️
src/libxrpl/basics/Number.cpp 99.2% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #6275   +/-   ##
=======================================
  Coverage     79.9%   79.9%           
=======================================
  Files          840     840           
  Lines        65549   65556    +7     
  Branches      7266    7266           
=======================================
+ Hits         52351   52357    +6     
- Misses       13198   13199    +1     
Files with missing lines Coverage Δ
include/xrpl/protocol/Protocol.h 100.0% <ø> (ø)
include/xrpl/protocol/STAmount.h 95.6% <100.0%> (+<0.1%) ⬆️
include/xrpl/protocol/SystemParameters.h 100.0% <ø> (ø)
include/xrpl/basics/Number.h 97.9% <95.5%> (-0.8%) ⬇️
src/libxrpl/basics/Number.cpp 98.6% <99.2%> (-0.2%) ⬇️

... and 2 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ximinez ximinez force-pushed the ximinez/number-maxint-range branch from 7275749 to 6fcb32e Compare January 27, 2026 23:22
@ximinez ximinez changed the base branch from release-3.1 to ximinez/staging-3.1 January 27, 2026 23:55
- That makes minMantissa 2^63/10+1.
- Simplifies many of the existing operations, and removes the need for
  the accessors (mantissa() & exponent()) to do any math.
- Simplify shiftExponent().
- Clean up to_string() to prevent integers from including "e0".
- Fix root() and root2() computations by ensuring the mantissas have
  a consistent length.
- Steal changes from @pratik's #6150 to avoid UB
…number-maxint-range

* commit '5f638f55536def0d88b970d1018a465a238e55f4':
  chore: Set ColumnLimit to 120 in clang-format (6288)
…axint-range

* upstream/develop:
  chore: Update secp256k1 and openssl (6327)
  chore: Remove unnecessary script (6326)
  refactor: Replace include guards by '#pragma once' (6322)
  chore: Remove unity builds (6300)
  refactor: Add ServiceRegistry to help modularization (6222)
  fix: Deletes expired NFToken offers from ledger (5707)
  chore: Add .zed editor config directory to .gitignore (6317)
  docs: Update API changelog, add APIv2+APIv3 version documentation (6308)
  fix: Restore config changes that broke standalone mode (6301)
  chore: Add upper-case match for ARM64 in CompilationEnv (6315)
  ci: Update hashes of XRPLF/actions (6316)
  chore: Format all cmake files without comments (6294)
  chore: Add cmake-format pre-commit hook (6279)
  chore: Remove unnecessary `boost::system` requirement from conanfile (6290)
@ximinez ximinez changed the base branch from ximinez/staging-3.1 to tapanito/lending-fix-amendment February 5, 2026 02:10
@ximinez ximinez force-pushed the ximinez/number-maxint-range branch from 9457b82 to 154bb65 Compare February 5, 2026 02:11
@ximinez ximinez changed the title DRAFT: Can I use an int64 range? Use a range of 2^63/10+1 to 2^63-1 for large mantissas Feb 5, 2026
@ximinez ximinez marked this pull request as ready for review February 5, 2026 17:27
@ximinez ximinez requested a review from a team February 5, 2026 17:27
@ximinez ximinez marked this pull request as draft February 5, 2026 17:27
@ximinez ximinez changed the base branch from tapanito/lending-fix-amendment to develop February 5, 2026 17:29
@ximinez ximinez force-pushed the ximinez/number-maxint-range branch from 9a26fdb to 07c0c32 Compare February 5, 2026 17:29
@ximinez ximinez marked this pull request as ready for review February 5, 2026 17:30
@ximinez ximinez removed the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Feb 5, 2026
@ximinez ximinez requested a review from vlntb February 5, 2026 17:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Number class to use a signed int64 mantissa instead of an unsigned mantissa with a separate boolean sign flag. The large mantissa range changes from [10^18, 10^19-1] to [2^63/10+1, 2^63-1], which allows all Number class member variables to fit within signed int64 and int types, reducing the memory footprint.

Changes:

  • Changed Number class mantissa representation from bool negative_ + uint64_t mantissa_ to a single int64_t mantissa_
  • Updated MantissaRange calculations to use [2^63/10+1, 2^63-1] for the large range
  • Refactored internal representation handling with new toInternal() and fromInternal() helper functions
  • Updated all arithmetic operations and utility functions to work with signed mantissa
  • Comprehensive test updates to verify new mantissa range behavior

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
include/xrpl/basics/Number.h Updated Number class to use signed mantissa, removed negative_ flag, refactored MantissaRange struct, added helper functions for internal/external conversion
src/libxrpl/basics/Number.cpp Updated all arithmetic operations and normalization logic to work with signed mantissa, added toInternal/fromInternal implementations
src/test/basics/Number_test.cpp Updated test cases for new mantissa range, added new test function testNormalizeToRange, updated expected values throughout
include/xrpl/protocol/SystemParameters.h Changed maxRep reference to largestMantissa
include/xrpl/protocol/Protocol.h Changed maxRep reference to largestMantissa
include/xrpl/protocol/STAmount.h Added assertion for non-negative Number before normalization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Update explanations.
- Use saver conversions between signed and unsigned.
Copilot AI review requested due to automatic review settings February 5, 2026 23:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 870 to 872
return std::make_pair(sign * static_cast<T>(mantissa), exponent);
}

Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreachable return statement. The previous line (869) already returns, making this line dead code. This second return statement should be removed.

Suggested change
return std::make_pair(sign * static_cast<T>(mantissa), exponent);
}
}

Copilot uses AI. Check for mistakes.
Comment on lines 310 to 314
#if MAXREP
constexpr static internalrep maxRep = std::numeric_limits<rep>::max();
static_assert(maxRep == 9'223'372'036'854'775'807);
static_assert(-maxRep == std::numeric_limits<rep>::min() + 1);
#endif
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preprocessor conditional 'MAXREP' appears to be undefined. These conditional blocks will never be included in the build unless MAXREP is defined elsewhere. Either define MAXREP appropriately or remove these conditional compilation directives if they're no longer needed.

Copilot uses AI. Check for mistakes.
Comment on lines 540 to 543
#if MAXREP
static_assert(smallRange.min < maxRep);
static_assert(smallRange.max < maxRep);
#endif
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preprocessor conditional 'MAXREP' appears to be undefined. These conditional blocks will never be included in the build unless MAXREP is defined elsewhere. Either define MAXREP appropriately or remove these conditional compilation directives if they're no longer needed.

Copilot uses AI. Check for mistakes.
Comment on lines 559 to 562
#if MAXREP
static_assert(largeRange.min < maxRep);
static_assert(largeRange.max > maxRep);
#endif
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preprocessor conditional 'MAXREP' appears to be undefined. These conditional blocks will never be included in the build unless MAXREP is defined elsewhere. Either define MAXREP appropriately or remove these conditional compilation directives if they're no longer needed.

Copilot uses AI. Check for mistakes.
// * 9223372036854775808
// * 9223372036854775809
// They both end up < min, but with a leftover. If they round up, everything
// will be fine. If they don't, well need to bring them up into range.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'well need' should be 'we'll need'.

Suggested change
// will be fine. If they don't, well need to bring them up into range.
// will be fine. If they don't, we'll need to bring them up into range.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 6, 2026 00:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant