Skip to content

Commit

Permalink
use power_by_squaring for complex^integer. fixes #3246
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 30, 2013
1 parent 0441c88 commit 9470bb2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ function ^{T<:FloatingPoint}(z::Complex{T}, p::Complex{T})
end
complex(x,y)
elseif z!=0
if p!=0 && isinteger(p)
return power_by_squaring(z, convert(Integer, real(p)))
end
exp(p*log(z))
elseif p!=0 #0^p
zero(z) #CHECK SIGNS
Expand All @@ -342,6 +345,9 @@ function exp10{T}(z::Complex{T})
end

function ^{T<:Complex}(z::T, p::T)
if isinteger(p)
return power_by_squaring(float(z), convert(Integer, real(p)))
end
pr, pim = reim(p)
zr, zi = reim(z)
r = abs(z)
Expand Down

0 comments on commit 9470bb2

Please sign in to comment.