rippled
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Static Private Member Functions | List of all members
xrpl::MantissaRange Struct Reference

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

#include <Number.h>

Collaboration diagram for xrpl::MantissaRange:
Collaboration graph
[legend]

Public Types

enum  mantissa_scale { small , large }
 
using rep = std::uint64_t
 

Public Member Functions

constexpr MantissaRange (mantissa_scale scale_)
 

Public Attributes

rep min
 
rep max
 
int log
 
mantissa_scale scale
 

Static Private Member Functions

static constexpr rep getMin (mantissa_scale scale_)
 

Detailed Description

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

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

The mantissa_scale enum indicates whether the range is "small" or "large". This intentionally restricts the number of MantissaRanges that can be instantiated to two: 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" scale is 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.

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 70 of file Number.h.

Member Typedef Documentation

◆ rep

Definition at line 72 of file Number.h.

Member Enumeration Documentation

◆ mantissa_scale

Enumerator
small 
large 

Definition at line 73 of file Number.h.

Constructor & Destructor Documentation

◆ MantissaRange()

constexpr xrpl::MantissaRange::MantissaRange ( mantissa_scale  scale_)
explicitconstexpr

Definition at line 75 of file Number.h.

Member Function Documentation

◆ getMin()

static constexpr rep xrpl::MantissaRange::getMin ( mantissa_scale  scale_)
staticconstexprprivate

Definition at line 87 of file Number.h.

Member Data Documentation

◆ min

rep xrpl::MantissaRange::min

Definition at line 80 of file Number.h.

◆ max

rep xrpl::MantissaRange::max

Definition at line 81 of file Number.h.

◆ log

int xrpl::MantissaRange::log

Definition at line 82 of file Number.h.

◆ scale

mantissa_scale xrpl::MantissaRange::scale

Definition at line 83 of file Number.h.