Skip to content

Commit b451eaf

Browse files
committed
make show copy and pastable
1 parent 9b2c873 commit b451eaf

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Polynomials.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ one{T}(::Type{Poly{T}}) = Poly([one(T)])
228228
## Overload arithmetic operators for polynomial operations between polynomials and scalars
229229
*{T<:Number,S}(c::T, p::Poly{S}) = Poly(c * p.a, p.var)
230230
*{T<:Number,S}(p::Poly{S}, c::T) = Poly(p.a * c, p.var)
231+
Base.dot{T<:Number,S}(p::Poly{S}, c::T) = p * c
232+
Base.dot{T<:Number,S}(c::T, p::Poly{S}) = c * p
231233
.*{T<:Number,S}(c::T, p::Poly{S}) = Poly(c * p.a, p.var)
232234
.*{T<:Number,S}(p::Poly{S}, c::T) = Poly(p.a * c, p.var)
233235
/(p::Poly, c::Number) = Poly(p.a / c, p.var)

src/show.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function printterm{T}(io::IO,p::Poly{T},j,first)
2828
pj = abs(pj)
2929
if pj != one(T) || j == 0
3030
show(io,pj)
31+
j != 0 && print(io, "")
3132
end
3233
printexponent(io,p.var,j)
3334
true
@@ -57,15 +58,18 @@ function printterm{T<:Complex}(io::IO,p::Poly{T},j,first)
5758
if abs_repj > 2*eps(T) #Real part is not 0
5859
if abs_impj > 2*eps(T) #Imag part is not 0
5960
print(io,'(',neg ? -pj : pj,')')
61+
abs(pj) != 1 && j != 0 && print(io, "")
6062
else
6163
print(io, neg ? -real(pj) : real(pj))
64+
abs(pj) != 1 && j != 0 && print(io, "")
6265
end
6366
else
6467
if abs_impj > 2*eps(T)
6568
print(io,'(', abs(imag(pj)),"im)")
69+
abs(pj) != 1 && j != 0 && print(io, "")
6670
end
6771
end
68-
printexponent(io,p.var,j)
72+
printexponent(io, p.var,j)
6973
true
7074
end
7175

0 commit comments

Comments
 (0)