Skip to content

Commit 783fa05

Browse files
authored
Merge pull request #83 from Keno/fixprint
Fix printing error #82 for polys with complex coefficients
2 parents 9a1a8f1 + 3c03a4c commit 783fa05

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function printproductsign{T}(io::IO, pj::T, j, mimetype)
113113
end
114114

115115
function printcoefficient{T}(io::IO, pj::Complex{T}, j, mimetype)
116-
116+
117117
hasreal = abs(real(pj)) > 0
118118
hasimag = abs(imag(pj)) > 0
119119

@@ -123,7 +123,7 @@ function printcoefficient{T}(io::IO, pj::Complex{T}, j, mimetype)
123123
print(io, ')')
124124
elseif hasreal
125125
a = real(pj)
126-
(showone(T) || a != one(T)) && show(io, mimetype, a)
126+
(j==0 || showone(T) || a != one(T)) && show(io, mimetype, a)
127127
elseif hasimag
128128
b = imag(pj)
129129
(showone(T) || b != one(T)) && show(io, mimetype, b)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ p = Poly([1,2,3,1]) # leading coefficient of 1
226226
@test repr(p) == "Poly(1 + 2⋅x + 3⋅x^2 + x^3)"
227227
p = Poly([1.0, 2.0, 3.0, 1.0])
228228
@test repr(p) == "Poly(1.0 + 2.0⋅x + 3.0⋅x^2 + 1.0⋅x^3)"
229+
p = Poly([1, im])
230+
@test repr(p) == "Poly(1 + im⋅x)"
229231
p = Poly([1+im, 1-im, -1+im, -1 - im])# minus signs
230232
@test repr(p) == "Poly((1 + 1im) + (1 - 1im)⋅x - (1 - 1im)⋅x^2 - (1 + 1im)⋅x^3)"
231233

0 commit comments

Comments
 (0)