Skip Menu |
 

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 11212
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Math-BigInt

People
Owner: TELS [...] cpan.org
Requestors: zaxo [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.74
Fixed in: 1.75

Attachments
Math-BigInt-1.74-atan2.patch



MIME-Version: 1.0
X-Mailer: MIME-tools 5.415 (Entity 5.415)
Subject: [PATCH] atan2 returns incorrect results
Content-Type: multipart/mixed; boundary="----------=_1106631276-17688-0"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 552
Download (untitled) / with headers
text/plain 552b
Ambrus at perlmonks noticed that: $ perl -e'use bignum; print atan2(0,1)' prints the value of pi/2, which is incorrect. This seems to occur for all recent versions. I haven't tested any old ones. I found that lib/Math/BigInt.pm overloads atan2, but does not pay attention to the argument order flag. Attached is a patch to lib/Math/BigInt.pm, as well as to t/fallback.t. The test patch implements tests which will catch this problem. The patched version builds and passes all tests. Installed, it fixes the problem ambrus found. Regards, Zaxo
Content-Type: application/octet-stream; name="Math-BigInt-1.74-atan2.patch"
Content-Disposition: inline; filename="Math-BigInt-1.74-atan2.patch"
Content-Transfer-Encoding: base64
Content-Length: 1224
--- Math-BigInt-1.74/lib/Math/BigInt.pm Sat Jan 1 10:57:35 2005 +++ Math-BigInt-1.74_1/lib/Math/BigInt.pm Sun Jan 23 23:33:26 2005 @@ -75,7 +75,9 @@ 'cos' => sub { cos($_[0]->numify()) }, 'sin' => sub { sin($_[0]->numify()) }, 'exp' => sub { exp($_[0]->numify()) }, -'atan2' => sub { atan2($_[0]->numify(),$_[1]) }, +'atan2' => sub { $_[2] ? + atan2($_[1],$_[0]->numify()) : + atan2($_[0]->numify(),$_[1]) }, # are not yet overloadable #'hex' => sub { print "hex"; $_[0]; }, --- Math-BigInt-1.74/t/fallback.t Thu Dec 11 14:17:58 2003 +++ Math-BigInt-1.74_1/t/fallback.t Sun Jan 23 22:36:17 2005 @@ -28,7 +28,7 @@ } print "# INC = @INC\n"; - plan tests => 8; + plan tests => 9; } # The tests below test that cos(BigInt) = cos(Scalar) which is DWIM, but not @@ -46,10 +46,11 @@ ok (exp($bi), exp(1)); ok (atan2($bi,$bi), atan2(1,1)); -my $bf = Math::BigInt->new(1); +my $bf = Math::BigInt->new(0); -ok (cos($bf), cos(1)); -ok (sin($bf), sin(1)); -ok (exp($bf), exp(1)); -ok (atan2($bf,$bf), atan2(1,1)); +ok (cos($bf), cos(0)); +ok (sin($bf), sin(0)); +ok (exp($bf), exp(0)); +ok (atan2($bi,$bf), atan2(1,0)); +ok (atan2($bf,$bi), atan2(0,1));
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
MIME-Version: 1.0
X-Mailer: MIME-tools 5.415 (Entity 5.415)
X-RT-Original-Encoding: iso-8859-1
Content-Length: 44
Fixed in v1.75 - thanx again for the report.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.