Just to be fair, I should mention that I tried *really* calculating
2 * 10001 in Perl. I used the "bigint.pl" library that comes with the
distribution, but it doesn't have a power function, so I quickly
hacked one in terms of the functions in bigint.pl.
This is the code:
#! /usr/local/bin/perl
require "bigint.pl";
sub bpow
{
local ($num, $exponent) = @_;
local ($answer) = '1';
while ($exponent)
{
if ($exponent & 0x01)
{
# this exponent of the number is a factor
# in the answer, so multiply it in.
$answer = &bmul ($answer, $num);
}
# go up to the next factor which is a power of two
$num = &bmul ($num, $num);
$exponent >>= 1;
}
$answer;
}
($base, $power) = @ARGV;
print "$base ** $power ==\n";
print &bpow ($base, $power), "\n";
And, on an RS/6000 250 (which is a PowerPC 601):
$ time ./power 2 10001
2 ** 10001 ==
[...] 5193418752
real 0m40.01s
user 0m39.73s
sys 0m0.13s
Not bad, considering it's using floating point to do the integer
stuff, which it's using (in arrays) to do the functions in bigint.pl,
which I'm calling over and over again to do my bpow() function.
If I'd written bpow from scratch, I'm sure it could have been much
faster.
Adios,
Logan
-- The genius of France can be seen at a glance And it's not in their fabled fashion scene It's not that they're mean, or their wine, or cuisine I refer of course to the guillotine (the French knew how to lynch) T-Bone Burnett, "I Can Explain Everything"