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

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

#include <IOUAmount.h>

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

Public Member Functions

 IOUAmount ()=default
 
 IOUAmount (Number const &other)
 
 IOUAmount (beast::Zero)
 
 IOUAmount (mantissa_type mantissa, exponent_type exponent)
 
IOUAmountoperator= (beast::Zero)
 
 operator Number () const
 
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.
 
int signum () const noexcept
 Return the sign of the amount.
 
exponent_type exponent () const noexcept
 
mantissa_type mantissa () const noexcept
 

Static Public Member Functions

static IOUAmount minPositiveAmount ()
 

Private Types

using mantissa_type = std::int64_t
 
using exponent_type = int
 

Private Member Functions

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

Static Private Member Functions

static IOUAmount fromNumber (Number const &number)
 

Private Attributes

mantissa_type mantissa_
 
exponent_type exponent_
 

Friends

std::ostreamoperator<< (std::ostream &os, IOUAmount const &x)
 

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 truncate to zero.

Definition at line 24 of file IOUAmount.h.

Member Typedef Documentation

◆ mantissa_type

Definition at line 27 of file IOUAmount.h.

◆ exponent_type

using xrpl::IOUAmount::exponent_type = int
private

Definition at line 28 of file IOUAmount.h.

Constructor & Destructor Documentation

◆ IOUAmount() [1/4]

xrpl::IOUAmount::IOUAmount ( )
default

◆ IOUAmount() [2/4]

xrpl::IOUAmount::IOUAmount ( Number const &  other)
explicit

Definition at line 123 of file IOUAmount.cpp.

◆ IOUAmount() [3/4]

xrpl::IOUAmount::IOUAmount ( beast::Zero  )

Definition at line 93 of file IOUAmount.h.

◆ IOUAmount() [4/4]

xrpl::IOUAmount::IOUAmount ( mantissa_type  mantissa,
exponent_type  exponent 
)

Definition at line 98 of file IOUAmount.h.

Member Function Documentation

◆ normalize()

void xrpl::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 71 of file IOUAmount.cpp.

◆ fromNumber()

IOUAmount xrpl::IOUAmount::fromNumber ( Number const &  number)
staticprivate

Definition at line 55 of file IOUAmount.cpp.

◆ operator=()

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

Definition at line 104 of file IOUAmount.h.

◆ operator Number()

xrpl::IOUAmount::operator Number ( ) const

Definition at line 113 of file IOUAmount.h.

◆ operator+=()

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

Definition at line 132 of file IOUAmount.cpp.

◆ operator-=()

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

Definition at line 119 of file IOUAmount.h.

◆ operator-()

IOUAmount xrpl::IOUAmount::operator- ( ) const

Definition at line 126 of file IOUAmount.h.

◆ operator==()

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

Definition at line 132 of file IOUAmount.h.

◆ operator<()

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

Definition at line 137 of file IOUAmount.h.

◆ operator bool()

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

Returns true if the amount is not zero.

Definition at line 143 of file IOUAmount.h.

◆ signum()

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

Return the sign of the amount.

Definition at line 149 of file IOUAmount.h.

◆ exponent()

IOUAmount::exponent_type xrpl::IOUAmount::exponent ( ) const
noexcept

Definition at line 155 of file IOUAmount.h.

◆ mantissa()

IOUAmount::mantissa_type xrpl::IOUAmount::mantissa ( ) const
noexcept

Definition at line 161 of file IOUAmount.h.

◆ minPositiveAmount()

IOUAmount xrpl::IOUAmount::minPositiveAmount ( )
static

Definition at line 65 of file IOUAmount.cpp.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream os,
IOUAmount const &  x 
)
friend

Definition at line 86 of file IOUAmount.h.

Member Data Documentation

◆ mantissa_

mantissa_type xrpl::IOUAmount::mantissa_
private

Definition at line 29 of file IOUAmount.h.

◆ exponent_

exponent_type xrpl::IOUAmount::exponent_
private

Definition at line 30 of file IOUAmount.h.