Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
NTPsec
ntpsec
Commits
75c50a7c
Commit
75c50a7c
authored
Aug 08, 2017
by
Gary E. Miller
💬
Browse files
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pylib/util.py
View file @
75c50a7c
...
...
@@ -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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment