Skip Menu |

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

Report information
The Basics
Id: 88293
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.999701



Subject: BigFloat batan(1.5) infinite loop
Date: Sat, 31 Aug 2013 06:23:41 +1000
To: bug-Math-BigInt [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
With Math::BigFloat 1.997 and recent debian i386 perl 5.14.2, the program foo.pl below goes into an apparently infinite loop, where I hoped it would print batan=0.982793723... There seems to be something doubtful where batan() notices abs($x) > 1 and inverts to 1/$x for the power series. If $x is an integer then $x>1 is noticed correctly, but if $x is not an integer then seems not.
#!/usr/bin/perl -w use strict; use Math::BigFloat; my $x = Math::BigFloat->new(1.5); $x->batan(); print "batan=$x\n"; exit 0;
-- Events jargon elucidated for the layman: "Wedding package" -- twice the price and non-refundable.
The following patch fixes this. It could be made more efficient by someone more familiar with the system. It also fixes the similar problem in: https://rt.cpan.org/Ticket/Display.html?id=61139 which has a similar issue, though does not attempt to deal with the accuracy issue there.
Subject: bigfloat-batan-fix.patch
--- lib/Math/BigFloat.pm.orig 2013-10-22 10:55:47.640415285 -0700 +++ lib/Math/BigFloat.pm 2013-10-23 15:10:18.820161719 -0700 @@ -3163,7 +3163,7 @@ # to calculate PI/2 - atan(1/x): my $one = $MBI->_new(1); my $pi = undef; - if ($x->{_es} eq '+' && ($MBI->_acmp($x->{_m},$one) >= 0)) + if ($x->bacmp($x->copy->bone) >= 0) { # calculate PI/2 $pi = $self->bpi($scale - 3);
Subject: Re: [rt.cpan.org #88293] BigFloat batan(1.5) infinite loop
Date: Thu, 24 Oct 2013 11:16:17 +1100
To: bug-Math-BigInt [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Dana Jacobsen via RT" <bug-Math-BigInt@rt.cpan.org> writes: Show quoted text
> > - if ($x->{_es} eq '+' && ($MBI->_acmp($x->{_m},$one) >= 0)) > + if ($x->bacmp($x->copy->bone) >= 0)
Yes, that's about it. $x->bacmp(1) seems enough for me if that helps. Perhaps the object style $one is only needed by the internal _acmp() ...
On Wed Oct 23 20:17:56 2013, user42@zip.com.au wrote: Show quoted text
> "Dana Jacobsen via RT" <bug-Math-BigInt@rt.cpan.org> writes:
> > > > - if ($x->{_es} eq '+' && ($MBI->_acmp($x->{_m},$one) >= 0)) > > + if ($x->bacmp($x->copy->bone) >= 0)
> > Yes, that's about it. $x->bacmp(1) seems enough for me if that helps. > Perhaps the object style $one is only needed by the internal _acmp() ...
$x->bacmp(1) should work fine, but I believe it is slightly slower. I've found, especially with the GMP backend, that programs using Math::BigInt can spend over half their time in Objectify caused by doing things like ->badd(1) instead of ->binc(). Converting integer arguments into BigInts outside of loops tends to speed things up a lot (e.g. making a Math::BigInt version of '2' at the top, then using bcmp($two) inside a loop instead of bcmp(2) saves lots of time). In this case it is debatable whether it is worth the trouble. NYTProf says the $x->copy->bone does save ~200 calls to new() in the big atan test file, but it's lost in the time spent in other parts of that file. Faster would be something using $x->{_es}, $MBI->_len($x->{_m}), and $MBI->_num($x->{_e}), but there are lots of weird cases.
Fixed in v1.999701.