Opened 21 years ago

Closed 17 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:

Description

The computation for number of milliseconds to 
Sleep() reads


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

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 by Markus Schöpflin, 17 years ago

Logged In: YES 
user_id=91733

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;
else
...

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

comment:2 by martin_wille, 17 years ago

Status: assignedclosed
Logged In: YES 
user_id=592361

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.