cwTime.h/cpp : Added fracSecondsToSpec()
This commit is contained in:
parent
c68f741ccf
commit
1ed6202885
12
cwTime.cpp
12
cwTime.cpp
@ -297,6 +297,13 @@ cw::rc_t cw::time::futureMs( spec_t& ts, unsigned ms )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cw::time::fracSecondsToSpec( spec_t& ts, double sec )
|
||||||
|
{
|
||||||
|
const unsigned long long ns_per_sec = 1000000000;
|
||||||
|
ts.tv_sec = (unsigned long long)sec;
|
||||||
|
ts.tv_nsec = (sec - ts.tv_sec) * ns_per_sec;
|
||||||
|
}
|
||||||
|
|
||||||
void cw::time::secondsToSpec( spec_t& ts, unsigned sec )
|
void cw::time::secondsToSpec( spec_t& ts, unsigned sec )
|
||||||
{
|
{
|
||||||
ts.tv_sec = sec;
|
ts.tv_sec = sec;
|
||||||
@ -305,12 +312,13 @@ void cw::time::secondsToSpec( spec_t& ts, unsigned sec )
|
|||||||
|
|
||||||
double cw::time::specToSeconds( const spec_t& t )
|
double cw::time::specToSeconds( const spec_t& t )
|
||||||
{
|
{
|
||||||
|
const long long ns_per_sec = 1000000000;
|
||||||
spec_t ts = t;
|
spec_t ts = t;
|
||||||
double sec = ts.tv_sec;
|
double sec = ts.tv_sec;
|
||||||
while( ts.tv_nsec >= 1000000000 )
|
while( ts.tv_nsec >= ns_per_sec )
|
||||||
{
|
{
|
||||||
sec += 1.0;
|
sec += 1.0;
|
||||||
ts.tv_nsec -= 1000000000;
|
ts.tv_nsec -= ns_per_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sec + ((double)ts.tv_nsec)/1e9;
|
return sec + ((double)ts.tv_nsec)/1e9;
|
||||||
|
1
cwTime.h
1
cwTime.h
@ -73,6 +73,7 @@ namespace cw
|
|||||||
// Advance the current time by 'ms' milliseconds;
|
// Advance the current time by 'ms' milliseconds;
|
||||||
rc_t futureMs( spec_t& ts, unsigned ms );
|
rc_t futureMs( spec_t& ts, unsigned ms );
|
||||||
|
|
||||||
|
void fracSecondsToSpec( spec_t& ts, double sec );
|
||||||
void secondsToSpec( spec_t& ts, unsigned sec );
|
void secondsToSpec( spec_t& ts, unsigned sec );
|
||||||
double specToSeconds( const spec_t& ts );
|
double specToSeconds( const spec_t& ts );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user