Skip to content

Commit ab1f3f5

Browse files
committed
fix neg float cmp
1 parent b717580 commit ab1f3f5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/tools.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Tools
22

3-
export kw_qreg, kw_creg, kw_gate, qasm_id, qasm_int, qasm_f64, qasm_str, cmp_ast
3+
export kw_qreg, kw_creg, kw_gate, qasm_id, qasm_int, qasm_f64, qasm_str, cmp_ast, cmp_exp
44

55
using ..Types
66
using MLStyle
@@ -62,7 +62,15 @@ function cmp_exp(lhs::Tuple, rhs::Tuple)
6262
return all(map(cmp_ast, lhs, rhs))
6363
end
6464

65-
cmp_exp(lhs, rhs) = cmp_ast(lhs, rhs)
65+
function cmp_exp(lhs, rhs)
66+
@switch (lhs, rhs) begin
67+
@case (Neg(a::Token{:float64}), b::Token{:float64})
68+
startswith(b.str, '-') && a.str == b.str[2:end]
69+
@case _
70+
cmp_ast(lhs, rhs)
71+
end
72+
end
73+
6674
cmp_ast(lhs, rhs) = lhs == rhs
6775

6876
@deprecate issimilar(x, y) cmp_ast(x, y)

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ using MLStyle
55
using RBNF: Token
66
using Test
77

8+
@testset "cmp_exp" begin
9+
@test cmp_exp(Neg(qasm_f64(0.2)), qasm_f64(-0.2))
10+
end
11+
812
@testset "conversion" begin
913
@test convert(String, Token{:str}("\"abc\"")) == "abc"
1014
@test convert(Symbol, Token{:id}("abc")) === :abc

0 commit comments

Comments
 (0)