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

Complex#atan2() #140

Closed
axkr opened this issue Jun 18, 2021 · 3 comments
Closed

Complex#atan2() #140

axkr opened this issue Jun 18, 2021 · 3 comments

Comments

@axkr
Copy link
Contributor

axkr commented Jun 18, 2021

          Complex cx=new Complex(2,0);
    	  Complex cy=new Complex(0,4);
    	  System.out.println( cx.atan2(cy)); 

gives (0.0, -0.5493061443340549) but should give 1.5707963267948966+I*0.5493061443340549*

https://www.wolframalpha.com/input/?i=atan%282%2CI*4%29

@maisonobe
Copy link
Contributor

Beware that in Wolfram alpha, it seems that the two argument atan function is interpreted as tan^-1(x, y) (see the input interpretation panel in the result page), whereas in Hipparchus
(and in all programming languages I have seen), the first argument of atan2 is y and the second is x.
Also as one imaginary part is zero and the real part of the other number is zero, one should check with tiny positive and negative values to see if there is a branch cut. In this case, there is one and putting the arguments in the other order give the same result as Hipparchus:

https://www.wolframalpha.com/input/?i=atan%28%2B1.0e-8%2BI*4%2C+2%2B1.0e-8+I%29

note that changing the sign of the almost zero real part changes the output:

https://www.wolframalpha.com/input/?i=atan%28-1.0e-8%2BI*4%2C+2%2B1.0e-8+I%29

So I would say the Hipparchus result is correct here.

@axkr
Copy link
Contributor Author

axkr commented Jun 18, 2021

OK.
Does it make sense to add some note to javadoc here:

axkr added a commit to axkr/symja_android_library that referenced this issue Jun 18, 2021
- Hipparchus-Math/hipparchus#140
- Note: the first argument of atan2 is y and the second is x.
@maisonobe
Copy link
Contributor

Good idea, I have updated documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants