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

Member Typedef Documentation

◆ rep

Definition at line 37 of file Number.h.

Member Enumeration Documentation

◆ rounding_mode

Enumerator
to_nearest 
towards_zero 
downward 
upward 

Definition at line 196 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 225 of file Number.h.

◆ Number() [3/4]

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

Definition at line 219 of file Number.h.

◆ Number() [4/4]

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

Definition at line 214 of file Number.h.

Member Function Documentation

◆ mantissa()

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

Definition at line 230 of file Number.h.

◆ exponent()

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

Definition at line 236 of file Number.h.

◆ operator+()

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

Definition at line 242 of file Number.h.

◆ operator-()

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

Definition at line 248 of file Number.h.

◆ operator++() [1/2]

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

Definition at line 256 of file Number.h.

◆ operator++() [2/2]

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

Definition at line 263 of file Number.h.

◆ operator--() [1/2]

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

Definition at line 271 of file Number.h.

◆ operator--() [2/2]

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

Definition at line 278 of file Number.h.

◆ operator+=()

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

Definition at line 230 of file Number.cpp.

◆ operator-=()

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

Definition at line 286 of file Number.h.

◆ operator*=()

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

Definition at line 376 of file Number.cpp.

◆ operator/=()

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

Definition at line 448 of file Number.cpp.

◆ min()

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

Definition at line 324 of file Number.h.

◆ max()

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

Definition at line 330 of file Number.h.

◆ lowest()

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

Definition at line 336 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 480 of file Number.cpp.

◆ signum()

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

Return the sign of the amount.

Definition at line 148 of file Number.h.

◆ truncate()

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

Definition at line 154 of file Number.h.

◆ getround()

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

Definition at line 47 of file Number.cpp.

◆ setround()

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

Definition at line 53 of file Number.cpp.

◆ normalize()

void ripple::Number::normalize ( )
private

Definition at line 178 of file Number.cpp.

◆ isnormal()

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

Definition at line 342 of file Number.h.

Friends And Related Symbol Documentation

◆ operator==

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

Definition at line 105 of file Number.h.

◆ operator!=

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

Definition at line 111 of file Number.h.

◆ operator<

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

Definition at line 116 of file Number.h.

◆ operator>

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

Definition at line 172 of file Number.h.

◆ operator<=

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

Definition at line 177 of file Number.h.

◆ operator>=

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

Definition at line 184 of file Number.h.

◆ operator<<

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

Definition at line 189 of file Number.h.

Member Data Documentation

◆ mantissa_

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

Definition at line 38 of file Number.h.

◆ exponent_

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

Definition at line 39 of file Number.h.

◆ minMantissa

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

Definition at line 43 of file Number.h.

◆ maxMantissa

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

Definition at line 44 of file Number.h.

◆ minExponent

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

Definition at line 47 of file Number.h.

◆ maxExponent

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

Definition at line 48 of file Number.h.

◆ mode_

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

Definition at line 204 of file Number.h.