Opened 16 years ago

Closed 13 years ago

#74 closed Bugs (None)

timeconv.inl to_duration() nsec error

Reported by: cpqlvc Owned by: martin_wille
Milestone: Component: None
Version: None Severity:
Keywords: Cc:


The computation for number of milliseconds to 
Sleep() reads

  milliseconds = static_cast<unsigned>(((xt.sec -
     cur.sec) * MILLISECONDS_PER_SECOND) +
     (((xt.nsec - cur.nsec) +

This computation is incorrect when xt.sec > cur.sec,
but xt.nsec < cur.nsec.  For example 

xt.sec  = 1019600872
xt.nsec = 44320000

cur.sec = 1019600871
cur.nsec = 977320000

Change History (2)

comment:1 Changed 13 years ago by Markus Schöpflin

Logged In: YES 

to_duration() seems to have been fixed in the meantime. But
to_microduration() still contains the same problem. And
probably a merge or copy&past error, because the following
lines look suspect when compared with to_duration(). (Note
the duplicate call to xtime_get().)

res = boost::xtime_get(&cur, boost::TIME_UTC);
assert(res == boost::TIME_UTC);

if (boost::xtime_get(&cur, boost::TIME_UTC) <= 0)
  microseconds = 0;

The two functions look nearly identical anyway, can't this
be implemented in a generic manner?

comment:2 Changed 13 years ago by martin_wille

Status: assignedclosed
Logged In: YES 

I copied the fix from to_duration to to_microduration().
The duplicate function call had been removed before.

This should fix the problems reported in this thread.
The potential for some code cleanup remains.

Note: See TracTickets for help on using tickets.