View Single Post
Re: need your advice on clock()
Old
  (#2)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: need your advice on clock() - 13-01-2004

Since your function is simply counting how many seconds have elapsed, try this instead

Code:
static float time_in_seconds = 0;
static long prev_clock = 0;
long current_clock; 
current_clock = clock();
if (current_clock < prev_clock)
time_in_seconds += ( (float) current_clock + 1 ) / CLOCKS_PER_SEC;
else
time_in_seconds = (float) current_clock / CLOCKS_PER_SEC;
return time_in_seconds;
You may want to use double instead of float because float does hot have enough precision from some time conversion operations.

btw, why won't my code format the way I want it to?


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut

Last edited by botmeister; 13-01-2004 at 03:39..
  
Reply With Quote