Skip to content

Commit

Permalink
Turn negative zero into positive zero in pdg_format (#916)
Browse files Browse the repository at this point in the history
Closes #840 (hopefully)

Negative "-0" is turned into "0" by pdg_format.
  • Loading branch information
HDembinski authored Jul 26, 2023
1 parent 12cff32 commit 4f4ec17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/iminuit/pdg_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def _strip(items: List[str]) -> List[str]:
if i > 0:
for k in mask:
items[k] = items[k][:-i]
# turn negative zero into positive zero
if items[0] == "-0":
items[0] = "0"
return items


Expand Down
2 changes: 2 additions & 0 deletions tests/test_pdg_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def test_strip():
assert _strip(["0.11", "0.20"]) == ["0.11", "0.20"]
assert _strip(["10.0", "20.0"]) == ["10", "20"]
assert _strip(["1.200", "3.40"]) == ["1.20", "3.4"]
assert _strip(["0.000", "0.000"]) == ["0", "0"]
assert _strip(["-0.00", "0.00"]) == ["0", "0"]


def test_term_format():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_matrix():
== """
x y
-- --- ---
x 1 -0
y -0 4
x 1 0
y 0 4
"""
)

0 comments on commit 4f4ec17

Please sign in to comment.