Skip to content

Commit 3efca84

Browse files
authored
Merge pull request #585 from JuliaSymbolics/myb/op
Simplify the construction of `x / 1` and `x / -1`
2 parents d68e092 + d2521fe commit 3efca84

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ end
11431143

11441144
\(a::Number, b::SN) = b / a
11451145

1146-
/(a::SN, b::Number) = (b isa Integer ? 1//b : inv(b)) * a
1146+
/(a::SN, b::Number) = (isone(abs(b)) ? b : (b isa Integer ? 1//b : inv(b))) * a
11471147

11481148
//(a::Union{SN, Number}, b::SN) = a / b
11491149

test/basics.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ end
301301
@test (2.5x/3x).num == 2.5
302302
@test (2.5x/3x).den == 3
303303
@test (x/3x) == 1//3
304+
@test isequal(x / 1, x)
305+
@test isequal(x / -1, -x)
304306
end
305307

306308
@testset "LiteralReal" begin

0 commit comments

Comments
 (0)