SyDEVS  v0.7
Simulation-based analysis of complex systems involving people, devices, physical elements, and dynamic environments.
sydevs::scale Class Reference

A data type which represents the general concept of scale as a dimensionless power of 1000. More...

#include <scale.h>

Public Types

using level_type = int8
 The type used to store the "level" integer internally. More...
 

Public Member Functions

constexpr scale ()
 Constructs a scale value with a level integer of zero. More...
 
constexpr scale (int64 level)
 Constructs a scale value with the specified level integer. More...
 
constexpr scale (const scale &)=default
 Copy constructor. More...
 
scaleoperator= (const scale &)=default
 Copy assignment. More...
 
 scale (scale &&)=default
 Move constructor. More...
 
scaleoperator= (scale &&)=default
 Move assignment. More...
 
 ~scale ()=default
 Destructor. More...
 
constexpr int64 level () const
 Returns the level integer. More...
 
constexpr float64 approx () const
 Returns 1000 to the power of level(), rounded if necessary. More...
 
scaleoperator++ ()
 Increments (prefix) the level integer. More...
 
scale operator++ (int)
 Increments (postfix) the level integer. More...
 
scaleoperator-- ()
 Decrements (prefix) the level integer. More...
 
scale operator-- (int)
 Decrements (postfix) the level integer. More...
 
scaleoperator+= (int64 rhs)
 Adds rhs to the level integer. More...
 
scaleoperator-= (int64 rhs)
 Subtracts rhs from the level integer. More...
 
constexpr const scale operator+ () const
 Returns a copy of the scale value. More...
 
constexpr const scale operator- () const
 Returns the negation of the scale value. More...
 
constexpr const scale operator+ (int64 rhs) const
 Returns a scale value with level() increased by rhs. More...
 
constexpr const scale operator- (int64 rhs) const
 Returns a scale value with level() decreased by rhs. More...
 
constexpr int64 operator- (scale rhs) const
 Returns level() minus rhs.level(). More...
 
constexpr float64 operator/ (scale rhs) const
 Returns 1000 to the power of level() divided by 1000 to the power of rhs.level(). More...
 
constexpr bool operator== (scale rhs) const
 Returns true if the scale value equals rhs. More...
 
constexpr bool operator!= (scale rhs) const
 Returns true if the scale value does not equal rhs. More...
 
constexpr bool operator< (scale rhs) const
 Returns true if the scale value is less than rhs. More...
 
constexpr bool operator> (scale rhs) const
 Returns true if the scale value is greater than rhs. More...
 
constexpr bool operator<= (scale rhs) const
 Returns true if the scale value is at most rhs. More...
 
constexpr bool operator>= (scale rhs) const
 Returns true if the scale value is at least rhs. More...
 
char symbol () const
 Provdes the metric prefix symbol. More...
 

Detailed Description

A data type which represents the general concept of scale as a dimensionless power of 1000.

A scale value can be used to characterize the resolution or approximate magnitude of a meausure of time (i.e. a duration), space (i.e. a distance), or potentially any other physical quantity.

Every scale value encapsulates a level integer, obtained using level(), which serves as the exponent of the dimensionless power of 1000. If the level integer is known at compile time, one of the predefined scale constants below may be used instead of invoking the constructor. The constants are named based on metric prefixes.

yocto // scale(-8);
zepto // scale(-7);
atto // scale(-6);
femto // scale(-5);
pico // scale(-4);
nano // scale(-3);
micro // scale(-2);
milli // scale(-1);
unit // scale(0);
kilo // scale(1);
mega // scale(2);
giga // scale(3);
tera // scale(4);
peta // scale(5);
exa // scale(6);
zetta // scale(7);
yotta // scale(8);
constexpr scale kilo
Definition: scale.h:164
constexpr scale atto
Definition: scale.h:157
constexpr scale giga
Definition: scale.h:166
constexpr scale peta
Definition: scale.h:168
constexpr scale femto
Definition: scale.h:158
constexpr scale zepto
Definition: scale.h:156
constexpr scale milli
Definition: scale.h:162
constexpr scale tera
Definition: scale.h:167
constexpr scale exa
Definition: scale.h:169
constexpr scale pico
Definition: scale.h:159
constexpr scale zetta
Definition: scale.h:170
constexpr scale yocto
Definition: scale.h:155
constexpr scale micro
Definition: scale.h:161
constexpr scale yotta
Definition: scale.h:171
constexpr scale unit
Definition: scale.h:163
constexpr scale nano
Definition: scale.h:160
constexpr scale mega
Definition: scale.h:165

The prefix name may be obtained from the scale value using the operator<< overload.

The represented power (i.e. 1000 to the power level()) may be approximated using approx().

