Greeting !!
The following code works fine….at least more than one second will execute expx function
in function Getexp , I called Getexp every 0.01 second for 100 times,
actually expx function will be called just one time only , that is what I want !!
But , my user need to change to at least more than 0.5 second to call expx ,
since the following code works in tick1 , tick2 in integer type ,
I need advice to change not too many codes below and will satisfy user needs ….
What function will be best suitable foe my case ? time_t won’t work for me in 0.5 sec case!
double Getexp(double valuex)
{
double wgt=0.9 ;
static double value_t0=0.0 ;
static double value_t1=0.0 ;
double dret = 0.0 ;
static time_t tick1=0 ,tick2=0 ;
if(value_t0 < 0.0001)
{
tick1=time(NULL);
tick2=tick1 ;
value_t0 = valuex ;
value_t1 = valuex ;
dret = expx(value_t1,value_t0,wgt) ;
value_t0 = dret ;
return value_t0 ;
}
tick2=time(NULL);
if(tick2 > tick1)
{
tick1 = tick2 ;
value_t1 = valuex ;
dret = expx(value_t1,value_t0,wgt) ;
value_t0 = dret ;
return value_t0 ;
}else
{
return value_t0 ;
}
}
It is rather difficult to assess what is being asked. But I suspect you are complaining that “time()” just has accuracy to the nearest second, but you need sub-second accuracy.
Some clock functions to explore instead of calling “time”.
GetTickCount (Windows)
GetSystemTime (Windows)
gettimeofday
clock_gettime
In other words, consider converting your code to process time in terms of milliseconds and use one of the appropriate calls above to get the that time