Skip to content

Commit 8a7cb87

Browse files
committed
Make Symbolics work with Rational numbers
1 parent 30c92ef commit 8a7cb87

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/SymbolicUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export @syms, term, showraw, hasmetadata, getmetadata, setmetadata
77
using DataStructures
88
using Setfield
99
import Setfield: PropertyLens
10-
import Base: +, -, *, /, \, ^, ImmutableDict
10+
import Base: +, -, *, /, //, \, ^, ImmutableDict
1111
using ConstructionBase
1212
include("types.jl")
1313

src/types.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ mul_t(a) = promote_symtype(*, symtype(a))
781781

782782
/(a::SN, b::Number) = inv(b) * a
783783

784+
//(a::Union{SN, Number}, b::SN) = a / b
785+
786+
//(a::SN, b::T) where {T <: Number} = (one(T) // b) * a
787+
784788
"""
785789
Pow(base, exp)
786790

test/basics.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ end
112112
@test SymbolicUtils.promote_symtype(ifelse, Bool, Int, Bool) == Union{Int, Bool}
113113
@test_throws MethodError w < 0
114114
@test isequal(w == 0, Term{Bool}(==, [w, 0]))
115+
116+
@eqtest x // 5 == (1 // 5) * x
117+
@eqtest x // Int16(5) == Rational{Int16}(1, 5) * x
118+
@eqtest 5 // x == 5 / x
119+
@eqtest x // a == x / a
115120
end
116121

117122
@testset "err test" begin

0 commit comments

Comments
 (0)