Skip to content

Commit

Permalink
Minor refactoring in Time as discussed in PR #685
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobj committed Jun 20, 2017
1 parent 24d9d4c commit c4d37d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 3 additions & 4 deletions nestkernel/nest_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ Time::fromstamp( Time::ms_stamp t )
// intended ones.
tic_t n = static_cast< tic_t >( t.t * Range::TICS_PER_MS );
n -= ( n % Range::TICS_PER_STEP );
long s = n * Range::TICS_PER_STEP_INV;
double ms = s * Range::MS_PER_STEP;
const double ms = n * Range::TICS_PER_STEP_INV * Range::MS_PER_STEP;
if ( ms < t.t )
{
n += Range::TICS_PER_STEP;
Expand All @@ -203,11 +202,11 @@ Time::reset_to_defaults()

std::ostream& operator<<( std::ostream& strm, const Time& t )
{
if ( t.tics == Time::LIM_NEG_INF.tics )
if ( t.is_neg_inf() )
{
strm << "-INF";
}
else if ( t.tics == Time::LIM_POS_INF.tics )
else if ( t.is_pos_inf() )
{
strm << "+INF";
}
Expand Down
25 changes: 20 additions & 5 deletions nestkernel/nest_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,22 @@ class Time
bool
is_neg_inf() const
{
return tics == LIM_NEG_INF.tics;
return tics <= LIM_NEG_INF.tics; // currently tics can never
// become smaller than
// LIM_NEG_INF.tics. however if
// LIM_NEG_INF.tics represent
// negative infinity, any smaller
// value cannot be larger and
// thus must be infinity as
// well. to be on the safe side
// we use less-or-equal instead
// of just equal.
}

bool
is_pos_inf() const
{
return tics >= LIM_POS_INF.tics; // see comment for is_neg_inf()
}

bool
Expand Down Expand Up @@ -493,11 +508,11 @@ class Time
double
get_ms() const
{
if ( tics == LIM_POS_INF.tics )
if ( is_pos_inf() )
{
return LIM_POS_INF_ms;
}
if ( tics == LIM_NEG_INF.tics )
if ( is_neg_inf() )
{
return LIM_NEG_INF_ms;
}
Expand All @@ -507,11 +522,11 @@ class Time
delay
get_steps() const
{
if ( tics == LIM_POS_INF.tics )
if ( is_pos_inf() )
{
return LIM_POS_INF.steps;
}
if ( tics == LIM_NEG_INF.tics )
if ( is_neg_inf() )
{
return LIM_NEG_INF.steps;
}
Expand Down

0 comments on commit c4d37d9

Please sign in to comment.