Skip to content

Commit

Permalink
fix neg float cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Apr 30, 2021
1 parent b717580 commit ab1f3f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/tools.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Tools

export kw_qreg, kw_creg, kw_gate, qasm_id, qasm_int, qasm_f64, qasm_str, cmp_ast
export kw_qreg, kw_creg, kw_gate, qasm_id, qasm_int, qasm_f64, qasm_str, cmp_ast, cmp_exp

using ..Types
using MLStyle
Expand Down Expand Up @@ -62,7 +62,15 @@ function cmp_exp(lhs::Tuple, rhs::Tuple)
return all(map(cmp_ast, lhs, rhs))
end

cmp_exp(lhs, rhs) = cmp_ast(lhs, rhs)
function cmp_exp(lhs, rhs)
@switch (lhs, rhs) begin
@case (Neg(a::Token{:float64}), b::Token{:float64})
startswith(b.str, '-') && a.str == b.str[2:end]
@case _
cmp_ast(lhs, rhs)
end
end

cmp_ast(lhs, rhs) = lhs == rhs

@deprecate issimilar(x, y) cmp_ast(x, y)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ using MLStyle
using RBNF: Token
using Test

@testset "cmp_exp" begin
@test cmp_exp(Neg(qasm_f64(0.2)), qasm_f64(-0.2))
end

@testset "conversion" begin
@test convert(String, Token{:str}("\"abc\"")) == "abc"
@test convert(Symbol, Token{:id}("abc")) === :abc
Expand Down

0 comments on commit ab1f3f5

Please sign in to comment.