Another issue I'm noticing... Technically, I'm not sure if this is a Math::BigInt bug, or an Overload bug, but it can be fixed (or atleast worked around) in Math::BigInt.
Anyhow, I am deriving a class BigVal from Math::BigInt. When I do certain
base 2 brsft's for negative numbers using this class, I get the wrong result. I have tracked down the problem to the fact that overloaded comparison of a BigVal against an int only works if the BigVal appears first. For a Math::BigInt, the order doesn't matter. A fix is to change line 1805 of BigInt.pm to
if ($y >= CORE::length($bin)) {
Test case:
#!/usr/local/bin/perl5.8.6 -w
use Math::BigInt lib => 'GMP';
@BigVal::ISA = qw(Math::BigInt);
my $x = new BigVal(1);
my $y = new Math::BigInt(1);
print "(3<=x) =>", 3 <= $x, "\n"; # wrong!
print "(3<=y) =>", 3 <= $y, "\n";
print "(x>=3) =>", $x >= 3, "\n";
print "(y>=3) =>", $y >= 3, "\n";
my $v1 = new BigVal("0x100000000")->bneg->brsft(31);
my $v2 = new Math::BigInt("0x100000000")->bneg->brsft(31);
$v1 != $v2 and print "Something wrong!\n";
package BigVal;
use overload;
output:
Use of uninitialized value in numeric le (<=) at /home/jrob/junk/test2.pl line 9.
(3<=x) =>1
(3<=y) =>
(x>=3) =>
(y>=3) =>
Use of uninitialized value in numeric le (<=) at BigInt.pm line 1805.
Something wrong!
can give the wrong result