[Git][NTPsec/ntpsec][master] 2 commits: f8dot4() now supports Nan, and fewer returns.

Gary E. Miller gitlab at mg.gitlab.com
Tue Aug 8 04:48:29 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
2777ef24 by Gary E. Miller at 2017-08-07T21:47:54-07:00
f8dot4() now supports Nan, and fewer returns.

pyflakes complained about too many returns.

- - - - -
67811eab by Gary E. Miller at 2017-08-07T21:47:54-07:00
Fix sometimes not-initialized estdisp

- - - - -


1 changed file:

- pylib/util.py


Changes:

=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -5,13 +5,13 @@
 from __future__ import print_function
 
 
-import socket
-import sys
-import time
+import collections
 import os
 import re
 import shutil
-import collections
+import socket
+import sys
+import time
 
 import ntp.ntpc
 import ntp.version
@@ -378,26 +378,33 @@ def unitify(value, startingunit, baseunit=None, width=8):
 
 def f8dot4(f):
     "Scaled floating point formatting to fit in 8 characters"
+
+    if str(float(f)).lower() == 'nan':
+        # yes, this is a better test than math.isnan()
+        return "     nan"
+
+    fmt = "%8d"          # xxxxxxxx
     if f >= 0:
         if f < 1000.0:
-            return "%8.4f" % f    # xxx.xxxx  normal case
+            fmt = "%8.4f"    # xxx.xxxx  normal case
         elif f < 10000.0:
-            return "%8.3f" % f    # xxxx.xxx
+            fmt = "%8.3f"    # xxxx.xxx
         elif f < 100000.0:
-            return "%8.2f" % f    # xxxxx.xx
+            fmt = "%8.2f"    # xxxxx.xx
         elif f < 1000000.0:
-            return "%8.1f" % f    # xxxxxx.x
-        return "%8d" % f          # xxxxxxxx
+            fmt = "%8.1f"    # xxxxxx.x
+    else:
+        # f < 0
+        if f > -100.0:
+            fmt = "%8.4f"      # -xx.xxxx  normal case
+        elif f > -1000.0:
+            fmt = "%8.3f"      # -xxx.xxx
+        elif f > -10000.0:
+            fmt = "%8.2f"      # -xxxx.xx
+        elif f > -100000.0:
+            fmt = "%8.1f"      # -xxxxx.x
 
-    if f > -100.0:
-        return "%8.4f" % f      # -xx.xxxx  normal case
-    elif f > -1000.0:
-        return "%8.3f" % f      # -xxx.xxx
-    elif f > -10000.0:
-        return "%8.2f" % f      # -xxxx.xx
-    elif f > -100000.0:
-        return "%8.1f" % f      # -xxxxx.x
-    return "%8d" % f            # -xxxxxxx
+    return fmt % f
 
 
 def f8dot3(f):
@@ -725,6 +732,7 @@ class PeerSummary:
 
     def summary(self, rstatus, variables, associd):
         "Peer status summary line."
+        estdisp = float('NaN')
         hmode = 0
         srchost = None
         srcport = 0



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/910d05617f38bce8729c871bd08f3e390dc574ed...67811eab3375b82636d7c0b9ae61f8d46354a502

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/910d05617f38bce8729c871bd08f3e390dc574ed...67811eab3375b82636d7c0b9ae61f8d46354a502
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170808/7a67e93c/attachment.html>


More information about the vc mailing list