lfpinit() signed or unsigned?

Achim Gratz Stromeko at nexgo.de
Sat Mar 11 16:24:42 UTC 2017


Eric S. Raymond writes:
> This is all correct.  I have revised the comment as follows:
>
>  * NTP uses two fixed point formats.
>  *
>  * The first (l_fp) is the "long" format and is 64 bits wide in units
>  * of 1/2e32 seconds (which is between 232 and 233 decimal

Nitpick: it's really 2^32 or 2**32, not 2e32==2.0*10^32

It'd be worth pointing to https://www.eecis.udel.edu/~mills/y2k.html or
the equivalent discussion in the NTPsec documentation (if it exists) in
order to understand that the l_fp is a symmetrical truncation about the
(implied) decimal point of an NTP date to a NTP timestamp.

>  * When it is convenient to compute in float seconds, this type can
>  * be interpreted as a fixed-point float with the radix point between

Drop "float", it's a fixed-point number.  The exponent is implied, not
part of the number format like a proper float.

BTW, the blurb attributed to Don Payette in the NTP FAQ 5.1.2.3
(http://www.ntp.org/ntpfaq/NTP-s-algo.htm) is wrong in at least two
ways.  I see where he was going with that explanation, but devoid of the
context that must have existed it might just give someone the wrong
ideas.  One, a double has quite a bit less than 64bit of mantissa,
seeing that it usually has only 64bits available in total.  Two, you
can't just stick a fixed point number into a float or into the mantissa.
For all halfway common FP formats still in use the mantissa is
_fractional_, so if you stuck the fixed point 64bits in there (or
whaetever of it fit), you'd have to multiply by 2^32 to get the correct
number (assuming the exponent was initially interpreted as zero).
However in nearly all FP formats the mantissa is also assumed to be
normalized (the leading bit is always a "1") and then that hidden bit is
left out in the stored bit pattern.  So you'd also need to properly tag
all values that don't have the MSB set as denormals.

>  * Internally, this type is sometimes used for time offsets.  In that 
>  * context it is interpreted as signed and can only express offsets
>  * up to a half cycle. Offsets are normally much, much smaller than that;
>  * for an offset to have a value even as large as 1 second would be 
>  * highly unusual.

Maybe change "cycle" to "NTP era"?  I'm not sure "NTP era" is (also)
used as a time interval yet, but if not we'd need to define a proper
term for it.  What is mentioned in the NTP FAQ referenced above as NTP
epoch should better be called "NTP era 0" to make it clear that it's
cyclical.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

DIY Stuff:
http://Synth.Stromeko.net/DIY.html



More information about the devel mailing list