Skip to content

Commit

Permalink
implement in terms of Partials
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 12, 2017
1 parent 9a91b37 commit 87947ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
21 changes: 1 addition & 20 deletions src/dual.jl
Expand Up @@ -403,28 +403,9 @@ end
# Pretty Printing #
###################

const _subscripts = ["", "", "", "", "", "", "", "", "", ""]

function Base.show{N}(io::IO, n::Dual{N})
parts, val = partials(n), value(n)
compact = get(io, :compact, false)
show(io, val)
for (i, p) in enumerate(parts)
if signbit(p) && !isnan(p)
p = -p
print(io, compact ? "-" : " - ")
else
print(io, compact ? "+" : " + ")
end
show(io, p)
if !(isa(p, Integer) && !isa(p, Bool) || isa(p, AbstractFloat) && isfinite(p))
print(io, "*")
end
print(io, "ɛ")
if length(parts) > 1
for d in reverse(digits(i))
print(io, _subscripts[d + 1])
end
end
end
show(io, parts, true)
end
28 changes: 27 additions & 1 deletion src/partials.jl
Expand Up @@ -211,4 +211,30 @@ end
# Pretty Printing #
###################

Base.show{N}(io::IO, p::Partials{N}) = print(io, "Partials", p.values)
const _subscripts = ["", "", "", "", "", "", "", "", "", ""]

Base.show(io::IO, ::MIME"text/plain", p::Partials) = show(io, p)

function Base.show{N}(io::IO, parts::Partials{N}, showing_dual = false)
compact = get(io, :compact, false)
for (i, p) in enumerate(parts)
if showing_dual == true || i != 1
if signbit(p) && !isnan(p)
p = -p
print(io, compact ? "-" : " - ")
else
print(io, compact ? "+" : " + ")
end
end
show(io, p)
if !(isa(p, Integer) && !isa(p, Bool) || isa(p, AbstractFloat) && isfinite(p))
print(io, "*")
end
print(io, "ɛ")
if length(parts) > 1
for d in reverse(digits(i))
print(io, _subscripts[d + 1])
end
end
end
end

0 comments on commit 87947ed

Please sign in to comment.