Modify

Opened 16 years ago

Closed 12 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

Attachments (0)

Change History (2)

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

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 Changed 12 years ago by martin_wille

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain martin_wille.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.