diff --git a/src/show.jl b/src/show.jl index b722689b..e23e2194 100644 --- a/src/show.jl +++ b/src/show.jl @@ -21,6 +21,8 @@ function show(io::IO, m::AbstractMonomial) end end +should_print_coefficient(x) = true # By default, just print all coefficients +should_print_coefficient(x::Number) = !isone(x) # For numbers, we omit any "one" coefficients print_coefficient(io::IO, coeff::Real) = print(io, coeff) print_coefficient(io::IO, coeff) = print(io, "(", coeff, ")") @@ -28,8 +30,8 @@ function Base.show(io::IO, t::AbstractTerm) if isconstant(t) print_coefficient(io, coefficient(t)) else - if !isone(coefficient(t)) - if isone(-coefficient(t)) + if should_print_coefficient(coefficient(t)) + if !should_print_coefficient(-coefficient(t)) print(io, '-') else print_coefficient(io, coefficient(t)) diff --git a/test/show.jl b/test/show.jl index 163ebdb4..e6f092e3 100644 --- a/test/show.jl +++ b/test/show.jl @@ -24,4 +24,5 @@ @test sprint(show, -(1.0 + 3.1im) * z*x) == "(-1.0 - 3.1im)xz" @test sprint(show, x^2 + (1.0 + 3.1im) * x) == "x^2 + (1.0 + 3.1im)x" @test sprint(show, x^2 - (1.0 + 3.1im) * x) == "x^2 + (-1.0 - 3.1im)x" + @test sprint(show, [1.0, 2.0] * x) == "([1.0, 2.0])x" end