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
Math::Complex atan2 bug #8100
Comments
From @tseeThis is a bug report for perl from smueller@cpan.org, This bug is still present in 5.9.2. [I just found out about perlbug. I hope this finally is the The syntax of using the atan2 routine is, generally: You will know that perl -MMath::Complex -e "print atan2(0,1)" perl -MMath::Complex -e "print atan2(1,0)" Now, in the complex plane, we get: This is not correct. Obviously, 0/i is the same as 0/1 At fault is the following code: In the last test case above, $inverted is set. Therefore, if I attached a patch which adds another if($inverted){}else{} I assume you want to add a test for any bugfix, but since I ($eps defined in Complex.t) my $res; diff -u follows: Inline Patch--- Complex.pm 2005-04-01 11:43:02.000000000 +0200
+++ C:/perl/perl58/lib/Math/Complex.pm 2005-08-04 16:45:13.890625000 +0200
@@ -1281,7 +1281,13 @@
return CORE::atan2($re1, $re2) if $im1 == 0;
return ($im1<=>0) * pip2 if $re2 == 0;
}
- my $w = atan($z1/$z2);
+ my $w;
+ if ($inverted) {
+ $w = atan($z2/$z1);
+ }
+ else {
+ $w = atan($z1/$z2);
+ }
my ($u, $v) = ref $w ? @{$w->cartesian} : ($w, 0);
$u += pi if $re2 < 0;
$u -= pit2 if $u > pi;
-----
Flags: Site configuration information for perl v5.8.7: Configured by builder at Mon Jun 6 13:36:05 2005. Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Locally applied patches: @INC for perl v5.8.7: Environment for perl v5.8.7: |
From @jhiWhile I certainly agree that a runtime divide-by-zero is not the right In my books atan2() is not well-defined for complex arguments at all, See e.g. http://mathworld.wolfram.com/InverseTangent.html |
The RT System itself - Status changed from 'new' to 'open' |
From @jhiJarkko Hietaniemi wrote:
This bit: : This is not correct. Obviously, 0/i is the same as 0/1 seems to be incorrect... if one believes the Mathematica definition Another good reference on these matters, MATLAB ignores the complex
|
From @jhi
Ahem, sorry... it seems that Mathematica's ArcTan is ArcTan[x, y] while
This still is true. |
From @jhi
I'll work out a patch... I have other outstanding things to do for
|
From st.mueller@smt.zeiss.comHi Jarkko, You wrote:
Well, that's fine. (Though not how I'd like to use the function.) Right We have: (Due to overloading, it doesn't matter if any one of the $cplxX is I understand your argument that atan2 of complex arguments isn't well Hence, I'd suggest patching the behaviour one way or another. There's - atan2($z1, $z2) = atan($z1/$z2) (same order as with the normal atan2) Either way, the behaviour should be documented. And IMHO it shouldn't be Best regards, |
From @jhiThe attached patch (#1) brings several pending updates to Math::Complex - Complex: fix for the [perl #31117]: atan2(0, i) now works, I also made the modules scratch-proof, err, 5.00504 and 5.6.2-resistant. Since the Complex+Trig have had some fixes/updates over the years, maybe The tiny patch (#2) documents the attested fact that atan2(0, 0) is not Both patches should be maint-worthy. |
From @jhi |
From @jhi |
@rgs - Status changed from 'open' to 'resolved' |
From @rgsJarkko Hietaniemi wrote:
Both applied to blead as #25414, thanks. But may I suggest that next time, -- |
From Nadeem.Douba@ec.gc.caThere is a small technical bug in "sub great_circle_destination {...}". North Western Hemisphere = ( South Western Hemisphere = ( North Eastern Hemisphere = ( South Eastern Hemisphere = ( There is no need to subtract by pi/2 (pip2) in this case. The North is 0; Here it is (tried and tested on GIS applications): =cut my ($dlat, $dlon) = great_circle_distance($lat, $lon, $distance, # 6378.1 is the radius of the earth in km. You could alternatively use sub great_circle_destination { my ( my ( # lat2 = asin(sin(lat1)*cos(d) + cos(lat1)*sin(d)*cos(hdng)) $rho = 1 unless defined($rho); return ($lat1, $lon1); } -----Original Message----- The attached patch (#1) brings several pending updates to Math::Complex - Complex: fix for the [perl #31117]: atan2(0, i) now works, I also made the modules scratch-proof, err, 5.00504 and 5.6.2-resistant. Since the Complex+Trig have had some fixes/updates over the years, maybe The tiny patch (#2) documents the attested fact that atan2(0, 0) is not Both patches should be maint-worthy. |
From @jhiRafael Garcia-Suarez wrote:
Ooops. In my defense I can say I did perl -wIlib lib/Math/Complex.t|grep not (and came up empty) but yeah, didn't run full test or use the harness...
|
From @jhi
I am confused. On a sphere the destination point d (radians)
We cannot change the default coordinate system of the great_circle_* One possible way to incorporate your semantics would be to add |
Migrated from rt.perl.org#37117 (status was 'resolved')
Searchable as RT37117$
The text was updated successfully, but these errors were encountered: