Skip to content

Commit

Permalink
Fixed semantics of oneunit for AbstractCliffordNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Feb 28, 2024
1 parent a0d2505 commit 908d84a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ numeric_type(x) = numeric_type(typeof(x))
Base.Tuple(x::AbstractCliffordNumber) = getfield(x, :data)::Tuple

#---Zero multivectors------------------------------------------------------------------------------#
import Base: zero
import Base: zero, oneunit

zero(C::Type{<:AbstractCliffordNumber{Q,T}}) where {Q,T} = C(_ -> ntuple(zero(T), Val(length(C))))
zero(C::Type{<:AbstractCliffordNumber}) = C(ntuple(_ -> zero(Bool), Val(length(C))))
zero(x::AbstractCliffordNumber) = zero(typeof(x))

# The default defintion assumes oneunit(T) = T(one(x))
# But this doesn't work here, because T(one(x)) doesn't do any error checking
# Only the explicit conversion does the error checking
oneunit(::Union{T,Type{T}}) where T<:AbstractCliffordNumber = convert(T, one(T))

#---Construct similar types------------------------------------------------------------------------#
import Base.similar

Expand Down
1 change: 0 additions & 1 deletion src/kvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ end

#---Generating multiplicative identities for arbitrary types---------------------------------------#

Base.oneunit(C::Type{<:AbstractCliffordNumber{Q}}) where Q = KVector{0,Q}(numeric_type(C)(true))
Base.one(C::Type{<:AbstractCliffordNumber{Q}}) where Q = KVector{0,Q}(numeric_type(C)(true))

#---Similar types----------------------------------------------------------------------------------#
Expand Down

0 comments on commit 908d84a

Please sign in to comment.