Skip Menu |

This queue is for tickets about the Math-BigInt-GMP CPAN distribution.

Report information
The Basics
Id: 71548
Status: resolved
Priority: 0/
Queue: Math-BigInt-GMP

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

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



From: CARNIL [...] cpan.org
Subject: libmath-bigint-gmp-perl: new() from UV wrong value
Hi This bug has been forwarded from http://bugs.debian.org/644659 Comparing what Math::BigInt::Calc does, Math::BigInt::GMP does not report the same back with the test foo.pl attached to the above bugreport. Any ideas on this? Thanks in advance, Salvatore Bonaccorso, Debian Perl Group
This is a different defect caused by the same code. In this case it is converting 18446744073709551615 to -1 because of the mpz_init_set_si: perl -Iblib/lib -Iblib/arch -E 'use Math::BigInt lib=>"GMP"; my $n = Math::BigInt->new(10); say $n; say $n->bacmp(~0); say $n->copy->bsub(~0);' 10 1 11 perl -E 'use Math::BigInt lib=>"Calc"; my $n = Math::BigInt->new(10); say $n; say $n->bacmp(~0); say $n->copy->bsub(~0);' 10 -1 -18446744073709551605 perl -E 'use Math::BigInt lib=>"Pari"; my $n = Math::BigInt->new(10); say $n; say $n->bacmp(~0); say $n->copy->bsub(~0);' 10 -1 -18446744073709551605 Changing to mpz_init_set_ui makes it work correctly, and still passes the test suite. I think a test like this ought to be added to the test suite.
By the way, a hacky workaround for both is to put ''. in front of the number. So: if ($_[0]->bacmp(''.~0) <= 0) { ... } or in the foo.pl case: my $b = Math::BigInt->new(''.$n); # alternately: my $b = Math::BigInt->new("$n"); I've been using the latter a lot to work around this bug.
Another case where this shows up: perl -E 'use Math::BigInt lib=>"GMP"; say Math::BigInt->new("14")->bmodpow(9506577562092332135, "29544731879021791655795710");' results in: Floating point exception (core dumped) The arguments have to be quoted or they go negative. For Ubuntu GMP 5.0.2 this causes an FP exception in this case. If a 64-bit argument is given to the modulus it just silently gives the wrong answer.
Now that I have a patch to fix this problem, I have uploaded the new release Math-BigInt-GMP-1.46 to PAUSE. That release should fix this bug.