Subject: | bigint support fails |
Date: | Tue, 30 Jul 2013 16:36:59 -0700 |
To: | bug-Math-Prime-Util-GMP [...] rt.cpan.org |
From: | Renewal Computer Services <jimm [...] renewalcomputerservices.com> |
D:\prj\twin-primes\math-prime-util>perl twin-primes.pl
1000000000000000000000000 500000
Parameter '1e+024' must be a positive integer at twin-primes.pl line 64.
D:\prj\twin-primes\math-prime-util>perl twin-primes.pl
1000000000000000000000000 500000
Parameter '1e+024' must be a positive integer at
D:/strawberry/perl/site/lib/Math/Prime/Util.pm line 310.
D:\prj\twin-primes\math-prime-util>perl twin-primes.pl
1000000000000000000000000 500000
Parameter '1e+024' must be a positive integer at twin-primes.pl line 64.
D:\prj\twin-primes\math-prime-util>perl twin-primes.pl
"1000000000000000000000000" "500000"
Parameter '1e+024' must be a positive integer at twin-primes.pl line 64.
D:\prj\twin-primes\math-prime-util>
I have tried the following code using int() and without. no difference.
it still fails and tries to turn the bigints into floats. please fix the
code?
#!/usr/bin/perl
#twinprimes.pl
#Abstract: generate twin primes, and the differences, showing maximum
difference for the set
#Author: Jim Michaels
#Created: 7/18/2013
#program arguments:
# positive integer center
# positive integer offset, less than center above
#I originally did this with C++, but it was too slow with sieve of
Eratosthenes. this had a fast sieve and it already had range capability.
#use Math::Big;
use Math::Prime::Util::GMP ':all';
#use Math::Prime::Util ':all';
use bigint;
sub help {
die("twinprimes.pl - generate list of twin primes with
differences\n" .
"usage:\n" .
" twinprimes.pl center offset\n" .
" perl twinprimes.pl center offset\n" .
"options:\n" .
" center: positive integer which twin primes center
around\n" .
" offset: positive integer which is subtracted from the
offset and added to the center to provide upper and lower bounds.\n" .
"\n" .
"This program generates twin primes in the style of
primesieve as far as format, but goes 2 steps further:\n" .
"- this handles BigInt for infinite precision math\n" .
"- it uses Perl's very flexible number formatting
(handles hexadecimal, octal, etc)\n" .
"- shows the difference between twin primes\n" .
"- shows the maximum and minimum difference at the end,
and the count\n" .
"By Jim Michaels, 7/18/2013\n"
);
}
if (2 != $#ARGV+1) {
#provide help, user provided invalid quantity of arguments
help();
}
my ($center, $offset, $i, $max_difference, $min_difference,
$difference, $old_i, $upper_bound, $lower_bound,$twin_prine_count,$offset);
my @twinprimes = ();
$center=int($ARGV[0]);
$offset=int($ARGV[1]);
$upper_bound = $center+$offset+2;
$lower_bound = $center-$offset;
my $aref = primes($lower_bound, $upper_bound);
my $num_primes_found = $#{$aref} + 1;
#my $num_primes_found = $#aref + 1;
$twin_prime_count=0;
$old_i = -1;
$difference = 0;
for ($i=0; $i < $num_primes_found - 1; $i++) {
if ($$aref[$i]+2==$$aref[$i+1]) {#twin prime?
$twin_prime_count++;
print "(" . $$aref[$i] . ", " . $$aref[$i+1] . ") index=" .
$twin_prime_count;
if (-1 != $old_i) {
$difference = $i-$old_i;
$min_difference = min($min_difference,$difference);
$max_difference = max($max_difference,$difference);
print " difference=" . $difference;
}
print "\n";
$old_i = $i;
}
}
print "\n";
print "center=" . $center . "\n";
print "offset=" . $offset . "\n\n";
print "lower bound=" . $lower_bound . "\n";
print "upper bound=" . $upper_bound . "\n";
print "min difference=" . $min_difference . "\n";
print "max difference=" . $max_difference . "\n";
print "count=" . $twin_prime_count . "\n";
print "\n";
sub min {
my($mn,$i);
if ($#_+1 < 1) {
return 0;
}
$mn=int($_[0]);
for ($i=0; $i <= $#_; $i++) {
#if (0 == $i) {
# $mn=$_[$i];
#}
if (int($_[$i]) < $mn) {
$mn=int($_[$i]);
}
}
return $mn;
}
sub max {
my($mx,$i);
if ($#_+1 < 1) {
return 0;
}
$mx=int($_[0]);
for ($i=0; $i <= $#_; $i++) {
#if (0 == $i) {
# $mx=$_[$i];
#}
if (int($_[$i]) > $mx) {
$mx=int($_[$i]);
}
}
return $mx;
}
--
Renewal Computer Services <http://RenewalComputerServices.com>
Jim Michaels, Owner
1303 NE 87th Ave
<http://www.mapquest.com/maps/1303+NE+87th+Ave+Vancouver+WA+98664-1959/>
(87th Ave & 13th St),
Vancouver, WA, 98664-1959 USA, 1-360-521-2060 Cell 1-10pm
Serving Vancouver, WA
DIY Computer Repair Info: Jesusnjim.com <http://Jesusnjim.com>
jimm@RenewalComputerServices.com <mailto:jimm@RenewalComputerServices.com>
jmichae3@yahoo.com <mailto:jmichae3@yahoo.com>
Message body is not shown because it is too large.