Skip Menu |

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

Report information
The Basics
Id: 60838
Status: open
Priority: 0/
Queue: Math-BigRat

People
Owner: Nobody in particular
Requestors: hasch-cpan [...] cozap.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.24
Fixed in: 0.2602



Subject: should bit operations make Math::BigRat crash?
Hello, I think there is an issue with some overloaded operations Math::BigRat inherits from Math::BigInt but fails to properly override. Test Code follows: use Math::BigRat; $x = Math::BigRat->new('1') | 0; Can't use an undefined value as an ARRAY reference at .../Math/BigInt/Calc.pm line 1175. Math::BigInt::Calc::_acmp('Math::BigInt::FastCalc', undef, undef) called at .../Math/BigInt/Calc.pm line 2142 Math::BigInt::Calc::_or('Math::BigInt::FastCalc', undef, undef) called at .../Math/BigInt.pm line 2105 Math::BigInt::bior('Math::BigRat=HASH(0x80fb0c)', 0) called at .../Math/BigInt.pm line 129 Math::BigInt::__ANON__('Math::BigRat=HASH(0x803030)', 0, '') called at test.pl line 2 I had expected an error message telling me that "bitwise or" is not implemented for rationals, or, since this particular value is actually an integer, success. I am using Math::BigRat version 0.24, Math::BigInt version 1.89_01, perl 5.12.1. -Martin
Hello again, I noticed this might actually be a Math::BigFloat / Math::BigInt issue, see rt.cpan.org #59615. -Martin
On Sat Aug 28 13:53:11 2010, MHASCH wrote: Show quoted text
> Hello, > > I think there is an issue with some overloaded operations Math::BigRat > inherits from Math::BigInt but fails to properly override. Test Code > follows: > > use Math::BigRat; > $x = Math::BigRat->new('1') | 0; > > Can't use an undefined value as an ARRAY reference at > .../Math/BigInt/Calc.pm line > 1175. > > I had expected an error message telling me that "bitwise or" is not > implemented for > rationals, or, since this particular value is actually an integer, > success.
Math::BigRat 0.2601 displays error (this change is not documented in Changes). -- Alexandr Ciornii, http://chorny.net
Currently, Math::BigRat and Math::BigFloat inherit from Math::BigInt. I consider this a design flaw and has caused several bugs, including this one. If I remember correctly, the only method it makes sense to inherit from Math::BigInt is sign(). Math::BigRat and Math::BigFloat also use some utility functions in Math::BigInt. I think a good start is to create a virtual parent class, e.g., Math::BigNum, and move sign() and the utility functions into that namespace, and let Math::BigInt, Math::BigRat, and Math::BigFloat inherit from this virtual parent class.