Skip to content

Commit

Permalink
Fix printing of complex coefficients in expressions (#3112)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 24, 2022
1 parent 5b88b2b commit bcb803e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function _is_one_for_printing(coef)
return _is_zero_for_printing(abs(coef) - oneunit(coef))
end

function _is_one_for_printing(coef::Complex)
return _is_one_for_printing(real(coef)) && _is_zero_for_printing(imag(coef))
end
_is_one_for_printing(coef::Complex{T}) where {T} = coef == one(T)

function _is_zero_for_printing(coef::Complex)
return _is_zero_for_printing(real(coef)) &&
Expand Down
8 changes: 8 additions & 0 deletions test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,14 @@ function test_show_latex_parameter()
return
end

function test_minus_one_complex_aff_expr()
model = Model()
@variable(model, x)
f = 1.0im * x + 1.0im
@test sprint(show, im * f) == "(-1.0 + 0.0im) x + (-1.0 + 0.0im)"
return
end

end

TestPrint.runtests()

0 comments on commit bcb803e

Please sign in to comment.