Subject: | random_prime() occasionally generates negative values (?) |
Date: | Wed, 30 Dec 2015 08:05:08 -0700 |
To: | bug-Math-Prime-Util [...] rt.cpan.org |
From: | Glenn Golden <gdg [...] zplane.com> |
Greetings Mr. Prime::Util,
The attached minimal example, run on an i686, occasionally produces
negative values for q, usually when q is around 9 digits. For example:
perl: v5.22.0
Math::Prime::Util: 0.55
q: -891554259
lolim: 2700528841
hilim: 4050793261
Perhaps this is some error on my part in usage of BigInt->new() with args
that can be either native or BigInt (as random_prime()) but I can't see what
it might be.
Show quoted text
---------------------------- cut here ----------------------------------
#!/usr/bin/perl
use warnings FATAL => 'all';
use strict;
use Math::BigFloat lib => 'GMP';
use Math::BigInt lib => 'GMP';
use Math::Prime::Util qw / :all /;
print "perl: $^V\n";
print "Math::Prime::Util: $Math::Prime::Util::VERSION\n\n";
my ($p, $q);
my ($lolim, $hilim);
$p = Math::BigInt->new(random_ndigit_prime(10));
$lolim = int(Math::BigFloat->new(1.0) * $p);
$hilim = int(Math::BigFloat->new(1.5) * $p);
$q = Math::BigInt->new(random_prime($lolim, $hilim));
print "q: " . $q->bstr() . "\n"; # Occasionally negative
print "lolim: " . $lolim->bstr() . "\n";
print "hilim: " . $hilim->bstr() . "\n";
print "\n";
------------------------------------------------------------------------