Subject: | BigInt documentation is a tad misleading for brsft |

Date: | Mon, 11 Oct 2010 19:04:00 +0200 |

To: | bug-Math-BigInt [...] rt.cpan.org |

From: | Test <Test [...] globis.net> |

Package: Math::BigInt
Distribution: straight from cpan.
Verison: 1.89
Thanks for the code. I'm grateful. Honest. But I did encounter a wee
disappointment.
The html documentation seems to state:
brsft()
<http://search.cpan.org/%7Eflora/Math-BigInt-1.96/lib/Math/BigInt.pm#___top>
$x->brsft($y,$n);
Shifts $x right by $y in base $n. Default is base 2, used are usually 10
and 2, but others work, too.
But looking in the pod documentation in the distrution package: line
3183 of the synopsis states
$x->brsft($y); # right shift in base 2
# returns (quo,rem) or quo if in scalar context
However, the real working code does not seem to be at all context
sensitive i.e. it never returns rem (comes back as undef)
I find this is a bit of a shame for simple situations where you want to
take the first and second nibble e.g. like stripping out the first and
second 64 bits of an IPv6 address to be stored in a MySQL database which
can't handle 128 bits in one integer.
I ended up using:
sub IP_to_db {
# make sure the input really is a bigint
my $bint = Math::BigInt->new(shift);
my $top_nibble=Math::BigInt->new(1);
$top_nibble->blsft(64); # left shift 64 bits
my $nibble_a;
my $nibble_b;
($nibble_a,$nibble_b)= $bint->bdiv($top_nibble); # split into 2*64
bits for MySQL
which is probably a lot less efficient than
my $nibble_a;
my $nibble_b;
($nibble_a,$nibble_b)= $bint->brsft(64);
(depending on the internal representation of course)
redards,