Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong sign of zero for (x+0im)^(negative real) #14342

Closed
stevengj opened this issue Dec 9, 2015 · 4 comments · Fixed by #24497
Closed

wrong sign of zero for (x+0im)^(negative real) #14342

stevengj opened this issue Dec 9, 2015 · 4 comments · Fixed by #24497
Labels
bug Indicates an unexpected problem or unintended behavior maths Mathematical functions

Comments

@stevengj
Copy link
Member

stevengj commented Dec 9, 2015

With Julia 0.5, (2.0+0im)^-2 correctly gives 0.25 - 0.0im, but (2.0+0im)^-2.1 gives 0.23325824788420185 + 0.0im. Notice that the sign of the imaginary part is incorrect, in that (2.0+δ*im)^-2.1 should give a negative imaginary part as δ ⟶ 0⁺.

cc: @jiahao

@stevengj stevengj added bug Indicates an unexpected problem or unintended behavior maths Mathematical functions labels Dec 9, 2015
@jiahao
Copy link
Member

jiahao commented Dec 10, 2015

Related to #10000?

@stevengj
Copy link
Member Author

@jiahao, I don't think so, because negative-integer powers work.

@jiahao
Copy link
Member

jiahao commented Dec 10, 2015

Negative integer powers use a different method. What gets called for (2.0+0.0im)^-2 is

Base.power_by_squaring(inv(2.0+0.0im), +2)

whereas (2.0+0.0im)^-2.1 calls exp((-2.1+0.0im)*log(2.0+0.0im)).

The problem appears to be the premature promotion of (2.0+0.0im)^-2.1 to (2.0+0.0im)^(-2.1+0.0im), as

julia> exp((-2.1+0.0im)log(2.0+0.0im))
0.23325824788420185 + 0.0im

julia> exp((-2.1)log(2.0+0.0im))
0.23325824788420185 - 0.0im

We can solve this by defining ^(z::Complex, w::Real) as its own special method, but perhaps there is a cleverer solution.

@stevengj
Copy link
Member Author

^(z::Complex, w::Real) should probably be its own method anyway, since I would be surprised if you couldn't compute this more efficiently than Complex^Complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior maths Mathematical functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants