SST  11.1.0
StructuralSimulationToolkit
SST::decimal_fixedpoint< whole_words, fraction_words > Class Template Reference

Class that implements a decimal fixed-point number. More...

#include <decimal_fixedpoint.h>

Public Member Functions

constexpr int getWholeWords () const
 Get the value of whole_words template parameter.
 
constexpr int getFractionWords () const
 Get the value of fraction_words template parameter.
 
 decimal_fixedpoint ()
 Default constructor. More...
 
 decimal_fixedpoint (const std::string &init)
 Build a decimal_fixedpoint using a string initializer. More...
 
template<class T >
 decimal_fixedpoint (T init, typename std::enable_if< std::is_unsigned< T >::value >::type *=nullptr)
 Build a decimal_fixedpoint using a 64-bit unsigned number. More...
 
template<class T >
 decimal_fixedpoint (T init, typename std::enable_if< std::is_signed< T >::value &&std::is_integral< T >::value >::type *=nullptr)
 Build a decimal_fixedpoint using a 64-bit signed number. More...
 
template<class T >
 decimal_fixedpoint (const T init, typename std::enable_if< std::is_floating_point< T >::value >::type *=nullptr)
 Build a decimal_fixedpoint using a double. More...
 
 decimal_fixedpoint (const decimal_fixedpoint &init)
 Build a decimal_fixedpoint using another decimal_fixedpoint. More...
 
decimal_fixedpointoperator= (const decimal_fixedpoint &v)
 Equal operator for other decimal_fixedpoint objects.
 
decimal_fixedpointoperator= (uint64_t v)
 Equal operator for 64-bit unsigned int.
 
decimal_fixedpointoperator= (int64_t v)
 Equal operator for 64-bit signed int.
 
decimal_fixedpointoperator= (double v)
 Equal operator for double.
 
decimal_fixedpointoperator= (const std::string &v)
 Equal operator for string.
 
void negate ()
 Negate the value (change the sign bit).
 
double toDouble () const
 Return a double precision version of the decimal_fixedpoint. More...
 
int64_t toLong () const
 Return a int64_t version of the decimal_fixedpoint. More...
 
uint64_t toUnsignedLong () const
 Return a uint64_t version of the decimal_fixedpoint. More...
 
bool isZero () const
 Return true if value is zero, otherwise return false.
 
template<typename T >
convert_to (typename std::enable_if< std::is_unsigned< T >::value >::type *=0) const
 Templated conversion function for unsigned types.
 
template<typename T >
convert_to (typename std::enable_if< std::is_signed< T >::value &&std::is_integral< T >::value >::type *=0) const
 Templated conversion function for signed integral types.
 
template<typename T >
convert_to (typename std::enable_if< std::is_floating_point< T >::value >::type *=0) const
 Templated conversion function for floating point types.
 
std::string toString (int32_t precision=6) const
 Create a string representation of this decimal_fixedpoint. More...
 
decimal_fixedpointoperator+= (const decimal_fixedpoint &v)
 Adds another number to this one and sets it equal to the result. More...
 
decimal_fixedpointoperator-= (const decimal_fixedpoint &v)
 Subtracts another number from this one and sets it equal to the result. More...
 
decimal_fixedpointoperator*= (const decimal_fixedpoint &v)
 Multiplies another number to this one and sets it equal to the result. More...
 
decimal_fixedpointoperator/= (const decimal_fixedpoint &v)
 Divides another number from this one and sets it equal to the result. More...
 
decimal_fixedpointinverse ()
 Inverts the number (1 divided by this number)
 
bool operator== (const decimal_fixedpoint &v) const
 Checks to see if two numbers are equal. More...
 
bool operator!= (const decimal_fixedpoint &v) const
 Checks to see if two numbers are not equal. More...
 
bool operator> (const decimal_fixedpoint &v) const
 Checks to see if this number is greater than another number. More...
 
bool operator>= (const decimal_fixedpoint &v) const
 Checks to see if this number is greater than or equal to another number. More...
 
bool operator< (const decimal_fixedpoint &v) const
 Checks to see if this number is less than another number. More...
 
bool operator<= (const decimal_fixedpoint &v) const
 Checks to see if this number is less than or equal to another number. More...
 

Static Public Attributes

static constexpr uint32_t storage_radix = 100000000
 
static constexpr uint64_t storage_radix_long = 100000000l
 
static constexpr int32_t digits_per_word = 8
 

Friends

template<int A, int B>
class sst_dec_fixed
 

Detailed Description

template<int whole_words, int fraction_words>
class SST::decimal_fixedpoint< whole_words, fraction_words >

Class that implements a decimal fixed-point number.

Fixed point class that stores digits in radix-10. Size is specified in words, and each word represents 8 digits.

Template Parameters
whole_wordsNumber of words used to represent the digits to the left of the decimal point. Each word represents 8 decimal digits.
fraction_wordsNumber of words used to represent the digits to the right of the decimal point. Each word represents 8 decimal digits.

Constructor & Destructor Documentation

template<int whole_words, int fraction_words>
SST::decimal_fixedpoint< whole_words, fraction_words >::decimal_fixedpoint ( )
inline

Default constructor.

Builds a decimal_fixedpoint with the value 0;

template<int whole_words, int fraction_words>
SST::decimal_fixedpoint< whole_words, fraction_words >::decimal_fixedpoint ( const std::string &  init)
inline

Build a decimal_fixedpoint using a string initializer.

Parameters
initInitialization string. The format is similar to the c++ double precision strings. For example 1.234, -1.234, 0.234, 1.234e14, 1.234e14, etc.
template<int whole_words, int fraction_words>
template<class T >
SST::decimal_fixedpoint< whole_words, fraction_words >::decimal_fixedpoint ( init,
typename std::enable_if< std::is_unsigned< T >::value >::type *  = nullptr 
)
inline

