Skip to content

Commit bcb803e

Browse files
authored
Fix printing of complex coefficients in expressions (#3112)
1 parent 5b88b2b commit bcb803e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/print.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ function _is_one_for_printing(coef)
5151
return _is_zero_for_printing(abs(coef) - oneunit(coef))
5252
end
5353

54-
function _is_one_for_printing(coef::Complex)
55-
return _is_one_for_printing(real(coef)) && _is_zero_for_printing(imag(coef))
56-
end
54+
_is_one_for_printing(coef::Complex{T}) where {T} = coef == one(T)
5755

5856
function _is_zero_for_printing(coef::Complex)
5957
return _is_zero_for_printing(real(coef)) &&

test/print.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,14 @@ function test_show_latex_parameter()
965965
return
966966
end
967967

968+
function test_minus_one_complex_aff_expr()
969+
model = Model()
970+
@variable(model, x)
971+
f = 1.0im * x + 1.0im
972+
@test sprint(show, im * f) == "(-1.0 + 0.0im) x + (-1.0 + 0.0im)"
973+
return
974+
end
975+
968976
end
969977

970978
TestPrint.runtests()

0 commit comments

Comments
 (0)