Skip to content

Commit 8a6a64e

Browse files
authored
fix bug printing complex leading terms with negative real part (#428)
* fix bug printing complex leading terms with negative real part * fix docs too
1 parent 76f3c9e commit 8a6a64e

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "3.1.4"
5+
version = "3.1.5"
66

77
[deps]
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/polynomials/LaurentPolynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ julia> z = variable(LaurentPolynomial, :z)
284284
LaurentPolynomial(1.0*z)
285285
286286
julia> p = LaurentPolynomial([im, 1+im, 2 + im], -1, :z)
287-
LaurentPolynomial(im*z⁻¹ + 1 + im + (2 + im)z)
287+
LaurentPolynomial(im*z⁻¹ + (1 + im) + (2 + im)z)
288288
289289
julia> conj(p)(conj(z)) ≈ conj(p(z))
290290
true

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function printcoefficient(io::IO, pj::S, j, mimetype) where {T,S <: Complex{T}}
255255
hasimag = !iszero(b) || isnan(b) || isinf(b)
256256

257257
if hasreal && hasimag
258-
iszero(j) || print(io, "(")
258+
print(io, "(")
259259
print(io, a)
260260

261261
# print b
@@ -277,7 +277,7 @@ function printcoefficient(io::IO, pj::S, j, mimetype) where {T,S <: Complex{T}}
277277
end
278278

279279
print(io, imagsymbol(mimetype))
280-
iszero(j) || print(io, ")")
280+
print(io, ")")
281281

282282
elseif hasreal
283283

test/Poly.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ p = Poly([1.0, 2.0, 3.0, 1.0])
295295
p = Poly([1, im])
296296
@test repr(p) == "$Poly(1 + im*x)"
297297
p = Poly([1+im, 1-im, -1+im, -1 - im])# minus signs
298-
@test repr(p) == "$Poly(1 + im + (1 - im)x - (1 - im)x^2 - (1 + im)x^3)"
298+
@test repr(p) == "$Poly((1 + im) + (1 - im)x - (1 - im)x^2 - (1 + im)x^3)"
299299
p = Poly([1.0, 0 + NaN*im, NaN, Inf, 0 - Inf*im]) # handle NaN or Inf appropriately
300300
@test repr(p) == "$Poly(1.0 + NaN*im*x + NaN*x^2 + Inf*x^3 - Inf*im*x^4)"
301301

@@ -304,7 +304,7 @@ p = Poly([1,2,3])
304304
p = Poly([1//2, 2//3, 1])
305305
@test repr("text/latex", p) == "\$\\frac{1}{2} + \\frac{2}{3}\\cdot x + x^{2}\$"
306306
p = Poly([complex(1,1),complex(0,1),complex(1,0),complex(1,1)])
307-
@test repr("text/latex", p) == "\$1 + i + i\\cdot x + x^{2} + (1 + i)x^{3}\$"
307+
@test repr("text/latex", p) == "\$(1 + i) + i\\cdot x + x^{2} + (1 + i)x^{3}\$"
308308

309309
# customized printing with printpoly
310310
function printpoly_to_string(args...; kwargs...)

test/StandardBasis.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ end
13921392
@test sprint(show, p) == "$P(1.0 + 2.0*x + 3.0*x^2)"
13931393

13941394
p = P([1 + 1im, -2im])
1395-
@test sprint(show, p) == "$P(1 + im - 2im*x)"
1395+
@test sprint(show, p) == "$P((1 + im) - 2im*x)"
13961396

13971397

13981398
p = P([1,2,3,1]) # leading coefficient of 1
@@ -1402,7 +1402,7 @@ end
14021402
p = P([1, im])
14031403
@test repr(p) == "$P(1 + im*x)"
14041404
p = P([1 + im, 1 - im, -1 + im, -1 - im])# minus signs
1405-
@test repr(p) == "$P(1 + im + (1 - im)x - (1 - im)x^2 - (1 + im)x^3)"
1405+
@test repr(p) == "$P((1 + im) + (1 - im)x - (1 - im)x^2 - (1 + im)x^3)"
14061406
p = P([1.0, 0 + NaN * im, NaN, Inf, 0 - Inf * im]) # handle NaN or Inf appropriately
14071407
@test repr(p) == "$P(1.0 + NaN*im*x + NaN*x^2 + Inf*x^3 - Inf*im*x^4)"
14081408

@@ -1412,13 +1412,13 @@ end
14121412
p = P([1 // 2, 2 // 3, 1])
14131413
@test repr("text/latex", p) == "\$\\frac{1}{2} + \\frac{2}{3}\\cdot x + x^{2}\$"
14141414
p = P([complex(1,1),complex(0,1),complex(1,0),complex(1,1)])
1415-
@test repr("text/latex", p) == "\$1 + i + i\\cdot x + x^{2} + (1 + i)x^{3}\$"
1415+
@test repr("text/latex", p) == "\$(1 + i) + i\\cdot x + x^{2} + (1 + i)x^{3}\$"
14161416

14171417
@test printpoly_to_string(P([1,2,3], "y")) == "1 + 2*y + 3*y^2"
14181418
@test printpoly_to_string(P([1,2,3], "y"), descending_powers = true) == "3*y^2 + 2*y + 1"
14191419
@test printpoly_to_string(P([2, 3, 1], :z), descending_powers = true, offset = -2) == "1 + 3*z^-1 + 2*z^-2"
14201420
@test printpoly_to_string(P([-1, 0, 1], :z), offset = -1, descending_powers = true) == "z - z^-1"
1421-
@test printpoly_to_string(P([complex(1,1),complex(1,-1)]),MIME"text/latex"()) == "1 + i + (1 - i)x"
1421+
@test printpoly_to_string(P([complex(1,1),complex(1,-1)]),MIME"text/latex"()) == "(1 + i) + (1 - i)x"
14221422
end
14231423

14241424
## closed issues
@@ -1428,7 +1428,7 @@ end
14281428
io=IOBuffer(); printpoly(io, p, compact=true, mulsymbol=""); @test String(take!(io)) == "1.23457 + 2.34568x"
14291429

14301430
## issue 278 with complex
1431-
@test printpoly_to_string(Polynomial([1 + im, 1, 2, im, 2im, 1+im, 1-im])) == "1 + im + x + 2*x^2 + im*x^3 + 2im*x^4 + (1 + im)x^5 + (1 - im)x^6"
1431+
@test printpoly_to_string(Polynomial([1 + im, 1, 2, im, 2im, 1+im, 1-im])) == "(1 + im) + x + 2*x^2 + im*x^3 + 2im*x^4 + (1 + im)x^5 + (1 - im)x^6"
14321432

14331433
## issue #320 (fix was broken)
14341434
@test printpoly_to_string(Polynomial(BigInt[1,0,1], :y)) == "1 + y^2"

0 commit comments

Comments
 (0)