SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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);

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

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

Constructor & Destructor Documentation

constexpr sydevs::scale::scale ( )

Constructs a scale value with a level integer of zero.

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

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.
constexpr sydevs::scale::scale ( const scale )
default

Copy constructor.

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

Move constructor.

sydevs::scale::~scale ( )
default

Destructor.

Member Function Documentation

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

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

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

Returns the level integer.

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

Returns true if the scale value does not equal rhs.

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

Returns a copy of the scale value.

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

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

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

Increments (prefix) the level integer.

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

Increments (postfix) the level integer.

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

Adds rhs to the level integer.

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

Returns the negation of the scale value.

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

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

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

Returns level() minus rhs.level().

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

Decrements (prefix) the level integer.

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

Decrements (postfix) the level integer.

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

Subtracts rhs from the level integer.

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

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

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

Returns true if the scale value is less than rhs.

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

Returns true if the scale value is at most rhs.

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

Copy assignment.

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

Move assignment.

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

Returns true if the scale value equals rhs.

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

Returns true if the scale value is greater than rhs.

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

Returns true if the scale value is at least rhs.

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: