From 683a7625acd24bb97385e396df69b942de998666 Mon Sep 17 00:00:00 2001 From: Brandon Flores Date: Wed, 11 Sep 2024 17:58:48 -0500 Subject: [PATCH] Simplified definition for `==` and added `isequal` deifnition --- src/CliffordNumbers.jl | 2 +- src/math/arithmetic.jl | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/CliffordNumbers.jl b/src/CliffordNumbers.jl index a7933de..f06495b 100644 --- a/src/CliffordNumbers.jl +++ b/src/CliffordNumbers.jl @@ -4,7 +4,7 @@ import Base: length, size, axes, getindex, to_index import Base: zero, one, oneunit import Base: signbit, sign import Base: reverse, adjoint, conj, ~ -import Base: ==, isapprox, +, -, *, /, //, muladd, abs, abs2, exp, ^ +import Base: ==, isequal, isapprox, +, -, *, /, //, muladd, abs, abs2, exp, ^ import Base: promote_rule, convert, similar, float, big import Base: summary, show diff --git a/src/math/arithmetic.jl b/src/math/arithmetic.jl index 03f9630..dd6d0e5 100644 --- a/src/math/arithmetic.jl +++ b/src/math/arithmetic.jl @@ -1,10 +1,9 @@ #---Equality and approximate equality--------------------------------------------------------------# -function ==(x::AbstractCliffordNumber{Q}, y::AbstractCliffordNumber{Q}) where Q - return all(x[i] == y[i] for i in BitIndices(promote_type(typeof(x), typeof(y)))) -end +==(x::T, y::T) where T<:AbstractCliffordNumber = Tuple(x) == Tuple(y) +isequal(x::T, y::T) where T<:AbstractCliffordNumber = isequal(Tuple(x), Tuple(y)) -# Define equality with scalar values in terms of scalar operations above +# TODO: does this avoid unnecessary comparisons or construction? ==(x::AbstractCliffordNumber, y::BaseNumber) = isscalar(x) && (scalar(x) == y) ==(x::BaseNumber, y::AbstractCliffordNumber) = isscalar(y) && (x == scalar(y))