Skip to content

Commit 63b91a4

Browse files
committed
Fix wrong complex repr() for -0.0
Test: assert repr(complex('-0.0')) == '(-0+0j)'
1 parent b7b05b3 commit 63b91a4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Lib/test/test_complex.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,6 @@ def test(v, expected, test_fn=self.assertEqual):
578578
self.assertEqual(-6j,complex(repr(-6j)))
579579
self.assertEqual(6j,complex(repr(6j)))
580580

581-
# TODO: RUSTPYTHON
582-
@unittest.expectedFailure
583581
@support.requires_IEEE_754
584582
def test_negative_zero_repr_str(self):
585583
def test(v, expected, test_fn=self.assertEqual):
@@ -636,8 +634,6 @@ def test_overflow(self):
636634
self.assertEqual(complex("-1e500j"), complex(0.0, -INF))
637635
self.assertEqual(complex("-1e500+1.8e308j"), complex(-INF, INF))
638636

639-
# TODO: RUSTPYTHON
640-
@unittest.expectedFailure
641637
@support.requires_IEEE_754
642638
def test_repr_roundtrip(self):
643639
vals = [0.0, 1e-500, 1e-315, 1e-200, 0.0123, 3.1415, 1e50, INF, NAN]

vm/src/builtins/complex.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,13 @@ impl PyComplex {
322322
};
323323
im_part.push('j');
324324

325-
// empty => return im_part, integer => drop ., fractional => float_ops
325+
// positive empty => return im_part, integer => drop ., fractional => float_ops
326326
let re_part = if re == 0.0 {
327-
return im_part;
327+
if re.is_sign_positive() {
328+
return im_part;
329+
} else {
330+
re.to_string()
331+
}
328332
} else if re.fract() == 0.0 {
329333
re.to_string()
330334
} else {

0 commit comments

Comments
 (0)