From 4f4ec17654950a46c3b1ad9c975f245c776adfb8 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Wed, 26 Jul 2023 11:30:01 +0200 Subject: [PATCH] Turn negative zero into positive zero in pdg_format (#916) Closes #840 (hopefully) Negative "-0" is turned into "0" by pdg_format. --- src/iminuit/pdg_format.py | 3 +++ tests/test_pdg_format.py | 2 ++ tests/test_tabulate.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/iminuit/pdg_format.py b/src/iminuit/pdg_format.py index 1ea93f74..d805ed2f 100644 --- a/src/iminuit/pdg_format.py +++ b/src/iminuit/pdg_format.py @@ -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 diff --git a/tests/test_pdg_format.py b/tests/test_pdg_format.py index 26e6e8dc..1e510078 100644 --- a/tests/test_pdg_format.py +++ b/tests/test_pdg_format.py @@ -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(): diff --git a/tests/test_tabulate.py b/tests/test_tabulate.py index 7ecd1d8c..42cc4745 100644 --- a/tests/test_tabulate.py +++ b/tests/test_tabulate.py @@ -33,7 +33,7 @@ def test_matrix(): == """ x y -- --- --- -x 1 -0 -y -0 4 +x 1 0 +y 0 4 """ )