Build a decimal_fixedpoint using a 64-bit unsigned number.

Parameters
initInitialization value.
template<int whole_words, int fraction_words>
template<class T >
SST::decimal_fixedpoint< whole_words, fraction_words >::decimal_fixedpoint ( init,
typename std::enable_if< std::is_signed< T >::value &&std::is_integral< T >::value >::type *  = nullptr 
)
inline

Build a decimal_fixedpoint using a 64-bit signed number.

Parameters
initInitialization value.
template<int whole_words, int fraction_words>
template<class T >
SST::decimal_fixedpoint< whole_words, fraction_words >::decimal_fixedpoint ( const T  init,
typename std::enable_if< std::is_floating_point< T >::value >::type *  = nullptr 
)
inline

Build a decimal_fixedpoint using a double.

Parameters
initInitialization value.
template<int whole_words, int fraction_words>
SST::decimal_fixedpoint< whole_words, fraction_words >::decimal_fixedpoint ( const decimal_fixedpoint< whole_words, fraction_words > &  init)
inline

Build a decimal_fixedpoint using another decimal_fixedpoint.

Parameters
initInitialization value.

Member Function Documentation

template<int whole_words, int fraction_words>
bool SST::decimal_fixedpoint< whole_words, fraction_words >::operator!= ( const decimal_fixedpoint< whole_words, fraction_words > &  v) const
inline

Checks to see if two numbers are not equal.

Parameters
vNumber to check equality against
template<int whole_words, int fraction_words>
decimal_fixedpoint& SST::decimal_fixedpoint< whole_words, fraction_words >::operator*= ( const decimal_fixedpoint< whole_words, fraction_words > &  v)
inline

Multiplies another number to this one and sets it equal to the result.

Parameters
vNumber to multiply to this one

Referenced by SST::decimal_fixedpoint< 3, 3 >::operator/=().

template<int whole_words, int fraction_words>
decimal_fixedpoint& SST::decimal_fixedpoint< whole_words, fraction_words >::operator+= ( const decimal_fixedpoint< whole_words, fraction_words > &  v)
inline

Adds another number to this one and sets it equal to the result.

Parameters
vNumber to add to this one

Referenced by SST::decimal_fixedpoint< 3, 3 >::operator-=().

template<int whole_words, int fraction_words>
decimal_fixedpoint& SST::decimal_fixedpoint< whole_words, fraction_words >::operator-= ( const decimal_fixedpoint< whole_words, fraction_words > &  v)
inline

Subtracts another number from this one and sets it equal to the result.

Parameters
vNumber to subtract from this one
template<int whole_words, int fraction_words>
decimal_fixedpoint& SST::decimal_fixedpoint< whole_words, fraction_words >::operator/= ( const decimal_fixedpoint< whole_words, fraction_words > &  v)
inline

Divides another number from this one and sets it equal to the result.

Parameters
vNumber to divide from this one
template<int whole_words, int fraction_words>
bool SST::decimal_fixedpoint< whole_words, fraction_words >::operator< ( const decimal_fixedpoint< whole_words, fraction_words > &  v) const
inline

Checks to see if this number is less than another number.

Parameters
vNumber to compare to
template<int whole_words, int fraction_words>
bool SST::decimal_fixedpoint< whole_words, fraction_words >::operator<= ( const decimal_fixedpoint< whole_words, fraction_words > &  v) const
inline

Checks to see if this number is less than or equal to another number.

Parameters
vNumber to compare to
template<int whole_words, int fraction_words>
bool SST::decimal_fixedpoint< whole_words, fraction_words >::operator== ( const decimal_fixedpoint< whole_words, fraction_words > &  v) const
inline

Checks to see if two numbers are equal.

Parameters
vNumber to check equality against
template<int whole_words, int fraction_words>
bool SST::decimal_fixedpoint< whole_words, fraction_words >::operator> ( const decimal_fixedpoint< whole_words, fraction_words > &  v) const
inline

Checks to see if this number is greater than another number.

Parameters
vNumber to compare to
template<int whole_words, int fraction_words>
bool SST::decimal_fixedpoint< whole_words, fraction_words >::operator>= ( const decimal_fixedpoint< whole_words, fraction_words > &  v) const
inline

Checks to see if this number is greater than or equal to another number.

Parameters
vNumber to compare to
template<int whole_words, int fraction_words>
double SST::decimal_fixedpoint< whole_words, fraction_words >::toDouble ( ) const
inline

Return a double precision version of the decimal_fixedpoint.

There is possible precision loss in this conversion.

Referenced by SST::decimal_fixedpoint< 3, 3 >::convert_to(), and SST::decimal_fixedpoint< 3, 3 >::inverse().

template<int whole_words, int fraction_words>
int64_t SST::decimal_fixedpoint< whole_words, fraction_words >::toLong ( ) const
inline

Return a int64_t version of the decimal_fixedpoint.

There is possible precision loss in this conversion.

Referenced by SST::decimal_fixedpoint< 3, 3 >::convert_to().

template<int whole_words, int fraction_words>
std::string SST::decimal_fixedpoint< whole_words, fraction_words >::toString ( int32_t  precision = 6) const
inline

Create a string representation of this decimal_fixedpoint.

Parameters
precisionPrecision to use when printing number

Referenced by SST::UnitAlgebra::toStringBestSI().

template<int whole_words, int fraction_words>
uint64_t SST::decimal_fixedpoint< whole_words, fraction_words >::toUnsignedLong ( ) const
inline

Return a uint64_t version of the decimal_fixedpoint.

There is possible precision loss in this conversion.

Referenced by SST::decimal_fixedpoint< 3, 3 >::convert_to().


The documentation for this class was generated from the following file: