Skip to content

Over/underflow in complex power function #54692

Open

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

rᵖ = r^pᵣ * exp(-pᵢ*θ)
by making 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorcomplexComplex numbersmathsMathematical functions

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions