Ask a Question related to PERL Modules, Design and Development.
-
Sisyphus #1
Re: use bigmnum
"gamo" <gamo@telecable.es> wrote in message
news:Pine.LNX.4.64.0606161644010.11351@jvz.es...
#!/usr/local/bin/perl -w
use bignum;
$fact=1;
for $i (2..1000){
$fact*=$i;
}
print "$fact\n";
$div = int ($fact/2003);
$resto = $fact - $div*2003;
# $resto = $fact % 2003;
print "$resto\n";
__END__
---------------------------------------------------
I think that what you wanted to achieve using int() should already be done
for you anyway - and calling int() leads to an error (for me, anyway) -
namely that $div then evaluates as 'NaN'.
However, it also looks like there's a bug in Math::BigInt.
For me $div (without the int call) is being evaluated as:
20089229160114516901832373136445530989480000000000 0000000000000000000000....
It should be:
20089229160114516901832373136445530989484516435881 9087640439296270563411....
You should file a bug report about this - or at least let the current
maintainer of the module know.
Both Math::Pari and Math::GMP should yield correct results.
Incidentally, for me (perl 5.8.8), '$resto = $fact % 2003;' evaluates
correctly.
Cheers,
Rob
Sisyphus Guest
-
use bigmnum?
#!/usr/local/bin/perl -w use bignum; $fact=1; for $i (2..1000){ $fact*=$i; } print "$fact\n"; $div = int ($fact/2003); -
Tim Heaney #2
Re: use bigmnum
"Sisyphus" <sisyphus1@nomail.afraid.org> writes:
This appears to be the default 40 digits we get from>
> However, it also looks like there's a bug in Math::BigInt.
>
> For me $div (without the int call) is being evaluated as:
> 20089229160114516901832373136445530989480000000000 0000000000000000000000....
Math::BigFloat->div_scale.
I get this when I use the bigint pragma, rather than bignum.> It should be:
> 20089229160114516901832373136445530989484516435881 9087640439296270563411....
And % works for me too...with either bignum or bigint.
Tim
Tim Heaney Guest
-
Tim Heaney #3
Re: use bigmnum
As a side note, the module already knows how to calculate factorial.> "gamo" <gamo@telecable.es> wrote in message
> news:Pine.LNX.4.64.0606161644010.11351@jvz.es...
>
> #!/usr/local/bin/perl -w
>
> use bignum;
>
> $fact=1;
> for $i (2..1000){
> $fact*=$i;
> }
> print "$fact\n";
$fact = Math::BigInt->bfac(1000);
Tim
Tim Heaney Guest
-
Sisyphus #4
Re: use bigmnum
"Tim Heaney" <theaney@gmail.com> wrote in message
..
..20089229160114516901832373136445530989484516435881 9087640439296270563411....>> > It should be:
> >Yes, I think I was mistaken - the problem only arises when bignum is>
> I get this when I use the bigint pragma, rather than bignum.
invoked. Using M::BI instead of bignum seems to fix things.
Btw, I think at least some newsreaders (and possibly the archives) are going
to show my post (and the follow-ups) as a separate thread from the
original - "use bigmnum" versus "use bignmum?". Sorry 'bout that .... some
curly issues with my newsreader that I didn't quite workaround as I had
hoped :-)
Cheers,
Rob
Sisyphus Guest



Reply With Quote

