[Git][NTPsec/ntpsec][master] Correct precision computation in pyntpdig.
Eric S. Raymond
gitlab at mg.gitlab.com
Wed Dec 7 19:02:18 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
9a9a756d by Eric S. Raymond at 2016-12-07T14:02:04-05:00
Correct precision computation in pyntpdig.
- - - - -
1 changed file:
- ntpdig/pyntpdig
Changes:
=====================================
ntpdig/pyntpdig
=====================================
--- a/ntpdig/pyntpdig
+++ b/ntpdig/pyntpdig
@@ -38,7 +38,7 @@ from __future__ import print_function, division
#
# The one new option in this version is -p, borrowed from ntpdate.
-import sys, socket, select, struct, time, getopt, datetime
+import sys, socket, select, struct, time, getopt, datetime, math
try:
import ntp.packet
@@ -192,15 +192,8 @@ def report(packet, json):
t = time.localtime(int(packet.transmit_timestamp))
ms = int(packet.transmit_timestamp * 1000000) % 1000000
- digits = 6
- #precision = packet.precision
- #while True:
- # precision *= 10.0
- # if precision >= 1:
- # break
- # digits += 1
- #if digits > 6:
- # digits = 6;
+ # Number of decimal digits of precision indicated by the precision field
+ digits = min(6, -int(math.log10(2**packet.precision)))
date = time.strftime("%Y-%m-%d", t)
tod = time.strftime("%T", t) + (".%*d" % (digits, ms))
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9a9a756dff03442bd8e8f1daf68da0f38661bf81
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161207/5c1b07dc/attachment.html>
More information about the vc
mailing list