Skip Menu |

This queue is for tickets about the Math-Prime-Util CPAN distribution.

Maintainer(s)' notes

The latest version is in https://github.com/danaj/Math-Prime-Util

    git clone --origin upstream git://github.com/danaj/Math-Prime-Util.git Math-Prime-Util

Comments, issues, and patches are welcome at either RT or github, or send me email.

Report information
The Basics
Id: 110779
Status: resolved
Priority: 0/
Queue: Math-Prime-Util

People
Owner: DANAJ [...] cpan.org
Requestors: gdg [...] zplane.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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"; ------------------------------------------------------------------------
Thanks for the report and test program. I've verified this on a 32-bit Perl. The issue seems to be with Math::BigInt::GMP's RT (71548 and 105317). It's happening in the test program rather than the module so there is nothing the module can do to fix it (perhaps encourage use of Math::GMP or Math::GMPz). If the Calc backend is used then the problem goes away. Fixed in Math::BigInt::GMP 1.47. If the Math::BigInt->new() wrapper around $q is removed, we get screwy looking results since it is doing the wrong thing in the comparison operator (that is, q *is* in range, but it says it is not). Upgrading to Math::BigInt::GMP 1.47 fixes the issue.
Subject: Re: [rt.cpan.org #110779] random_prime() occasionally generates negative values (?)
Date: Sat, 2 Jan 2016 18:03:07 -0700
To: Dana Jacobsen via RT <bug-Math-Prime-Util [...] rt.cpan.org>
From: Glenn Golden <gdg [...] zplane.com>
Dana Jacobsen via RT <bug-Math-Prime-Util@rt.cpan.org> [2015-12-30 14:43:12 -0500]: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=110779 > > > Thanks for the report and test program. I've verified this on a 32-bit Perl. >
Show quoted text
> The issue seems to be with Math::BigInt::GMP's RT (71548 and 105317). >
OK, thanks. Is the 105317 cite above correct? It looks like that ticket pertains to an autoconfig issue, but perhaps it is in fact related...? Show quoted text
> > Upgrading to Math::BigInt::GMP 1.47 fixes the issue. >
Confirmed, thank you.
On Sat Jan 02 20:03:32 2016, gdg@zplane.com wrote: Show quoted text
> > OK, thanks. Is the 105317 cite above correct? It looks like that > ticket > pertains to an autoconfig issue, but perhaps it is in fact related...?
Sorry, transposed digits. 103517. https://rt.cpan.org//Dist/Display.html?Queue=Math-BigInt-GMP Two of these are the related tickets.
Closing since this is an issue with Math::BigInt::GMP, and the newest version of that module fixes the issue.