Skip to content

Commit 54c4689

Browse files
authored
Merge pull request #715 from AayushSabharwal/as/hashconsing-number-equality
fix: ensure numbers have the same type in `isequal_with_metadata`
2 parents 81e0c48 + ffc06db commit 54c4689

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/types.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ function isequal_with_metadata(a::Union{AbstractArray, Tuple}, b::Union{Abstract
406406
return true
407407
end
408408

409+
isequal_with_metadata(a::Number, b::Number) = typeof(a) == typeof(b) && isequal(a, b)
410+
409411
Base.one( s::Symbolic) = one( symtype(s))
410412
Base.zero(s::Symbolic) = zero(symtype(s))
411413

test/hash_consing.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,17 @@ Base.isequal(a::MySymbolic, b::MySymbolic) = isequal(a.sym, b.sym)
188188
@test isequal(myt, mytt)
189189
@test !isequal_with_metadata(myt, mytt)
190190
end
191+
192+
@testset "`isequal_with_metadata` ensures numbers have the same type" begin
193+
@syms x
194+
tmp1 = x ^ 3.0
195+
tmp2 = x ^ 3
196+
@test !SymbolicUtils.isequal_with_metadata(tmp1, tmp2)
197+
@test arguments(tmp1)[2] isa Float64
198+
@test arguments(tmp2)[2] isa Int
199+
tmp1 = 2tmp1
200+
tmp2 = 2tmp2
201+
@test !SymbolicUtils.isequal_with_metadata(tmp1, tmp2)
202+
@test arguments(arguments(tmp1)[2])[2] isa Float64
203+
@test arguments(arguments(tmp2)[2])[2] isa Int
204+
end

0 commit comments

Comments
 (0)