architecture independent manipulation of NTP stamps

This commit is contained in:
Jeff Hill
2003-10-28 18:56:56 +00:00
parent c69536fc8e
commit c26cd7fdce
2 changed files with 4 additions and 4 deletions

View File

@@ -391,7 +391,7 @@ epicsTime::epicsTime (const aitTimeStamp &ts)
// 631152000 (at posix epic) + 2272060800 (btw posix and epics epoch) +
// 15 ( leap seconds )
static const unsigned long epicsEpocSecsPastEpochNTP = 2903212815u;
static const double ULONG_MAX_PLUS_ONE = (static_cast<double>(ULONG_MAX) + 1.0);
static const double NTP_FRACTION DENOMINATOR = (static_cast<double>(0xffffffff) + 1.0);
struct l_fp { /* NTP time stamp */
epicsUInt32 l_ui; /* sec past NTP epoch */
@@ -406,7 +406,7 @@ epicsTime::operator l_fp () const
l_fp ts;
ts.l_ui = this->secPastEpoch + epicsEpocSecsPastEpochNTP;
ts.l_uf = static_cast < unsigned long >
( ( this->nSec * ULONG_MAX_PLUS_ONE ) / nSecPerSec );
( ( this->nSec * NTP_FRACTION DENOMINATOR ) / nSecPerSec );
return ts;
}
@@ -417,7 +417,7 @@ epicsTime::epicsTime ( const l_fp & ts )
{
this->secPastEpoch = ts.l_ui - epicsEpocSecsPastEpochNTP;
this->nSec = static_cast < unsigned long >
( ( ts.l_uf / ULONG_MAX_PLUS_ONE ) * nSecPerSec );
( ( ts.l_uf / NTP_FRACTION DENOMINATOR ) * nSecPerSec );
}
// return pointer to trailing "%0<n>f" (<n> is a number) in a format string,

View File

@@ -78,7 +78,7 @@ int epicsTimeTest (void)
epicsTime tsf = ntp;
const double diff = fabs ( tsf - tsi );
// the difference in the precision of the two time formats
static const double precisionNTP = 1.0 / ( 1.0 + UINT_MAX );
static const double precisionNTP = 1.0 / ( 1.0 + 0xffffffff );
static const double precisionEPICS = 1.0 / nSecPerSec;
assert ( diff <= precisionEPICS + precisionNTP );
}