Skip Menu |

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

Report information
The Basics
Id: 68067
Status: resolved
Priority: 0/
Queue: Math-BaseCalc

People
Owner: Nobody in particular
Requestors: bunk [...] novozymes.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.014
Fixed in: (no value)



Hi It seems that to_base has issues with large integers. I've tested by converting 2^63-1 into base 36, but the second last digit ('e' below) becomes a '0' instead of an 'e' as expected. my $int = 9223372036854775807; # 2^63-1 my $int_base36 = '1y2p0ij32e8e7'; # 2^63-1 in base 36 my $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z']); my $base36 = $calc36->to_base($int); After this, I expect $base36 and $int_base36 to have the same value. They don't. from_base works fine for converting the other way. Please see the attached test for a bit more elaborate roundtrip test case. Best regards Jacob
Subject: large_int_base36.t
use Test::More tests=>5; use strict; use warnings; use_ok('Math::BaseCalc'); is($Math::BaseCalc::VERSION, '1.014', "Lastest version"); my $int = 9223372036854775807; # 2^63-1 my $int_base36 = '1y2p0ij32e8e7'; my $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z']); my $base36 = $calc36->to_base($int); is($base36,$int_base36, "to_base has done proper conversion of $int"); my $int2 = $calc36->from_base($base36); is($int2,$int, "$int has roundtripped"); $int2 = $calc36->from_base($int_base36); is($int2, $int, "from_base correct for $int_base36 ($int)");
Subject: Problem with large numbers
Thanks Jacob, looks like this is caused by an auto-conversion to a floating point number inside to_base(), which I've eliminated by adding a 'use integer;'. For good measure, are you able to test the copy in SVN, at http://perl-math-basecalc.googlecode.com/svn/trunk ? -Ken
Subject: Fixed
From: bunk [...] novozymes.com
On Tue May 10 14:51:46 2011, KWILLIAMS wrote: Show quoted text
> Thanks Jacob, looks like this is caused by an auto-conversion to a > floating point number inside to_base(), which I've eliminated by adding > a 'use integer;'. > > For good measure, are you able to test the copy in SVN, at > http://perl-math-basecalc.googlecode.com/svn/trunk ?
Great! Thanks for a quick response. I can confirm that the bug seems to have been fixed in the code in SVN. Best regards Jacob P.S. Sorry for failing to set a subject for the ticket, I missed that input box while creating the ticket.
Subject: Fixed?
Ditto here. Looks like the ticket got re-opened for some reason, but it should be resolved.
Yes, thanks.