rippled
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ripple::IOUAmount Class Reference

Floating point representation of amounts with high dynamic range. More...

Inheritance diagram for ripple::IOUAmount:
Inheritance graph
[legend]
Collaboration diagram for ripple::IOUAmount:
Collaboration graph
[legend]

Public Member Functions

 IOUAmount ()=default
 
 IOUAmount (IOUAmount const &other)=default
 
IOUAmountoperator= (IOUAmount const &other)=default
 
 IOUAmount (beast::Zero)
 
 IOUAmount (std::int64_t mantissa, int exponent)
 
IOUAmountoperator= (beast::Zero)
 
IOUAmountoperator+= (IOUAmount const &other)
 
IOUAmountoperator-= (IOUAmount const &other)
 
IOUAmount operator- () const
 
bool operator== (IOUAmount const &other) const
 
bool operator< (IOUAmount const &other) const
 
 operator bool () const noexcept
 Returns true if the amount is not zero. More...
 
int signum () const noexcept
 Return the sign of the amount. More...
 
int exponent () const noexcept
 
std::int64_t mantissa () const noexcept
 

Private Member Functions

void normalize ()
 Adjusts the mantissa and exponent to the proper range. More...
 

Private Attributes

std::int64_t mantissa_
 
int exponent_
 

Detailed Description

Floating point representation of amounts with high dynamic range.

Amounts are stored as a normalized signed mantissa and an exponent. The range of the normalized exponent is [-96,80] and the range of the absolute value of the normalized mantissa is [1000000000000000, 9999999999999999].

Arithmetic operations can throw std::overflow_error during normalization if the amount exceeds the largest representable amount, but underflows will silently trunctate to zero.

Definition at line 41 of file IOUAmount.h.

Constructor & Destructor Documentation

◆ IOUAmount() [1/4]

ripple::IOUAmount::IOUAmount ( )
default

◆ IOUAmount() [2/4]

ripple::IOUAmount::IOUAmount ( IOUAmount const &  other)
default

◆ IOUAmount() [3/4]

ripple::IOUAmount::IOUAmount ( beast::Zero  )

Definition at line 63 of file IOUAmount.h.

◆ IOUAmount() [4/4]

ripple::IOUAmount::IOUAmount ( std::int64_t  mantissa,
int  exponent 
)

Definition at line 68 of file IOUAmount.h.

Member Function Documentation

◆ normalize()

void ripple::IOUAmount::normalize ( )
private

Adjusts the mantissa and exponent to the proper range.

This can throw if the amount cannot be normalized, or is larger than the largest value that can be represented as an IOU amount. Amounts that are too small to be represented normalize to 0.

Definition at line 38 of file IOUAmount.cpp.

◆ operator=() [1/2]

IOUAmount& ripple::IOUAmount::operator= ( IOUAmount const &  other)
default

◆ operator=() [2/2]

IOUAmount& ripple::IOUAmount::operator= ( beast::Zero  )

Definition at line 74 of file IOUAmount.h.

◆ operator+=()

IOUAmount & ripple::IOUAmount::operator+= ( IOUAmount const &  other)

Definition at line 80 of file IOUAmount.cpp.

◆ operator-=()

IOUAmount& ripple::IOUAmount::operator-= ( IOUAmount const &  other)

Definition at line 87 of file IOUAmount.h.

◆ operator-()

IOUAmount ripple::IOUAmount::operator- ( ) const

Definition at line 94 of file IOUAmount.h.

◆ operator==()

bool ripple::IOUAmount::operator== ( IOUAmount const &  other) const

Definition at line 100 of file IOUAmount.h.

◆ operator<()

bool ripple::IOUAmount::operator< ( IOUAmount const &  other) const

Definition at line 122 of file IOUAmount.cpp.

◆ operator bool()

ripple::IOUAmount::operator bool ( ) const
explicitnoexcept

Returns true if the amount is not zero.

Definition at line 109 of file IOUAmount.h.

◆ signum()

int ripple::IOUAmount::signum ( ) const
noexcept

Return the sign of the amount.

Definition at line 116 of file IOUAmount.h.

◆ exponent()

int ripple::IOUAmount::exponent ( ) const
noexcept

Definition at line 122 of file IOUAmount.h.

◆ mantissa()

std::int64_t ripple::IOUAmount::mantissa ( ) const
noexcept

Definition at line 128 of file IOUAmount.h.

Member Data Documentation

◆ mantissa_

std::int64_t ripple::IOUAmount::mantissa_
private

Definition at line 45 of file IOUAmount.h.

◆ exponent_

int ripple::IOUAmount::exponent_
private

Definition at line 46 of file IOUAmount.h.