Bug#723021: [rt.cpan.org #78653] Bug#723021: String::Koremutake: Does not handle large numbers

Axel Beckert abe at debian.org
Sun Sep 15 14:40:46 UTC 2013


Hi,

I'm taking the upstream bug report at CPAN's RT into Cc, so slightly
adapting the subject.

Axel Beckert wrote:
> Axel Beckert wrote:
> > "use bigint;" suffices to solve the issue:
> > 
> > perl -Mbigint -MString::Koremutake -le '...'
> [...]
> > Despite this should be fixed upstream (see RT bug report), I think we
> > can solve this in the package easily and don't have to wait for
> > upstream.
> > 
> > I'll likely take care of it soon.
> 
> While thinking about it, I'm no more sure if this really should go
> into the package and "use bigint;" should rather be at the
> responsibility of the programmer using the package as it suffices to
> call "use bigint;" outside the package anyway.

We discussed this briefly at #debian-perl on IRC and came to the
conclusion that this is not really a bug in the module itself but
rather at the responsibility of the programmer or caller to "use
bigint;" if the programm needs that large integers as it's the case
with the remainder of Perl, too.

Nevertheless we do think that this is definitely worth some entry in
the POD of String::Koremutake under e.g. CAVEATS.

My suggestion for a wording:

---snip---
CAVEATS

You need to "use bigint;" if you want String::Koremutake to work with
integers larger than what fits into a normal Perl integer before it
gets converted to a floating point number on your platform.

Example:

Without "use bigint;" big integers get converted to fixed precision
floating point numbers:

$ perl -MString::Koremutake -le 'my $a = 65536**4; my $k = String::Koremutake->new; foreach my $b ($a, $a+1, $a+2, $a+3) { print "$b: ".$k->integer_to_koremutake($b); }'
1.84467440737096e+19: bibababababababababa
1.84467440737096e+19: bibababababababababa
1.84467440737096e+19: bibababababababababa
1.84467440737096e+19: bibababababababababa

If you use that large integers, you should add "use bigint;" to your
program which solves that issue:

$ perl -Mbigint -MString::Koremutake -le 'my $a = 65536**4; my $k = String::Koremutake->new; foreach my $b ($a, $a+1, $a+2, $a+3) { print "$b: ".$k->integer_to_koremutake($b); }'
18446744073709551616: bibababababababababa
18446744073709551617: bibababababababababe
18446744073709551618: bibababababababababi
18446744073709551619: bibababababababababo

It will likely save you from other issues with big integers, too.

Note that "foreach my $b ($a .. $a+3)" doesn't work either as the ".."
operator can't be overloaded. See CAVEATS in "perldoc bigint" for
details.
---snap---

		Regards, Axel
-- 
 ,''`.  |  Axel Beckert <abe at debian.org>, http://people.debian.org/~abe/
: :' :  |  Debian Developer, ftp.ch.debian.org Admin
`. `'   |  1024D: F067 EA27 26B9 C3FC 1486  202E C09E 1D89 9593 0EDE
  `-    |  4096R: 2517 B724 C5F6 CA99 5329  6E61 2FF9 CD59 6126 16B5



More information about the pkg-perl-maintainers mailing list