Skip to content

Commit

Permalink
Manually handled integer exponentiation of AbstractCliffordNumber t…
Browse files Browse the repository at this point in the history
…o avoid issues with negative exponents
  • Loading branch information
brainandforce committed Sep 11, 2024
1 parent 41c6b45 commit 6592767
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/math/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ end
# See this issue: https://github.com/JuliaLang/julia/issues/53504
^(x::C, n::Integer) where C<:Union{KVector,OddCliffordNumber} = convert(exponential_type(C), x)^n

# If this is not defined, negative exponentiation fails even for Float cases
function ^(x::AbstractCliffordNumber, n::Integer)
# But throw the error anyway for Integer scalar types
if n < 0 && !(scalar_type(x) <: Union{Integer,Complex{<:Integer}})
return Base.power_by_squaring(inv(x), -n)
end
return Base.power_by_squaring(x, n)
end

#---Special cases for exponentiation---------------------------------------------------------------#

# KVector of orders 0 and 1 are guaranteed to square to scalars
Expand Down

0 comments on commit 6592767

Please sign in to comment.