-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Description
@aswart found another complex function that causes problems for complex-step differentiation (see also #2889).
When raising a complex number with negative real part and small imaginary part to an integer power (an everyday occurrence with complex step diferentiation), the imaginary part is wrong.
Example:
This gives an accurate result :
julia> imag(complex(-2,1e-20)|x->x*x)
-4.0e-20
But, when using ^(z::Complex, n::Integer) = z^complex(n)
julia> imag(complex(-2,1e-20)|x->x^2)
-9.797174393178826e-16
then we get something entirely different. (MATLAB and Python give -4.0e-20).
One way to fix this would be to simply defer this case to Base.power_by_squaring(A,p)
, but the more general case ^(Complex,Complex) would then probably still need some attention.
julia> imag(complex(-2,1e-20)|x->Base.power_by_squaring(x,2))
-4.0e-20
CC: @jiahao
Metadata
Metadata
Assignees
Labels
No labels