Skip Menu |

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

Report information
The Basics
Id: 121139
Status: resolved
Priority: 0/
Queue: Math-BigRat

People
Owner: Nobody in particular
Requestors: haffread [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in:
  • 0.2612
  • 0.2611
  • 0.260805
  • 0.2609
  • 0.2610
Fixed in: 0.2613



Subject: Problem with operator values being changed
Date: Sat, 15 Apr 2017 09:34:07 +0100
To: bug-math-bigrat [...] rt.cpan.org
From: Paul Haffenden <haffread [...] gmail.com>
Hello, I'm using strawberry perl on windows 7 This is perl 5, version 24, subversion 1 (v5.24.1) built for MSWin32-x86-multi-thread-64int Copyright 1987-2017, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. And I'm having a problem with this little piece of example code, in that $maxpts is getting changed unexpectedly after the multiplication: ============================== use strict; use warnings; use Math::BigRat; sub main { my($pts) = Math::BigRat->new("61/4"); my($maxpts) = Math::BigRat->new("40/1"); print("BigRat varsion: $Math::BigRat::VERSION\n"); my($tmp) = $pts->copy(); print("$tmp $maxpts\n"); $tmp = $tmp * $maxpts; print("$tmp $maxpts\n"); } main(); exit(0); ====================== When I run it I get: BigRat varsion: 0.2612 61/4 40 610 10 But if I change the initial value of $maxpts to '5/1' say, then $maxpts doesn't change after the multiplication. Paul.
This is a very severe problem. I have added a smaller test script. Using Math::BigRat version 0.2612, it prints: 1..2 # Math::BigRat version is 0.2612 ok 1 not ok 2 # Failed test at t/11a_math_bigrat.t line 16. # got: '1' # expected: '3/2' # Looks like you failed 1 test of 2. Using Math::BigRat version 0.2608, it prints: 1..2 # Math::BigRat version is 0.2612 ok 1 not ok 2 # Failed test at t/11a_math_bigrat.t line 16. # got: '1' # expected: '3/2' # Looks like you failed 1 test of 2. Regards, Martin
Subject: bigrat.t
#!/usr/bin/perl use strict; use warnings; use Test::More tests => 2; use Math::BigRat; diag('Math::BigRat version is ' . Math::BigRat->VERSION); my $a = Math::BigRat->new('3/2'); my $x = Math::BigRat->new('2/3'); is("$a", "3/2"); my $y = $a; $y = $x * $y; is("$a", "3/2");
Using Math::BigRat version 0.2608, it prints: 1..2 # Math::BigRat version is 0.2608 ok 1 ok 2 Regards, Martin
Subject: [PATCH] Problem with operator values being changed
I found the problem. The bmul method modified its second argument. I have added a patch. -Martin
Subject: Math-BigRat-0.2612-MHASCH-01.patch
diff -Nrup Math-BigRat-0.2612.orig/lib/Math/BigRat.pm Math-BigRat-0.2612/lib/Math/BigRat.pm --- Math-BigRat-0.2612.orig/lib/Math/BigRat.pm 2017-03-01 12:48:14.000000000 +0100 +++ Math-BigRat-0.2612/lib/Math/BigRat.pm 2017-05-31 23:08:10.666505683 +0200 @@ -887,9 +887,9 @@ sub bmul { my $gcd_sq = $LIB -> _gcd($LIB -> _copy($y->{_n}), $x->{_d}); $x->{_n} = $LIB -> _mul(scalar $LIB -> _div($x->{_n}, $gcd_pr), - scalar $LIB -> _div($y->{_n}, $gcd_sq)); + scalar $LIB -> _div($LIB -> _copy($y->{_n}), $gcd_sq)); $x->{_d} = $LIB -> _mul(scalar $LIB -> _div($x->{_d}, $gcd_sq), - scalar $LIB -> _div($y->{_d}, $gcd_pr)); + scalar $LIB -> _div($LIB -> _copy($y->{_d}), $gcd_pr)); # compute new sign $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; diff -Nrup Math-BigRat-0.2612.orig/t/rt121139.t Math-BigRat-0.2612/t/rt121139.t --- Math-BigRat-0.2612.orig/t/rt121139.t 1970-01-01 01:00:00.000000000 +0100 +++ Math-BigRat-0.2612/t/rt121139.t 2017-05-31 23:09:53.626885108 +0200 @@ -0,0 +1,16 @@ +#!perl + +# check for cpan rt #121139 + +use strict; +use warnings; +use Test::More tests => 2; +use Math::BigRat; + +my $a = Math::BigRat->new('3/2'); +my $x = Math::BigRat->new('2/3'); +is("$a", "3/2"); + +my $y = $a; +$y = $x * $y; +is("$a", "3/2");