-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
incorrect (Inf + Inf*im)^2.0 and other complex^float #24515
Comments
On the other hand, we have:
I don't think that it is worth the extra checks to deal with this overflow case correctly, however. You'd have to slow down all complex multiplications to make |
Wow, I found some even worse bugs: julia> (0+0im)^-3.0
0.0 + 0.0im (!!!) and julia> (1.0+0.0im)^1e300
ERROR: InexactError: convert(Int64, 1.0e300)
Stacktrace:
[1] convert at ./float.jl:703 [inlined]
[2] convert at ./int.jl:530 [inlined]
[3] convert at ./int.jl:534 [inlined]
[4] ^(::Complex{Float64}, ::Complex{Float64}) at ./complex.jl:657
[5] ^(::Complex{Float64}, ::Float64) at ./promotion.jl:310 |
I'm working at a patch that fixes this, and also makes the code 60% faster for complex^complex and 120% faster for real^complex. |
Another bad case? julia> Inf^(-Inf + 0.0im)
-0.0 - 0.0im Actually, maybe that's correct: Python seems to get this one wrong: In [1]: inf = float('inf')
In [2]: inf ** (-inf + 0j)
Out[2]: (nan+nanj) |
Closed by #24570. |
In Julia 0.4–0.7, I get:
which seems wrong (it assumes that the two
Inf
components are the "same"). The correct answer is given for^2
:The error seems to be due to this line, which dates back to #2891 by @jiahao.
My first inclination is to remove the entire
p==2
special case from this^
method. As I commented in #24497, that seems to be a performance optimization that is probably largely superseded, since most cases that need a fastz^2
probably use (a) an integer exponent (that calls a different method) and/or (b) a literal integer exponent (for whichz^2
is inlined asz*z
forComplex64
andComplex128
).The text was updated successfully, but these errors were encountered: