Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,19 @@ def test_no_extra_minus_sign() -> None:
assert doc.as_string() == "a = -1.5"


def test_no_extra_plus_sign_on_negative_zero() -> None:
doc = parse("a = -1.5")
doc["a"] *= 0
assert doc.as_string() == "a = -0.0"
doc["a"] *= -1
assert doc.as_string() == "a = +0.0"

# Integer true division also goes through Float._new.
doc = parse("a = +0")
doc["a"] /= -1
assert doc.as_string() == "a = -0.0"


def test_serialize_table_with_dotted_key() -> None:
child = api.table()
child.add(api.key(("b", "c")), 1)
Expand Down
3 changes: 2 additions & 1 deletion tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,8 @@ def as_string(self) -> str:
def _new(self, result: float) -> Float:
raw = str(result)

if self._sign and result >= 0:
# -0.0 >= 0 is True, but str(-0.0) already carries its sign.
if self._sign and result >= 0 and not raw.startswith("-"):
raw = f"+{raw}"

return Float(result, self._trivia, raw)
Expand Down
Loading