Commit 75c50a7c by Gary E. Miller 💬

### Make f8dot3() not crash on bad input.

`f8dot3() expect a float, but sometimes gets other things...`
parent 8f408587
Pipeline #10707981 passed with stages
in 8 minutes and 59 seconds
 ... ... @@ -389,6 +389,7 @@ def f8dot4(f): if str(float(f)).lower() == 'nan': # yes, this is a better test than math.isnan() # it also catches None, strings, etc. return " nan" fmt = "%8d" # xxxxxxxx ... ... @@ -402,7 +403,7 @@ def f8dot4(f): elif f < 1000000.0: fmt = "%8.1f" # xxxxxx.x else: # f < 0 # negative number, account for minus sign if f > -100.0: fmt = "%8.4f" # -xx.xxxx normal case elif f > -1000.0: ... ... @@ -417,22 +418,29 @@ def f8dot4(f): def f8dot3(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() # it also catches None, strings, etc. return " nan" fmt = "%8d" % f # xxxxxxxx or -xxxxxxx if f >= 0: if f < 10000.0: return "%8.3f" % f # xxxx.xxx normal case fmt = "%8.3f" # xxxx.xxx normal case 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 if f > -1000.0: return "%8.3f" % f # -xxx.xxx normal case elif f > -10000.0: return "%8.2f" % f # -xxxx.xx elif f > -100000.0: return "%8.1f" % f # -xxxxx.x return "%8d" % f # -xxxxxxx fmt = "%8.1f" # xxxxxx.x else: # negative number, account for minus sign if f > -1000.0: fmt = "%8.3f" # -xxx.xxx normal case elif f > -10000.0: fmt = "%8.2f" # -xxxx.xx elif f > -100000.0: fmt = "%8.1f" # -xxxxx.x return fmt % f # A hack to avoid repeatedly hammering on DNS when ntpmon runs. ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!