-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviorcomplexComplex numbersComplex numbersmathsMathematical functionsMathematical functions
Description
Julia's base complex^complex power function may produce NaN for some arguments when the result should be representable because of underflow/overflow at intermediate stages of the computation.
Example:
julia> a=exp(1+im)
1.4686939399158851 + 2.2873552871788423im
julia> b=1e5*(1+im)
100000.0 + 100000.0im
julia> abs(a^b)
NaN
In this case, the naive implementation of complex powers produces a correct result
julia> abs(exp(b*log(a)))
1.0
I suspect that this issue was introduced by #24570.
The example is constructed to cause overflow/underflow in
Line 860 in a5d6b50
| rᵖ = r^pᵣ * exp(-pᵢ*θ) |
r^pᵣ very large and exp(-pᵢ*θ) very small.
Version info
julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU: 12 × Apple M2 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviorcomplexComplex numbersComplex numbersmathsMathematical functionsMathematical functions