From 659276792799cb14cc8383ec240ae40988ea3ac8 Mon Sep 17 00:00:00 2001 From: Brandon Flores Date: Wed, 11 Sep 2024 15:15:04 -0500 Subject: [PATCH] Manually handled integer exponentiation of `AbstractCliffordNumber` to avoid issues with negative exponents --- src/math/exponential.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/math/exponential.jl b/src/math/exponential.jl index 79e8c4c..500a060 100644 --- a/src/math/exponential.jl +++ b/src/math/exponential.jl @@ -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