-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
-im*Inf should probably be equal to -Inf*im #9531
Comments
The issue is that julia> 0Inf
NaN
julia> -im
0 - 1im
julia> ans * Inf
NaN - Inf*im |
This is a special case of well-known problems with nonfinite complex floating point operations: #*(z::Complex, w::Complex) = Complex(real(z) * real(w) - imag(z) * imag(w),
# real(z) * imag(w) + imag(z) * real(w))
julia> Complex(5.0, Inf) * Complex(0.0, 1.0)
-Inf + NaN*im Arguably, the issue here is that we promote integral 0 to floating-point 0.0, then multiply by One alternative is to try to make julia> 0*Inf
NaN |
However, the answer is even worse for this example: julia> times(-im, Inf)
p1 = (a0 + b0) * a1 = -Inf
p2 = a0 * a1 = NaN
a = p2 = NaN
b = p1 - p2 = NaN
NaN + NaN*im |
Another thought was to do complex multiplication in polar form, but there is no floating point number julia> type ComplexPolar
r
θ
end
julia> *(a::ComplexPolar, b::ComplexPolar) = ComplexPolar(a.r*b.r, a.θ+b.θ)
* (generic function with 120 methods)
julia> Base.convert(::Type{Complex},a::ComplexPolar) = Complex(a.r*cos(a.θ), a.r*sin(a.θ));
convert (generic function with 493 methods)
julia> Base.convert(::Type{ComplexPolar},a::Complex) = ComplexPolar(abs(a), angle(a))
convert (generic function with 494 methods)
julia> a = convert(ComplexPolar, -im)
ComplexPolar(1.0,-1.5707963267948966)
julia> b = convert(ComplexPolar, Complex(Inf,0))
ComplexPolar(Inf,0.0)
julia> a*b
ComplexPolar(Inf,-1.5707963267948966)
julia> convert(Complex, ans)
Inf - Inf*im
julia> cos(-1.5707963267948966)
6.123233995736766e-17
julia> cos(prevfloat(-1.5707963267948966))
-1.6081226496766366e-16 |
May store theta as a number between [-1,1) that is multiplied by pi? Sent from my iPad
|
If you do that, the answer is still |
Maybe this is an argument for an imaginary number type? Sent from my iPad
|
This behaviour is surprising and probably wrong:
julia> -Infim
-0.0 - Infim
julia> -imInf
NaN - Infim
The text was updated successfully, but these errors were encountered: