Skip Menu |
 

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

Report information
The Basics
Id: 121284
Status: open
Priority: 0/
Queue: Math-BigInt-Lite

People
Owner: Nobody in particular
Requestors: DANAJ [...] cpan.org
Cc:
AdminCc:

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



Subject: Problems with Math::BigInt gcd
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <rt-4.0.18-13713-1492836984-1006.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 251
Download (untitled) / with headers
text/plain 251b
After installing Math::BigInt::Lite, the following: perl -E 'use bigint; ($a,$b)=(8267,927208363107752634625923); say Math::BigInt::bgcd($a,$b);' instead of producing 1, now does: Can't use an undefined value as an ARRAY reference at ....
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-13713-1492836984-1006.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-13713-1492836984-1006.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-7956-1492883941-1973.121284-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 139
Download (untitled) / with headers
text/plain 139b
Thanks for the report. This is yet another case where the broken OO design in the Math::BigInt-related modules shows up. I'll look into it.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-7956-1492883941-1973.121284-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-13713-1492836984-1006.0-0-0 [...] rt.cpan.org> <rt-4.0.18-7956-1492883941-1973.121284-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-8985-1493058727-1833.121284-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1534
Download (untitled) / with headers
text/plain 1.4k
It appears that this is a very old bug. Behind the scenes, the original one-liner is equivalent to this: ---------------- use strict; use warnings; use 5.014; use Math::BigInt; use Math::BigInt::Lite; my $a = Math::BigInt::Lite -> new(8267); my $b = Math::BigInt -> new(927208363107752634625923); say Math::BigInt::bgcd($a, $b); ---------------- Math::BigInt::bgcd() first uses objectify() to ensure that all operands are objects() of the desired ("goal") class. In this case, objectify() is not given a desired class explicitly, so it assumes that the desired class is the class of the first operand, which is Math::BigInt::Lite. objectify() sets out to convert all the operands to Math::BigInt::Lite objects, but it accepts objects of classes that Math::BigInt::Lite may be upgraded to, i.e., Math::BigInt. The operand $a already is a Math::BigInt::Lite, and $b is a Math::BigInt, so objectify() does nothing to any of the operands. The operands are then passed back to Math::BigInt::bgcd(). So Math::BigInt::bgcd() is given a Math::BigInt::Lite ($a) and a Math::BigInt ($b), but Math::BigInt::bgcd() can't handle Math::BigInt::Lite objects, so the code fails. The solution seems to be to improve objectify() so it becomes better at guessing what the desired class is. One solution might be to use caller() to determine who called objectify(). A better solution, in my opinion, also happens to be a goal of of mine: to change all calls to objectify() into methods calls. That way, objectify() always knows the desired class.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-8985-1493058727-1833.121284-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-13713-1492836984-1006.0-0-0 [...] rt.cpan.org> <rt-4.0.18-7956-1492883941-1973.121284-0-0 [...] rt.cpan.org> <rt-4.0.18-8985-1493058727-1833.121284-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-3271-1493066991-1974.121284-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 478
Download (untitled) / with headers
text/plain 478b
Thanks for the detailed analysis! On Mon Apr 24 14:32:07 2017, pjacklam wrote: Show quoted text
> The solution seems to be to improve objectify() so it becomes better > at guessing what the desired class is.
This might be hard, as the same problem happens with blcm, and the theoretically best class would be different for the same arguments here. We don't know if ::Lite or not is best until we get the result back (since it could be either small or large). Just something to keep in mind.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.