SST  14.0.0
StructuralSimulationToolkit
SST::UnitAlgebra Class Reference

Performs Unit math in full precision. More...

#include <unitAlgebra.h>

Inheritance diagram for SST::UnitAlgebra:
SST::Core::Serialization::serializable SST::Core::Serialization::serializable_type< UnitAlgebra >

Data Structures

class  InvalidNumberString
 Exception for when number couldn't be parsed. More...
 
class  InvalidUnitType
 Base exception for all exception classes in UnitAlgebra. More...
 
class  NonMatchingUnits
 Exception for when attempting operations between objects that do not have matching base units. More...
 

Public Member Functions

void init (const std::string &val)
 
 UnitAlgebra (const std::string &val)
 
Create a new UnitAlgebra instance, and pre-populate with a parsed value. More...
 
 UnitAlgebra (const UnitAlgebra &)=default
 Copy constructor.
 
void print (std::ostream &stream, int32_t precision=6)
 Print to an ostream the value. More...
 
void printWithBestSI (std::ostream &stream, int32_t precision=6)
 Print to an ostream the value Formats the number using SI-prefixes. More...
 
std::string toString (int32_t precision=6) const
 Return a string representation of this value. More...
 
std::string toStringBestSI (int32_t precision=6) const
 Return a string representation of this value Formats the number using SI-prefixes. More...
 
UnitAlgebraoperator= (const std::string &v)
 
UnitAlgebraoperator*= (const UnitAlgebra &v)
 Multiply by an argument;.
 
template<typename T >
UnitAlgebraoperator*= (const T &v)
 Multiply by an argument;.
 
UnitAlgebraoperator/= (const UnitAlgebra &v)
 Divide by an argument;.
 
template<typename T >
UnitAlgebraoperator/= (const T &v)
 Divide by an argument;.
 
UnitAlgebraoperator+= (const UnitAlgebra &v)
 Add an argument;.
 
template<typename T >
UnitAlgebraoperator+= (const T &v)
 Multiply by an argument;.
 
UnitAlgebraoperator-= (const UnitAlgebra &v)
 Subtract an argument;.
 
template<typename T >
UnitAlgebraoperator-= (const T &v)
 Divide by an argument;.
 
bool operator> (const UnitAlgebra &v) const
 Compare if this object is greater than the argument.
 
bool operator>= (const UnitAlgebra &v) const
 Compare if this object is greater than, or equal to, the argument.
 
bool operator< (const UnitAlgebra &v) const
 Compare if this object is less than the argument.
 
bool operator<= (const UnitAlgebra &v) const
 Compare if this object is less than, or equal to, the argument.
 
bool operator== (const UnitAlgebra &v) const
 Compare if this object is equal to, the argument.
 
bool operator!= (const UnitAlgebra &v) const
 Compare if this object is not equal to, the argument.
 
UnitAlgebrainvert ()
 Apply a reciprocal operation to the object.
 
bool hasUnits (const std::string &u) const
 Returns true if the units in the parameter string are found in this object.
 
sst_big_num getValue () const
 Return the raw value.
 
int64_t getRoundedValue () const
 
double getDoubleValue () const
 
bool isValueZero () const
 
void serialize_order (SST::Core::Serialization::serializer &ser) override
 
- Public Member Functions inherited from SST::Core::Serialization::serializable
virtual const char * cls_name () const =0
 
virtual uint32_t cls_id () const =0
 
virtual std::string serialization_name () const =0
 

Additional Inherited Members

- Static Public Attributes inherited from SST::Core::Serialization::serializable
static constexpr uint32_t NullClsId = std::numeric_limits<uint32_t>::max()
 
- Protected Types inherited from SST::Core::Serialization::serializable
enum  cxn_flag_t { ConstructorFlag }
 
- Static Protected Member Functions inherited from SST::Core::Serialization::serializable
static void serializable_abort (uint32_t line, const char *file, const char *func, const char *obj)
 

Detailed Description

Performs Unit math in full precision.

Allows operations such as multiplying a frequency by 2.

Constructor & Destructor Documentation

◆ UnitAlgebra()

UnitAlgebra::UnitAlgebra ( const std::string &  val)


Create a new UnitAlgebra instance, and pre-populate with a parsed value.

Parameters
valValue to parse. It is of the following format:
val := NUMBER( )?UNITS
NUMBER := (-)?[0-9]+(.[0-9]+)?
UNITS := UNITGROUP(/UNITGROUP)
UNITGROUP := UNIT(-UNIT)*
UNIT := (SIPREFIX)?(BASEUNIT|COMPUNIT)
SIPREFIX := {a,f,p,n,u,m,[kKMGTPE]i?}
BASEUNIT := {s,B,b,events}
COMPUNIT := {Hz,hz,Bps,bps,event}

Member Function Documentation

◆ getRoundedValue()

int64_t UnitAlgebra::getRoundedValue ( ) const
Returns
Rounded value as a 64bit integer

Referenced by SST::TimeLord::getTimeConverter().

◆ print()

void UnitAlgebra::print ( std::ostream &  stream,
int32_t  precision = 6 
)

Print to an ostream the value.

Parameters
streamOutput stream
precisionNumber of digits to print. Default is 6. <= 0 is full precision.

◆ printWithBestSI()

void UnitAlgebra::printWithBestSI ( std::ostream &  stream,
int32_t  precision = 6 
)

Print to an ostream the value Formats the number using SI-prefixes.

Parameters
streamOutput stream
precisionNumber of digits to print. Default is 6. <= 0 is full precision.

◆ toString()

string UnitAlgebra::toString ( int32_t  precision = 6) const

Return a string representation of this value.

Parameters
precisionNumber of digits to print. Default is 6. <= 0 is full precision.

◆ toStringBestSI()

string UnitAlgebra::toStringBestSI ( int32_t  precision = 6) const

Return a string representation of this value Formats the number using SI-prefixes.

Parameters
precisionNumber of digits to print. Default is 6. <= 0 is full precision.

References SST::decimal_fixedpoint< whole_words, fraction_words >::toString().

Referenced by SST::SimulatorHeartbeat::execute(), SST::CheckpointAction::execute(), and SST::TimeLord::getTimeConverter().


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