The following operators adjust the scale value's level integer: ++, --, +=, -=, +, -, ==, *, !=, <, >, <=, >=. Examples are below.

nano + 4 == kilo
micro - 3 == femto
tera - mega == 2
1 + milli == unit

The / operator yields the factor that separates two scales. The result is approximated if the denominator is a larger scale than the numerator.

milli/pico == 1000000000

Member Typedef Documentation

◆ level_type

The type used to store the "level" integer internally.

Constructor & Destructor Documentation

◆ scale() [1/4]

constexpr sydevs::scale::scale ( )
constexpr

Constructs a scale value with a level integer of zero.

◆ scale() [2/4]

constexpr sydevs::scale::scale ( int64  level)
explicitconstexpr

Constructs a scale value with the specified level integer.

The dimensionless power represented by the constructed scale value is 1000 to the power of level.

Parameters
levelThe level integer of the scale value.

◆ scale() [3/4]

constexpr sydevs::scale::scale ( const scale )
constexprdefault

Copy constructor.

◆ scale() [4/4]

sydevs::scale::scale ( scale &&  )
default

Move constructor.

◆ ~scale()

sydevs::scale::~scale ( )
default

Destructor.

Member Function Documentation

◆ approx()

constexpr float64 sydevs::scale::approx ( ) const
constexpr

Returns 1000 to the power of level(), rounded if necessary.

◆ level()

constexpr int64 sydevs::scale::level ( ) const
constexpr

Returns the level integer.

◆ operator!=()

constexpr bool sydevs::scale::operator!= ( scale  rhs) const
constexpr

Returns true if the scale value does not equal rhs.

◆ operator+() [1/2]

constexpr const scale sydevs::scale::operator+ ( ) const
constexpr

Returns a copy of the scale value.

◆ operator+() [2/2]

constexpr const scale sydevs::scale::operator+ ( int64  rhs) const
constexpr

Returns a scale value with level() increased by rhs.

◆ operator++() [1/2]

scale & sydevs::scale::operator++ ( )

Increments (prefix) the level integer.

◆ operator++() [2/2]

scale sydevs::scale::operator++ ( int  )

Increments (postfix) the level integer.

◆ operator+=()

scale & sydevs::scale::operator+= ( int64  rhs)

Adds rhs to the level integer.

◆ operator-() [1/3]

constexpr const scale sydevs::scale::operator- ( ) const
constexpr

Returns the negation of the scale value.

◆ operator-() [2/3]

constexpr const scale sydevs::scale::operator- ( int64  rhs) const
constexpr

Returns a scale value with level() decreased by rhs.

◆ operator-() [3/3]

constexpr int64 sydevs::scale::operator- ( scale  rhs) const
constexpr

Returns level() minus rhs.level().

◆ operator--() [1/2]

scale & sydevs::scale::operator-- ( )

Decrements (prefix) the level integer.

◆ operator--() [2/2]

scale sydevs::scale::operator-- ( int  )

Decrements (postfix) the level integer.

◆ operator-=()

scale & sydevs::scale::operator-= ( int64  rhs)

Subtracts rhs from the level integer.

◆ operator/()

constexpr float64 sydevs::scale::operator/ ( scale  rhs) const
constexpr

Returns 1000 to the power of level() divided by 1000 to the power of rhs.level().

◆ operator<()

constexpr bool sydevs::scale::operator< ( scale  rhs) const
constexpr

Returns true if the scale value is less than rhs.

◆ operator<=()

constexpr bool sydevs::scale::operator<= ( scale  rhs) const
constexpr

Returns true if the scale value is at most rhs.

◆ operator=() [1/2]

scale& sydevs::scale::operator= ( const scale )
default

Copy assignment.

◆ operator=() [2/2]

scale& sydevs::scale::operator= ( scale &&  )
default

Move assignment.

◆ operator==()

constexpr bool sydevs::scale::operator== ( scale  rhs) const
constexpr

Returns true if the scale value equals rhs.

◆ operator>()

constexpr bool sydevs::scale::operator> ( scale  rhs) const
constexpr

Returns true if the scale value is greater than rhs.

◆ operator>=()

constexpr bool sydevs::scale::operator>= ( scale  rhs) const
constexpr

Returns true if the scale value is at least rhs.

◆ symbol()

char sydevs::scale::symbol ( ) const

Provdes the metric prefix symbol.

The metric prefix symbol is the single-character as indicated at http://en.wikipedia.org/wiki/Metric_prefix for level() >= -8 and level() <= 8. If the level integer is outside this range, or if it is zero, then integer 0 is returned.

Returns
The single-character metric prefix symbol or 0.

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