Skip to content

Commit 9e85a60

Browse files
authored
Merge pull request #264 from JuliaSymbolics/s/powprint
Fix printing of `^` with negative base
2 parents 5426f7d + 7d5728d commit 9e85a60

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/types.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,13 @@ end
469469
function show_pow(io, args)
470470
base, ex = args
471471

472-
print_arg(io, base, paren=true)
472+
if base isa Real && base < 0
473+
print(io, "(")
474+
print_arg(io, base)
475+
print(io, ")")
476+
else
477+
print_arg(io, base, paren=true)
478+
end
473479
print(io, "^")
474480
print_arg(io, ex, paren=true)
475481
end

test/basics.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ end
153153
@test repr((a + b) - (b + c)) == "a - c"
154154
@test repr(a + -1*(b + c)) == "a - b - c"
155155
@test repr(a + -1*b) == "a - b"
156+
@test repr(-1^a) == "-(1^a)"
157+
@test repr((-1)^a) == "(-1)^a"
156158
end
157159

158160
@testset "similarterm with Add" begin

0 commit comments

Comments
 (0)