xrpld
Loading...
Searching...
No Matches
xrpl::MantissaRange Struct Referencefinal

MantissaRange defines a range for the mantissa of a normalized Number. More...

#include <Number.h>

Collaboration diagram for xrpl::MantissaRange:

Classes

class  Access

Public Types

enum class  MantissaScale {
  Small , LargeLegacy , Large320 , Large330 ,
  Large = Large330
}
enum class  CuspRoundingFix : std::uint8_t { Disabled = 0 , Enabled320 = 1 , Enabled330 = 2 , Enabled = Enabled330 }
using rep = std::uint64_t

Public Member Functions

constexpr MantissaRange (MantissaScale sc)

Static Public Member Functions

static std::set< MantissaScale > const & getAllScales ()

Public Attributes

MantissaScale const scale
int const log {getExponent(scale)}
rep const min {getMin(scale, log)}
rep const max {(min * 10) - 1}
CuspRoundingFix const cuspRoundingFix {isCuspFixEnabled(scale)}

Static Private Member Functions

static constexpr int getExponent (MantissaScale scale)
static constexpr rep getMin (MantissaScale scale, int exponent)
static constexpr CuspRoundingFix isCuspFixEnabled (MantissaScale scale)

Detailed Description

MantissaRange defines a range for the mantissa of a normalized Number.

The mantissa is in the range [min, max], where

  • min is a power of 10, and
  • max = min * 10 - 1.

The MantissaScale enum indicates properties of the range: size, and some behavioral options. This intentionally restricts the number of unique MantissaRanges that can be instantiated: one for each scale.

The "Small" scale is based on the behavior of STAmount for IOUs. It has a min value of 10^15, and a max value of 10^16-1. This was sufficient for uses before Lending Protocol was implemented, mostly related to AMM.

However, it does not have sufficient precision to represent the full integer range of int64_t values (-2^63 to 2^63-1), which are needed for XRP and MPT values. The implementation of SingleAssetVault, and LendingProtocol need to represent those integer values accurately and precisely, both for the STNumber field type, and for internal calculations. That necessitated the "large" scale.

The "Large" scales are intended to represent all values that can be represented by an STAmount - IOUs, XRP, and MPTs. It has a min value of 10^18, and a max value of 10^19-1. "LargeLegacy" is like "Large", but preserves a rounding error when a computation results in a mantissa of Number::kMaxRep that needs to be rounded up, but rounds down instead. It will maintain consistent behavior until the fixCleanup3_2_0 amendment is enabled.

Note that if the mentioned amendments are eventually retired, this class should be left in place, but the "Small" scale option should be removed. This will allow for future expansion beyond 64-bits if it is ever needed.

Definition at line 130 of file Number.h.

Member Typedef Documentation

◆ rep

Definition at line 132 of file Number.h.

Member Enumeration Documentation

◆ MantissaScale

Enumerator
Small 
LargeLegacy 
Large320 
Large330 
Large 

Definition at line 136 of file Number.h.

◆ CuspRoundingFix

Enumerator
Disabled 
Enabled320 
Enabled330 
Enabled 

Definition at line 154 of file Number.h.

Constructor & Destructor Documentation

◆ MantissaRange()

xrpl::MantissaRange::MantissaRange ( MantissaScale sc)
explicitconstexpr

Definition at line 167 of file Number.h.

Member Function Documentation

◆ getAllScales()

std::set< MantissaScale > const & xrpl::MantissaRange::getAllScales ( )
static

Definition at line 178 of file Number.h.

◆ getExponent()

constexpr int xrpl::MantissaRange::getExponent ( MantissaScale scale)
staticconstexprprivate

Definition at line 199 of file Number.h.

◆ getMin()

constexpr rep xrpl::MantissaRange::getMin ( MantissaScale scale,
int exponent )
staticconstexprprivate

Definition at line 221 of file Number.h.

◆ isCuspFixEnabled()

constexpr CuspRoundingFix xrpl::MantissaRange::isCuspFixEnabled ( MantissaScale scale)
staticconstexprprivate

Definition at line 229 of file Number.h.

Member Data Documentation

◆ scale

MantissaScale const xrpl::MantissaRange::scale

Definition at line 171 of file Number.h.

◆ log

int const xrpl::MantissaRange::log {getExponent(scale)}

Definition at line 172 of file Number.h.

◆ min

rep const xrpl::MantissaRange::min {getMin(scale, log)}

Definition at line 173 of file Number.h.

◆ max

rep const xrpl::MantissaRange::max {(min * 10) - 1}

Definition at line 174 of file Number.h.

◆ cuspRoundingFix

CuspRoundingFix const xrpl::MantissaRange::cuspRoundingFix {isCuspFixEnabled(scale)}

Definition at line 175 of file Number.h.