Skip Menu |

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

Report information
The Basics
Id: 115761
Status: resolved
Priority: 0/
Queue: Math-Currency

People
Owner: Nobody in particular
Requestors: daniel [...] trustnetworks.co.uk
Cc:
AdminCc:

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



Subject: Overloaded bcmp incorrect
Date: Thu, 30 Jun 2016 16:51:23 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
Good afternoon Please see the following tests: trust-database:~ $ perl use Math::Currency; use feature qw/say/; my $small = new Math::Currency(10); my $large = new Math::Currency(100); say "$small $large"; say "small vs large = " . $small->bcmp($large); say "$small $large"; say "large vs small = " . $large->bcmp($small); say "$small $large"; #10.00 #100.00 small vs large = 1 #10.00 #100.00 large vs small = 1 #10.00 #100.00 trust-database:~ $ perl use Math::BigFloat; use feature qw/say/; my $small = new Math::BigFloat(10); my $large = new Math::BigFloat(100); say "$small $large"; say "small vs large = " . $small->bcmp($large); say "$small $large"; say "large vs small = " . $large->bcmp($small); say "$small $large"; 10 100 small vs large = -1 10 100 large vs small = 1 10 100 Notice that Math::Currency returns 1 for both large <=> small and small <=> large. The problem is thus: Math::BigFloat defines bcmp as follows: $x->bcmp($y); # compare numbers (undef, < 0, == 0, > 0) Your undocumented overridden function expects the following for older Math::BigInt versions: Math::Currency->bcmp($x, $y) I can see that either 0.48 resolved a compatibility issue with newer versions of BigInt, but you're only applying it to versions at least 1.999717. I am using Debian 8.4 with Perl 5.20.2 and this has BigInt 1.9993; the revised behaviour was certainly required for this version of BigInt. In fact, I don't even know what your original implementation of bcmp was intended to achieve: my PC has Perl 5.8.9 installed and bcmp in Math::BigInt even then was only expecting one parameter. I've worked around this by resetting _LEGACY_MATH_BIGINT to 0.
On Thu Jun 30 11:51:38 2016, daniel@trustnetworks.co.uk wrote: Show quoted text
> I can see that either 0.48 resolved a compatibility issue with newer > versions of BigInt, but you're only applying it to versions at least > 1.999717. I am using Debian 8.4 with Perl 5.20.2 and this has BigInt > 1.9993; the revised behaviour was certainly required for this version > of BigInt. In fact, I don't even know what your original > implementation of bcmp was intended to achieve: my PC has Perl 5.8.9 > installed and bcmp in Math::BigInt even then was only expecting one > parameter.
The problem that v0.48 solved is that Math::BigInt v1.999718 *completely* broke comparisons. See https://rt.cpan.org/Ticket/Display.html?id=115247 The _LEGACY_MATH_BIGINT was to attempt to be compliant with older releases as well as newer ones. Its possible 1.999717 is not the correct point where things broke perhaps? I'll see if I can narrow this down farther if so. Debian also has a history of patching modules so they do not match what is in CPAN. I don't know if that is the case here, but if they have patched Math::BigInt so it behaves differently from CPAN, its going to be very difficult to determine what _LEGACY_MATH_BIGINT should be set to. Otherwise, probably the best long term solution is going to be for Math::Currency to require at least Math::BigInt 1.999717 and do not support older versions any longer. -- Regards, Michael Schout
Subject: RE: [rt.cpan.org #115761] Overloaded bcmp incorrect
Date: Thu, 30 Jun 2016 17:10:22 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
The problem with your override is that you're converting bcmp from a one-arg function to a two-arg function, which destroys it. Your function should still accept one and only one parameter (the number to compare with) and *internally* mess about with parameters. Your corrections may need to internally make alterations to the true parameter list (including the package/object received as parameter one), but you're actually breaking the function's contract and rendering it completely inoperable. Show quoted text
> -----Original Message----- > From: MSCHOUT via RT [mailto:bug-Math-Currency@rt.cpan.org] > Sent: 30 June 2016 17:02 > To: Daniel Beardsmore > Subject: [rt.cpan.org #115761] Overloaded bcmp incorrect > > <URL: https://rt.cpan.org/Ticket/Display.html?id=115761 > > > On Thu Jun 30 11:51:38 2016, daniel@trustnetworks.co.uk wrote: >
> > I can see that either 0.48 resolved a compatibility issue with newer > > versions of BigInt, but you're only applying it to versions at least > > 1.999717. I am using Debian 8.4 with Perl 5.20.2 and this has BigInt > > 1.9993; the revised behaviour was certainly required for
> this version
> > of BigInt. In fact, I don't even know what your original > > implementation of bcmp was intended to achieve: my PC has Perl 5.8.9 > > installed and bcmp in Math::BigInt even then was only expecting one > > parameter.
> > The problem that v0.48 solved is that Math::BigInt v1.999718 > *completely* broke comparisons. See > https://rt.cpan.org/Ticket/Display.html?id=115247 > > The _LEGACY_MATH_BIGINT was to attempt to be compliant with > older releases as well as newer ones. > > Its possible 1.999717 is not the correct point where things > broke perhaps? I'll see if I can narrow this down farther if > so. Debian also has a history of patching modules so they do > not match what is in CPAN. I don't know if that is the case > here, but if they have patched Math::BigInt so it behaves > differently from CPAN, its going to be very difficult to > determine what _LEGACY_MATH_BIGINT should be set to. > > Otherwise, probably the best long term solution is going to > be for Math::Currency to require at least Math::BigInt > 1.999717 and do not support older versions any longer. > > -- > Regards, > Michael Schout >
Subject: RE: [rt.cpan.org #115761] Overloaded bcmp incorrect
Date: Thu, 30 Jun 2016 17:16:23 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
Something I didn't mention: 0.47 was also broken. The 0.48 fix didn't break it -- the function never worked at all. It always swallowed the first parameter (the nonexistent class parameter it thinks existed but doesn't) and expected two more parameters, causing a comparison with undef of everything. The function was thinking it was being called as Math::Currency->bcmp($x, $y), it seems, yet the docs for BigFloat/BigInt expect $x->bcmp($y), causing the function to be broken. 0.48 fixes the original bug, but only for newer BigInts. I had 0.47 before, and updated thinking the change fixed it, and found the function still broken. Show quoted text
> -----Original Message----- > From: MSCHOUT via RT [mailto:bug-Math-Currency@rt.cpan.org] > Sent: 30 June 2016 17:02 > To: Daniel Beardsmore > Subject: [rt.cpan.org #115761] Overloaded bcmp incorrect > > <URL: https://rt.cpan.org/Ticket/Display.html?id=115761 > > > On Thu Jun 30 11:51:38 2016, daniel@trustnetworks.co.uk wrote: >
> > I can see that either 0.48 resolved a compatibility issue with newer > > versions of BigInt, but you're only applying it to versions at least > > 1.999717. I am using Debian 8.4 with Perl 5.20.2 and this has BigInt > > 1.9993; the revised behaviour was certainly required for
> this version
> > of BigInt. In fact, I don't even know what your original > > implementation of bcmp was intended to achieve: my PC has Perl 5.8.9 > > installed and bcmp in Math::BigInt even then was only expecting one > > parameter.
> > The problem that v0.48 solved is that Math::BigInt v1.999718 > *completely* broke comparisons. See > https://rt.cpan.org/Ticket/Display.html?id=115247 > > The _LEGACY_MATH_BIGINT was to attempt to be compliant with > older releases as well as newer ones. > > Its possible 1.999717 is not the correct point where things > broke perhaps? I'll see if I can narrow this down farther if > so. Debian also has a history of patching modules so they do > not match what is in CPAN. I don't know if that is the case > here, but if they have patched Math::BigInt so it behaves > differently from CPAN, its going to be very difficult to > determine what _LEGACY_MATH_BIGINT should be set to. > > Otherwise, probably the best long term solution is going to > be for Math::Currency to require at least Math::BigInt > 1.999717 and do not support older versions any longer. > > -- > Regards, > Michael Schout >
On Thu Jun 30 12:16:40 2016, daniel@trustnetworks.co.uk wrote: Show quoted text
> Something I didn't mention: 0.47 was also broken.
Understood, thanks -- Regards, Michael Schout
Subject: RE: [rt.cpan.org #115761] Overloaded bcmp incorrect
Date: Thu, 30 Jun 2016 18:33:29 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
OK, here's a workaround: sub bcmp { my $class = $#_ == 2 ? shift : __PACKAGE__; # make sure we're dealing with two Math::Currency objects my ( $x, $y ) = map { ref $_ ne $class ? $class->new($_) : $_ } @_[ 0, 1 ]; return $x->as_float <=> $y->as_float; } Cause: The OOP contract stipulates that bcmp takes one parameter, the number for comparison. This is how the method functions when called by a client. Math::BigInt 1.9993 also passes the package name as an extra parameter when using bcmp to implement == through overloading -- this means that the function will either fail for bcmp or fail for == and will never work for both at the same time. This is true of both 0.47 and 0.49. The above quick hack checks for the parameter count: if the true count is 3, then the first one is shifted off as the class, allowing the function to continue working as expected. I may have a rogue version of BigInt -- I don't know. Clearly something is very wrong in Camel Land. I've attached a copy of all of /usr/share/perl/5.20.2/Math in case it helps! Cheers Daniel. Show quoted text
> -----Original Message----- > From: MSCHOUT via RT [mailto:bug-Math-Currency@rt.cpan.org] > Sent: 30 June 2016 17:02 > To: Daniel Beardsmore > Subject: [rt.cpan.org #115761] Overloaded bcmp incorrect > > <URL: https://rt.cpan.org/Ticket/Display.html?id=115761 > > > On Thu Jun 30 11:51:38 2016, daniel@trustnetworks.co.uk wrote: >
> > I can see that either 0.48 resolved a compatibility issue with newer > > versions of BigInt, but you're only applying it to versions at least > > 1.999717. I am using Debian 8.4 with Perl 5.20.2 and this has BigInt > > 1.9993; the revised behaviour was certainly required for
> this version
> > of BigInt. In fact, I don't even know what your original > > implementation of bcmp was intended to achieve: my PC has Perl 5.8.9 > > installed and bcmp in Math::BigInt even then was only expecting one > > parameter.
> > The problem that v0.48 solved is that Math::BigInt v1.999718 > *completely* broke comparisons. See > https://rt.cpan.org/Ticket/Display.html?id=115247 > > The _LEGACY_MATH_BIGINT was to attempt to be compliant with > older releases as well as newer ones. > > Its possible 1.999717 is not the correct point where things > broke perhaps? I'll see if I can narrow this down farther if > so. Debian also has a history of patching modules so they do > not match what is in CPAN. I don't know if that is the case > here, but if they have patched Math::BigInt so it behaves > differently from CPAN, its going to be very difficult to > determine what _LEGACY_MATH_BIGINT should be set to. > > Otherwise, probably the best long term solution is going to > be for Math::Currency to require at least Math::BigInt > 1.999717 and do not support older versions any longer. > > -- > Regards, > Michael Schout >
Download Math.zip
application/x-zip-compressed 132.3k

Message body not shown because it is not plain text.

Subject: RE: [rt.cpan.org #115761] Overloaded bcmp incorrect
Date: Thu, 30 Jun 2016 18:33:52 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
It might be that BigInt is itself broken! Show quoted text
> -----Original Message----- > From: MSCHOUT via RT [mailto:bug-Math-Currency@rt.cpan.org] > Sent: 30 June 2016 18:30 > To: Daniel Beardsmore > Subject: [rt.cpan.org #115761] Overloaded bcmp incorrect > > <URL: https://rt.cpan.org/Ticket/Display.html?id=115761 > > > On Thu Jun 30 12:16:40 2016, daniel@trustnetworks.co.uk wrote:
> > Something I didn't mention: 0.47 was also broken.
> > Understood, thanks > -- > Regards, > Michael Schout >
Ok, here's whats going on. Even though Math::BigInt documents bcmp() as a one-arg object method, it was not always used this way. In Math::BigInt, the overload of operator <=> in 1.99, it was called as: ref($_[0])->bcmp($_[0],$_[1]) In 1.999718 the overload of <=> in BigInt was changed to: $_[0]->bcmp($_[1]) These two ways that bcmp() might get called break the signature of bcmp in an incompatible way. It seems the best choice is to use your proposed solution and check the number of args to bcmp() moving forward. This fixes things so bcmp() works as an object method, and also that <=> overloading works in both old and new Math::BigInt versions. I'll have something released tomorrow sometime. Thanks for your patience. -- Regards, Michael Schout
Subject: RE: [rt.cpan.org #115761] Overloaded bcmp incorrect
Date: Fri, 1 Jul 2016 08:22:04 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
I figured it was something like that as soon as I noticed that my fix broke the use of ==. Show quoted text
> -----Original Message----- > From: MSCHOUT via RT [mailto:bug-Math-Currency@rt.cpan.org] > Sent: 01 July 2016 06:19 > To: Daniel Beardsmore > Subject: [rt.cpan.org #115761] Overloaded bcmp incorrect > > <URL: https://rt.cpan.org/Ticket/Display.html?id=115761 > > > Ok, here's whats going on. > > Even though Math::BigInt documents bcmp() as a one-arg object > method, it was not always used this way. > > In Math::BigInt, the overload of operator <=> in 1.99, it was > called as: > > ref($_[0])->bcmp($_[0],$_[1]) > > In 1.999718 the overload of <=> in BigInt was changed to: > > $_[0]->bcmp($_[1]) > > These two ways that bcmp() might get called break the > signature of bcmp in an incompatible way. > > It seems the best choice is to use your proposed solution and > check the number of args to bcmp() moving forward. This > fixes things so bcmp() works as an object method, and also > that <=> overloading works in both old and new Math::BigInt versions. > > I'll have something released tomorrow sometime. > > Thanks for your patience. > > -- > Regards, > Michael Schout >
This has been fixed in v0.50 which I released to CPAN yesterday. Let me know if you still have problems. Thanks -- Regards, Michael Schout
Subject: RE: [rt.cpan.org #115761] Overloaded bcmp incorrect
Date: Wed, 6 Jul 2016 20:00:44 +0100
To: "bug-Math-Currency [...] rt.cpan.org" <bug-Math-Currency [...] rt.cpan.org>
From: Daniel Beardsmore <daniel [...] trustnetworks.co.uk>
I can see that there's a lot more changed in that file than just argument check, so hopefully no new bugs :) The test I put in place to look for ==/bcmp errors passes with the new module, so fingers crossed! Cheers. Show quoted text
> -----Original Message----- > From: MSCHOUT via RT [mailto:bug-Math-Currency@rt.cpan.org] > Sent: 05 July 2016 15:23 > To: Daniel Beardsmore > Subject: [rt.cpan.org #115761] Overloaded bcmp incorrect > > <URL: https://rt.cpan.org/Ticket/Display.html?id=115761 > > > This has been fixed in v0.50 which I released to CPAN yesterday. > > Let me know if you still have problems. > > Thanks > -- > Regards, > Michael Schout >
On Wed Jul 06 15:00:57 2016, daniel@trustnetworks.co.uk wrote: Show quoted text
> I can see that there's a lot more changed in that file than just > argument check, so hopefully no new bugs :)
FWIW, the vast majority of hte code changes are just cleanups / formatting. I've taken this module over recently and 0.50 is the first release from me that is built using Dist::Zilla which generates most of the POD and other files like README/LICENSE, Makefile.PL etc. If you are just diffing the distribution tarballs there will be a LOT of diffs due to that. Show quoted text
> The test I put in place to look for ==/bcmp errors passes with the new > module, so fingers crossed!
Your tests are included in t/010_bcmp.t FYI I have not seen a single failure of 0.50 from cpantesters yet (288 passes), so things are looking good so far. I'm going to resolve this ticket as I consider the issue this ticket refers to resolved in 0.50. If you run into another issue please open a new ticket. -- Regards, Michael Schout