use bigmnum?
am 16.06.2006 16:46:48 von gamo
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323328-391487729-1150469208=:11351
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
#!/usr/local/bin/perl -w
use bignum;
$fact=3D1;
for $i (2..1000){
$fact*=3D$i;
}
print "$fact\n";
$div =3D int ($fact/2003);
$resto =3D $fact - $div*2003;
# $resto =3D $fact % 2003;
print "$resto\n";
__END__
this should be 2, not 0 or $fact
TIA
--=20
http://www.telecable.es/personales/gamo/
S=F3lo hay 10 tipos de personas, las que saben binario y las que no
perl -e 'print 111_111_111**2,"\n";'
--8323328-391487729-1150469208=:11351--
Re: use bigmnum?
am 17.06.2006 04:55:02 von unknown
gamo wrote:
> #!/usr/local/bin/perl -w
>
> use bignum;
>
> $fact=1;
> for $i (2..1000){
> $fact*=$i;
> }
> print "$fact\n";
> $div = int ($fact/2003);
# This gives NaN for $div when I do it. Though I confess I am not
# sure why, as int appears to be overloaded. But if $div == NaN,
> $resto = $fact - $div*2003;
# is bound to give NaN as well. On the other hand,
$resto = $fact % 2003;
# gives 2 when I run it. So why not code it that way?
> print "$resto\n";
>
> __END__
> this should be 2, not 0 or $fact
>
When I see mysterious and unreproducable results, I always look at versions.
Me:
perl 5.8.6 (built from source)
bignum 0.17
Math::BigFloat 1.51
Math::BigInt 1.77
OS: Darwin 7.9.0 (or, really, Mac OS 10.3.9), though I do not believe
this has anything to do with it.
If you are out of date, you may wish to consider upgrading.
> TIA
>
Or TIO, in my case ;-)
Tom Wyant
Re: use bigmnum?
am 17.06.2006 14:49:49 von gamo
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323328-1119329942-1150548589=:11922
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
On Fri, 16 Jun 2006, harryfmudd [AT] comcast [DOT] net wrote:
> gamo wrote:
>=20
> > #!/usr/local/bin/perl -w
> >=20
> > use bignum;
> >=20
> > $fact=3D1;
> > for $i (2..1000){
> > $fact*=3D$i;
> > }
> > print "$fact\n";
> > $div =3D int ($fact/2003);
>=20
> # This gives NaN for $div when I do it. Though I confess I am not
> # sure why, as int appears to be overloaded. But if $div == NaN,
>=20
> > $resto =3D $fact - $div*2003;
>=20
> # is bound to give NaN as well. On the other hand,
>=20
> $resto =3D $fact % 2003;
>=20
> # gives 2 when I run it. So why not code it that way?
Because it says me:
Can't use an undefined value as an ARRAY reference at=20
/usr/local/lib/perl5/5.8.8/Math/BigInt/Calc.pm line 1068.
>=20
> > print "$resto\n";
> >=20
> > __END__
> > this should be 2, not 0 or $fact
> >=20
>=20
> When I see mysterious and unreproducable results, I always look at versio=
ns.
>=20
> Me:
> perl 5.8.6 (built from source)
> bignum 0.17
> Math::BigFloat 1.51
> Math::BigInt 1.77
> OS: Darwin 7.9.0 (or, really, Mac OS 10.3.9), though I do not believe thi=
s has
> anything to do with it.
>=20
> If you are out of date, you may wish to consider upgrading.
>=20
I'm using 5.8.8
and the modules that come with it.
Thank you very much.
> > TIA
> >=20
>=20
> Or TIO, in my case ;-)
>=20
> Tom Wyant
>=20
--=20
http://www.telecable.es/personales/gamo/
S=F3lo hay 10 tipos de personas, las que saben binario y las que no
perl -e 'print 111_111_111**2,"\n";'
--8323328-1119329942-1150548589=:11922--
Re: use bigmnum
am 18.06.2006 02:40:11 von Sisyphus
"gamo" 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:
200892291601145169018323731364455309894800000000000000000000 000000000000....
It should be:
200892291601145169018323731364455309894845164358819087640439 296270563411....
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
Re: use bigmnum
am 18.06.2006 03:20:40 von Tim Heaney
"Sisyphus" writes:
>
> However, it also looks like there's a bug in Math::BigInt.
>
> For me $div (without the int call) is being evaluated as:
> 200892291601145169018323731364455309894800000000000000000000 000000000000....
This appears to be the default 40 digits we get from
Math::BigFloat->div_scale.
> It should be:
> 200892291601145169018323731364455309894845164358819087640439 296270563411....
I get this when I use the bigint pragma, rather than bignum.
And % works for me too...with either bignum or bigint.
Tim
Re: use bigmnum?
am 18.06.2006 03:34:14 von unknown
gamo wrote:
> On Fri, 16 Jun 2006, harryfmudd [AT] comcast [DOT] net wrote:
>
>
>>gamo wrote:
>>
>>
>>>#!/usr/local/bin/perl -w
>>>
>>>use bignum;
>>>
>>>$fact=1;
>>>for $i (2..1000){
>>> $fact*=$i;
>>>}
>>>print "$fact\n";
>>>$div = int ($fact/2003);
>>
>># This gives NaN for $div when I do it. Though I confess I am not
>># sure why, as int appears to be overloaded. But if $div == NaN,
>>
>>
>>>$resto = $fact - $div*2003;
>>
>># is bound to give NaN as well. On the other hand,
>>
>>$resto = $fact % 2003;
>>
>># gives 2 when I run it. So why not code it that way?
>
>
> Because it says me:
> Can't use an undefined value as an ARRAY reference at
> /usr/local/lib/perl5/5.8.8/Math/BigInt/Calc.pm line 1068.
>
>
>>>print "$resto\n";
>>>
>>>__END__
>>>this should be 2, not 0 or $fact
>>>
>>
>>When I see mysterious and unreproducable results, I always look at versions.
>>
>>Me:
>>perl 5.8.6 (built from source)
>>bignum 0.17
>>Math::BigFloat 1.51
>>Math::BigInt 1.77
>>OS: Darwin 7.9.0 (or, really, Mac OS 10.3.9), though I do not believe this has
>>anything to do with it.
>>
>>If you are out of date, you may wish to consider upgrading.
>>
>
>
> I'm using 5.8.8
> and the modules that come with it.
>
> Thank you very much.
>
According to Module::CoreList, 5.8.8 comes with the same bignum,
Math::BigFloat, and Math::BigInt I'm running. I don't imagine upgrading
myself to 5.8.8 overnight (though I'll have to sometime).
Maybe someone running your version of Perl can help. Did you build it
yourself, or get it from somewhere?
I'm grasping at straws, though.
Tom Wyant
Re: use bigmnum
am 18.06.2006 03:45:53 von Tim Heaney
> "gamo" 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";
As a side note, the module already knows how to calculate factorial.
$fact = Math::BigInt->bfac(1000);
Tim
Re: use bigmnum
am 18.06.2006 04:09:57 von Sisyphus
"Tim Heaney" wrote in message
..
..
>
> > It should be:
> >
200892291601145169018323731364455309894845164358819087640439 296270563411....
>
> I get this when I use the bigint pragma, rather than bignum.
Yes, I think I was mistaken - the problem only arises when bignum is
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
Re: use bigmnum?
am 18.06.2006 07:28:26 von gamo
On Sat, 17 Jun 2006, harryfmudd [AT] comcast [DOT] net wrote:
> According to Module::CoreList, 5.8.8 comes with the same bignum,
> Math::BigFloat, and Math::BigInt I'm running. I don't imagine upgrading myself
> to 5.8.8 overnight (though I'll have to sometime).
>
> Maybe someone running your version of Perl can help. Did you build it
> yourself, or get it from somewhere?
I build it.
>
> I'm grasping at straws, though.
>
> Tom Wyant
>