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

#include <Number.h>

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

Classes

class  Guard
 
struct  unchecked
 

Public Types

enum  rounding_mode { to_nearest , towards_zero , downward , upward }
 

Public Member Functions

constexpr Number ()=default
 
 Number (rep mantissa)
 
 Number (rep mantissa, int exponent)
 
constexpr Number (rep mantissa, int exponent, unchecked) noexcept
 
constexpr rep mantissa () const noexcept
 
constexpr int exponent () const noexcept
 
constexpr Number operator+ () const noexcept
 
constexpr Number operator- () const noexcept
 
Numberoperator++ ()
 
Number operator++ (int)
 
Numberoperator-- ()
 
Number operator-- (int)
 
Numberoperator+= (Number const &x)
 
Numberoperator-= (Number const &x)
 
Numberoperator*= (Number const &x)
 
Numberoperator/= (Number const &x)
 
 operator rep () const
 Conversions to Number are implicit and conversions away from Number are explicit.
 
constexpr int signum () const noexcept
 Return the sign of the amount.
 
Number truncate () const noexcept
 

Static Public Member Functions

static constexpr Number min () noexcept
 
static constexpr Number max () noexcept
 
static constexpr Number lowest () noexcept
 
static rounding_mode getround ()
 
static rounding_mode setround (rounding_mode mode)
 

Static Public Attributes

static constexpr std::int64_t minMantissa = 1'000'000'000'000'000LL
 
static constexpr std::int64_t maxMantissa = minMantissa * 10 - 1
 
static constexpr int minExponent = -32768
 
static constexpr int maxExponent = 32768
 

Private Types

using rep = std::int64_t
 

Private Member Functions

void normalize ()
 
constexpr bool isnormal () const noexcept
 

Private Attributes

rep mantissa_ {0}
 
int exponent_ {std::numeric_limits<int>::lowest()}
 

Static Private Attributes

static thread_local rounding_mode mode_ = Number::to_nearest
 

Friends

constexpr bool operator== (Number const &x, Number const &y) noexcept
 
constexpr bool operator!= (Number const &x, Number const &y) noexcept
 
constexpr bool operator< (Number const &x, Number const &y) noexcept
 
constexpr bool operator> (Number const &x, Number const &y) noexcept
 
constexpr bool operator<= (Number const &x, Number const &y) noexcept
 
constexpr bool operator>= (Number const &x, Number const &y) noexcept
 
std::ostreamoperator<< (std::ostream &os, Number const &x)
 

Detailed Description

Definition at line 25 of file Number.h.

Member Typedef Documentation

◆ rep

Definition at line 27 of file Number.h.

Member Enumeration Documentation

◆ rounding_mode

Enumerator
to_nearest 
towards_zero 
downward 
upward 

Definition at line 173 of file Number.h.

Constructor & Destructor Documentation

◆ Number() [1/4]

constexpr xrpl::Number::Number ( )
explicitconstexprdefault

◆ Number() [2/4]

xrpl::Number::Number ( rep  mantissa)

Definition at line 204 of file Number.h.

◆ Number() [3/4]

xrpl::Number::Number ( rep  mantissa,
int  exponent 
)
explicit

Definition at line 198 of file Number.h.

◆ Number() [4/4]

constexpr xrpl::Number::Number ( rep  mantissa,
int  exponent,
unchecked   
)
explicitconstexprnoexcept

Definition at line 193 of file Number.h.

Member Function Documentation

◆ mantissa()

constexpr Number::rep xrpl::Number::mantissa ( ) const
constexprnoexcept

Definition at line 209 of file Number.h.

◆ exponent()

constexpr int xrpl::Number::exponent ( ) const
constexprnoexcept

Definition at line 215 of file Number.h.

◆ operator+()

constexpr Number xrpl::Number::operator+ ( ) const
constexprnoexcept

Definition at line 221 of file Number.h.

◆ operator-()

constexpr Number xrpl::Number::operator- ( ) const
constexprnoexcept

Definition at line 227 of file Number.h.

◆ operator++() [1/2]

Number & xrpl::Number::operator++ ( )

Definition at line 235 of file Number.h.

◆ operator++() [2/2]

Number xrpl::Number::operator++ ( int  )

Definition at line 242 of file Number.h.

◆ operator--() [1/2]

Number & xrpl::Number::operator-- ( )

