mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 15:45:06 -05:00
util: add conversion between intervals and NTP 64-bit format
This will be needed to save PTP correction in NTP timestamp format.
This commit is contained in:
27
util.c
27
util.c
@@ -818,6 +818,33 @@ UTI_DiffNtp64ToDouble(const NTP_int64 *a, const NTP_int64 *b)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
double
|
||||
UTI_Ntp64ToDouble(NTP_int64 *src)
|
||||
{
|
||||
NTP_int64 zero;
|
||||
|
||||
UTI_ZeroNtp64(&zero);
|
||||
return UTI_DiffNtp64ToDouble(src, &zero);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
UTI_DoubleToNtp64(double src, NTP_int64 *dest)
|
||||
{
|
||||
int32_t hi;
|
||||
|
||||
src = CLAMP(INT32_MIN, src, INT32_MAX);
|
||||
hi = round(src);
|
||||
if (hi > src)
|
||||
hi -= 1;
|
||||
|
||||
dest->hi = htonl(hi);
|
||||
dest->lo = htonl((src - hi) * (1.0e9 * NSEC_PER_NTP64));
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* Maximum offset between two sane times */
|
||||
#define MAX_OFFSET 4294967296.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user