Skip to content

Commit

Permalink
Improve display of coefficients
Browse files Browse the repository at this point in the history
  • Loading branch information
jagot committed Nov 27, 2023
1 parent 553f6a4 commit 232504c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/show_coefficients.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
function showcoeff(io::IO, n::Number, show_sign::Bool, show_one::Bool=false)
isimag(n) = !iszero(n) && isreal(im*n)
isneg(n) = n < 0
const RealOrComplex{T<:Real} = Union{T,Complex{T}}

isimag(::Real) = false
isimag(n) = !iszero(n) && !isreal(n) && isreal(1im*n)
isneg(n::Real) = n < 0

function showcoeff(io::IO, n::Number, show_sign::Bool, show_one::Bool=false)
if isreal(n) && isneg(real(n)) || isimag(n) && isneg(imag(n))
write(io, "- ")
else
show_sign && write(io, "+ ")
end
n = round(n, digits=6)
printable(n::RealOrComplex{<:AbstractFloat}) = round(n, digits=6)
printable(n) = n
n = printable(n)
if !(isone(n) || isone(-n))
if !(isreal(n) || isimag(n))
write(io, "($n)")
Expand Down

0 comments on commit 232504c

Please sign in to comment.