Skip to content

Commit 4bf317c

Browse files
authored
Merge pull request RustPython#1076 from corona10/complex_repr
Fix complex representation for negative imaginary number case.
2 parents 546c1c0 + b1aa10d commit 4bf317c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

tests/snippets/builtin_complex.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,9 @@
135135
assert_raises(OverflowError, lambda: complex(10 ** 1000, 0), msg)
136136
assert_raises(OverflowError, lambda: complex(0, 10 ** 1000), msg)
137137
assert_raises(OverflowError, lambda: 0j + 10 ** 1000, msg)
138+
139+
# str/repr
140+
assert '(1+1j)' == str(1+1j)
141+
assert '(1-1j)' == str(1-1j)
142+
assert '(1+1j)' == repr(1+1j)
143+
assert '(1-1j)' == repr(1-1j)

vm/src/obj/objcomplex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl PyComplex {
204204
if re == 0.0 {
205205
format!("{}j", im)
206206
} else {
207-
format!("({}+{}j)", re, im)
207+
format!("({}{:+}j)", re, im)
208208
}
209209
}
210210

0 commit comments

Comments
 (0)