Skip to content
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

Add tests for complex division corner cases, issue #22983 #23013

Merged
merged 1 commit into from
Aug 1, 2017

Conversation

giordano
Copy link
Contributor

No description provided.

@ararslan ararslan added complex Complex numbers maths Mathematical functions test This change adds or pertains to unit tests labels Jul 28, 2017
test/complex.jl Outdated Show resolved Hide resolved
@giordano
Copy link
Contributor Author

@stevengj I assume complex(1) / complex(1) is currently giving a "wrong" results (the only issue being the sign of imaginary part), right?

@stevengj
Copy link
Member

stevengj commented Jul 29, 2017

@giordano, no

julia> complex(1)/complex(1)
1.0 + 0.0im

is correct. ISO/IEC 10967-3:2006(E) section 5.2.6.3 says that the result should be

(1.0+0.0im)/(1.0+0.0im)
= Complex(1.0*1.0+0.0*0.0, 0.0*1.0-1.0*0.0) / (1.0*1.0 + 0.0*0.0)
= Complex(1.0, 0.0) / 1.0
= Complex(1.0, 0.0)
= 1.0 + 0.0im

since 0.0 - 0.0 = +0.0 according to IEEE 754.

If you think of it as (1+x*im) / (1 + y*im) in the limit as x and y go to zero from above, then whether it is 1 + 0.0im or 1 - 0.0im (with the "sign of 0" taken as the direction from which zero is approached) depends on the order of the limits, so the former choice is a valid option.

@stevengj
Copy link
Member

stevengj commented Jul 29, 2017

(It's also pretty sensible that z/z give one(z) for any nonzero z, and we've defined one to be 1.0+0.0im, although actually this doesn't always happen due to roundoff errors.)

@giordano
Copy link
Contributor Author

Oh, right, thanks! I added the test for one(Complex{T}) / one(Complex{T}) and slightly reorganized the test to avoid defining variables.

@StefanKarpinski StefanKarpinski merged commit 9b397fa into JuliaLang:master Aug 1, 2017
@giordano giordano deleted the complex-division branch May 12, 2019 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complex Complex numbers maths Mathematical functions test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants