OMNeT++ Simulation Library  6.0.3
Simulation Time

Description

The simulation kernel and models use simtime_t to represent simulation time. simtime_t is an alias to the SimTime class that is 64-bit fixed-point representation with a globally shared exponent. This group describes simtime_t, SimTime, and related types and macros.

Classes

class  SimTime
 int64_t-based, base-10 fixed-point simulation time. More...
 

Macros

#define SIMTIME_MAX   omnetpp::SimTime::getMaxTime()
 The maximum representable simulation time with the current resolution. More...
 
#define SIMTIME_ZERO   omnetpp::SimTime::ZERO
 Zero simulation time. More...
 
#define SIMTIME_STR(t)   ((t).str().c_str())
 Convert simtime_t to a C string. More...
 
#define SIMTIME_DBL(t)   ((t).dbl())
 Convert simtime_t to a double. This conversion incurs precision loss. More...
 

Typedefs

typedef SimTime simtime_t
 Represents simulation time. More...
 

Enumerations

enum  SimTimeUnit
 Enum for simulation time base-10 exponents. More...
 

Functions

simtime_t simTime ()
 Returns the current simulation time. More...
 
const SimTime floor (const SimTime &x)
 simtime_t version of floor(double) from math.h. More...
 
const SimTime floor (const SimTime &x, const SimTime &unit, const SimTime &offset=SimTime())
 Generalized version of floor(), accepting a unit and an offset: floor(x,u,off) = floor((x-off)/u)*u + off. More...
 
const SimTime ceil (const SimTime &x)
 simtime_t version of ceil(double) from math.h. More...
 
const SimTime ceil (const SimTime &x, const SimTime &unit, const SimTime &offset=SimTime())
 Generalized version of ceil(), accepting a unit and an offset: ceil(x,u,off) = ceil((x-off)/u)*u + off. More...
 
const SimTime fabs (const SimTime &x)
 Returns the absolute value of the simulation time x. More...
 
int64_t div (const SimTime &x, const SimTime &y)
 Computes the quotient of the simulation times x and y. The quotient is the algebraic quotient with any fractional part discarded (truncated towards zero). The function internally relies on the standard C/C++ integer division (/) operation. More...
 
const SimTime fmod (const SimTime &x, const SimTime &y)
 Computes the remainder of the division of two simulation times. More...
 
SIM_API int64_t preciseDiv (int64_t x, const SimTime &y, int64_t &fractionNumerator, int64_t &fractionDenominator)
 Precise division of an integer and a simulation time. More...
 

Variables

const typedef simtime_tsimtime_t_cref
 Constant reference to a simtime_t. More...
 
const typedef double const_simtime_t
 This type must be used for global variables representing simulation time. More...
 

Macro Definition Documentation

◆ SIMTIME_MAX

#define SIMTIME_MAX   omnetpp::SimTime::getMaxTime()

The maximum representable simulation time with the current resolution.

◆ SIMTIME_ZERO

#define SIMTIME_ZERO   omnetpp::SimTime::ZERO

Zero simulation time.

Using SIMTIME_ZERO can be more efficient than using the 0 constant, especially in non-optimized (debug) builds, because it spares the SimTime constructor call.

◆ SIMTIME_STR

#define SIMTIME_STR (   t)    ((t).str().c_str())

Convert simtime_t to a C string.

◆ SIMTIME_DBL

#define SIMTIME_DBL (   t)    ((t).dbl())

Convert simtime_t to a double. This conversion incurs precision loss.

Typedef Documentation

◆ simtime_t

typedef SimTime simtime_t

Represents simulation time.

Enumeration Type Documentation

◆ SimTimeUnit

Enum for simulation time base-10 exponents.

Function Documentation

◆ simTime()

simtime_t omnetpp::simTime ( )
inline

Returns the current simulation time.

References cSimulation::getActiveSimulation(), and cSimulation::getSimTime().

◆ floor() [1/2]

const SimTime omnetpp::floor ( const SimTime x)
inline

simtime_t version of floor(double) from math.h.

References getScale(), raw(), and setRaw().

◆ floor() [2/2]

const SimTime omnetpp::floor ( const SimTime x,
const SimTime unit,
const SimTime offset = SimTime() 
)
inline

Generalized version of floor(), accepting a unit and an offset: floor(x,u,off) = floor((x-off)/u)*u + off.

Examples: floor(2.1234, 0.1) = 2.1; floor(2.1234, 0.1, 0.007) = 2.107; floor(2.1006, 0.1, 0.007) = 2.007.

References raw(), and setRaw().

◆ ceil() [1/2]

const SimTime omnetpp::ceil ( const SimTime x)
inline

simtime_t version of ceil(double) from math.h.

References getScale(), raw(), and setRaw().

◆ ceil() [2/2]

const SimTime omnetpp::ceil ( const SimTime x,
const SimTime unit,
const SimTime offset = SimTime() 
)
inline

Generalized version of ceil(), accepting a unit and an offset: ceil(x,u,off) = ceil((x-off)/u)*u + off.

References raw(), and setRaw().

◆ fabs()

const SimTime omnetpp::fabs ( const SimTime x)
inline

Returns the absolute value of the simulation time x.

References raw().

◆ div()

int64_t omnetpp::div ( const SimTime x,
const SimTime y 
)
inline

Computes the quotient of the simulation times x and y. The quotient is the algebraic quotient with any fractional part discarded (truncated towards zero). The function internally relies on the standard C/C++ integer division (/) operation.

The handling of division by zero (i.e. when y==0) is platform dependent; on most platforms it causes a runtime error of some sort.

See also
fmod()

References raw().

◆ fmod()

const SimTime omnetpp::fmod ( const SimTime x,
const SimTime y 
)
inline

Computes the remainder of the division of two simulation times.

The function internally relies on the standard C/C++ integer modulo (%) operation. This has implications regarding the sign of the result: If both operands are nonnegative then the remainder is nonnegative; if not, the sign of the remainder is implementation-defined. However, the following is always true (substitute div() for / and fmod() for %): (x/y) * y + xy == x

The handling of division by zero (i.e. when y==0) is platform dependent; on most platforms it causes a runtime error of some sort.

See also
div()

References raw(), and setRaw().

◆ preciseDiv()

SIM_API int64_t omnetpp::preciseDiv ( int64_t  x,
const SimTime y,
int64_t &  fractionNumerator,
int64_t &  fractionDenominator 
)

Precise division of an integer and a simulation time.

The result is returned as an integer part (in the return value) and a fraction (in the fractionNumerator, fractionDenominator output parameters).

See also
div()

Variable Documentation

◆ simtime_t_cref

const typedef simtime_t& simtime_t_cref

Constant reference to a simtime_t.

In many configurations (e.g. debug builds), it is more efficient to return a SimTime from a function as a const ref than by value.

◆ const_simtime_t

const typedef double const_simtime_t

This type must be used for global variables representing simulation time.

The normal simtime_t type (i.e. SimTime) cannot be used for static variables, because the scale exponent is only available after the configuration has been read by the simulation program. This type is simply an alias of double.