Definition at line 250 of file Number.h.

◆ operator--() [2/2]

Number xrpl::Number::operator-- ( int  )

Definition at line 257 of file Number.h.

◆ operator+=()

Number & xrpl::Number::operator+= ( Number const &  x)

Definition at line 267 of file Number.cpp.

◆ operator-=()

Number & xrpl::Number::operator-= ( Number const &  x)

Definition at line 265 of file Number.h.

◆ operator*=()

Number & xrpl::Number::operator*= ( Number const &  x)

Definition at line 388 of file Number.cpp.

◆ operator/=()

Number & xrpl::Number::operator/= ( Number const &  x)

Definition at line 445 of file Number.cpp.

◆ min()

constexpr Number xrpl::Number::min ( )
staticconstexprnoexcept

Definition at line 303 of file Number.h.

◆ max()

constexpr Number xrpl::Number::max ( )
staticconstexprnoexcept

Definition at line 309 of file Number.h.

◆ lowest()

constexpr Number xrpl::Number::lowest ( )
staticconstexprnoexcept

Definition at line 315 of file Number.h.

◆ operator rep()

xrpl::Number::operator rep ( ) const
explicit

Conversions to Number are implicit and conversions away from Number are explicit.

This design encourages and facilitates the use of Number as the preferred type for floating point arithmetic as it makes "mixed mode" more convenient, e.g. MPTAmount + Number.

Definition at line 477 of file Number.cpp.

◆ signum()

constexpr int xrpl::Number::signum ( ) const
constexprnoexcept

Return the sign of the amount.

Definition at line 140 of file Number.h.

◆ truncate()

Number xrpl::Number::truncate ( ) const
noexcept

Definition at line 506 of file Number.cpp.

◆ getround()

Number::rounding_mode xrpl::Number::getround ( )
static

Definition at line 28 of file Number.cpp.

◆ setround()

Number::rounding_mode xrpl::Number::setround ( rounding_mode  mode)
static

Definition at line 34 of file Number.cpp.

◆ normalize()

void xrpl::Number::normalize ( )
private

Definition at line 226 of file Number.cpp.

◆ isnormal()

constexpr bool xrpl::Number::isnormal ( ) const
constexprprivatenoexcept

Definition at line 321 of file Number.h.

Friends And Related Symbol Documentation

◆ operator==

constexpr bool operator== ( Number const &  x,
Number const &  y 
)
friend

Definition at line 97 of file Number.h.

◆ operator!=

constexpr bool operator!= ( Number const &  x,
Number const &  y 
)
friend

Definition at line 103 of file Number.h.

◆ operator<

constexpr bool operator< ( Number const &  x,
Number const &  y 
)
friend

Definition at line 108 of file Number.h.

◆ operator>

constexpr bool operator> ( Number const &  x,
Number const &  y 
)
friend

Definition at line 149 of file Number.h.

◆ operator<=

constexpr bool operator<= ( Number const &  x,
Number const &  y 
)
friend

Definition at line 154 of file Number.h.

◆ operator>=

constexpr bool operator>= ( Number const &  x,
Number const &  y 
)
friend

Definition at line 161 of file Number.h.

◆ operator<<

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

Definition at line 166 of file Number.h.

Member Data Documentation

◆ mantissa_

rep xrpl::Number::mantissa_ {0}
private

Definition at line 28 of file Number.h.

◆ exponent_

int xrpl::Number::exponent_ {std::numeric_limits<int>::lowest()}
private

Definition at line 29 of file Number.h.

◆ minMantissa

constexpr std::int64_t xrpl::Number::minMantissa = 1'000'000'000'000'000LL
staticconstexpr

Definition at line 33 of file Number.h.

◆ maxMantissa

constexpr std::int64_t xrpl::Number::maxMantissa = minMantissa * 10 - 1
staticconstexpr

Definition at line 35 of file Number.h.

◆ minExponent

constexpr int xrpl::Number::minExponent = -32768
staticconstexpr

Definition at line 39 of file Number.h.

◆ maxExponent

constexpr int xrpl::Number::maxExponent = 32768
staticconstexpr

Definition at line 40 of file Number.h.

◆ mode_

thread_local Number::rounding_mode xrpl::Number::mode_ = Number::to_nearest
staticprivate

Definition at line 181 of file Number.h.