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
ripple::Number Class Reference

#include <Number.h>

Collaboration diagram for ripple::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 = 9'999'999'999'999'999LL
 
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 16 of file Number.h.

Member Typedef Documentation

◆ rep

Definition at line 18 of file Number.h.

Member Enumeration Documentation

◆ rounding_mode

Enumerator
to_nearest 
towards_zero 
downward 
upward 

Definition at line 177 of file Number.h.

Constructor & Destructor Documentation

◆ Number() [1/4]

constexpr ripple::Number::Number ( )
explicitconstexprdefault

◆ Number() [2/4]

ripple::Number::Number ( rep  mantissa)

Definition at line 206 of file Number.h.

◆ Number() [3/4]

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

Definition at line 200 of file Number.h.

◆ Number() [4/4]

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

Definition at line 195 of file Number.h.

Member Function Documentation

◆ mantissa()

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

Definition at line 211 of file Number.h.

◆ exponent()

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

Definition at line 217 of file Number.h.

◆ operator+()

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

Definition at line 223 of file Number.h.

◆ operator-()

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

Definition at line 229 of file Number.h.

◆ operator++() [1/2]

Number & ripple::Number::operator++ ( )

Definition at line 237 of file Number.h.

◆ operator++() [2/2]

Number ripple::Number::operator++ ( int  )

Definition at line 244 of file Number.h.

◆ operator--() [1/2]

Number & ripple::Number::operator-- ( )

Definition at line 252 of file Number.h.

◆ operator--() [2/2]

Number ripple::Number::operator-- ( int  )

Definition at line 259 of file Number.h.

◆ operator+=()

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

Definition at line 211 of file Number.cpp.

◆ operator-=()

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

Definition at line 267 of file Number.h.

◆ operator*=()

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

Definition at line 357 of file Number.cpp.

◆ operator/=()

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

Definition at line 429 of file Number.cpp.

◆ min()

constexpr Number ripple::Number::min ( )
staticconstexprnoexcept

Definition at line 305 of file Number.h.

◆ max()

constexpr Number ripple::Number::max ( )
staticconstexprnoexcept

Definition at line 311 of file Number.h.

◆ lowest()

constexpr Number ripple::Number::lowest ( )
staticconstexprnoexcept

Definition at line 317 of file Number.h.

◆ operator rep()

ripple::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 461 of file Number.cpp.

◆ signum()

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

Return the sign of the amount.

Definition at line 129 of file Number.h.

◆ truncate()

Number ripple::Number::truncate ( ) const
noexcept

Definition at line 135 of file Number.h.

◆ getround()

Number::rounding_mode ripple::Number::getround ( )
static

Definition at line 28 of file Number.cpp.

◆ setround()

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

Definition at line 34 of file Number.cpp.

◆ normalize()

void ripple::Number::normalize ( )
private

Definition at line 159 of file Number.cpp.

◆ isnormal()

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

Definition at line 323 of file Number.h.

Friends And Related Symbol Documentation

◆ operator==

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

Definition at line 86 of file Number.h.

◆ operator!=

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

Definition at line 92 of file Number.h.

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

◆ operator<=

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

Definition at line 158 of file Number.h.

◆ operator>=

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

Definition at line 165 of file Number.h.

◆ operator<<

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

Definition at line 170 of file Number.h.

Member Data Documentation

◆ mantissa_

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

Definition at line 19 of file Number.h.

◆ exponent_

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

Definition at line 20 of file Number.h.

◆ minMantissa

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

Definition at line 24 of file Number.h.

◆ maxMantissa

constexpr std::int64_t ripple::Number::maxMantissa = 9'999'999'999'999'999LL
staticconstexpr

Definition at line 25 of file Number.h.

◆ minExponent

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

Definition at line 28 of file Number.h.

◆ maxExponent

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

Definition at line 29 of file Number.h.

◆ mode_

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

Definition at line 185 of file Number.h.