in reply to undefined value as an ARRAY

Curiously, when I run the following command-line script on my mac (to replicate the essentials of your code), the "bfac" call apparently does not return, and the process runs in a seemingly infinite loop, chewing up cpu time:
perl -MMath::BigFloat -e '$|++;$x=Math::BigFloat->new("2.0"); print "\ncalling bpow at ",scalar(localtime)."\n";$x->bpow("128"); print "calling copy at ",scalar(localtime)."\n";$p=$x->copy(); print "calling bfac at ",scalar(localtime)."\n";$p->bfac(); print "finished at ",scalar(localtime)."\n"' calling bpow at Wed Aug 11 21:44:28 2010 calling copy at Wed Aug 11 21:44:28 2010 calling bfac at Wed Aug 11 21:44:28 2010
(still running an hour later... oh well, I'm just going to kill it now.) FWIW, I'm using the version that comes with "snow leopard" (osx 10.6.4):
This is perl, v5.10.0 built for darwin-thread-multi-2level
When you ran your script, did it crash right away, or did it run for a long time before crashing?

(Updated my command-line script to include the (rather important) first line of the command.)

Replies are listed 'Best First'.
Re^2: undefined value as an ARRAY
by oko1 (Deacon) on Aug 12, 2010 at 03:24 UTC

    I suspect you'd have to wait a bit more than an hour. Given this:

    #!/usr/bin/perl -w use strict; use Benchmark qw/:all/; use Math::BigFloat; cmpthese( 1, { '2**10' => sub { my $x = Math::BigFloat->new(2**10); my $prod +uct = $x->copy(); $product->bfac(); }, '2**11' => sub { my $x = Math::BigFloat->new(2**11); my $prod +uct = $x->copy(); $product->bfac(); }, '2**12' => sub { my $x = Math::BigFloat->new(2**12); my $prod +uct = $x->copy(); $product->bfac(); }, '2**13' => sub { my $x = Math::BigFloat->new(2**13); my $prod +uct = $x->copy(); $product->bfac(); }, '2**14' => sub { my $x = Math::BigFloat->new(2**14); my $prod +uct = $x->copy(); $product->bfac(); } });

    I get run times like these:

    s/iter 2**14 2**13 2**12 2**11 2**10 2**14 139 -- -78% -97% -99% -100% 2**13 31.3 345% -- -88% -97% -99% 2**12 3.88 3488% 706% -- -78% -95% 2**11 0.870 15902% 3493% 346% -- -76% 2**10 0.210 66195% 14786% 1748% 314% --

    With that kind of progression, 2**128 is, um, likely to take a while. :)


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf
Re^2: undefined value as an ARRAY
by toolic (Bishop) on Aug 12, 2010 at 02:46 UTC
    When you ran your script, did it crash right away, or did it run for a long time before crashing?
    Another data point: I get the error immediately. When I try smaller numbers, I do not get the error, but it does seem to take a while.
    This is perl, v5.8.8 built for MSWin32-x86-multi-thread
      If your script works for smaller numbers then it's probably a bug in either Math::BigFloat itself or in a library it uses .

      If it is an option for you try it on another system or with a newer version of Perl.