Subject: | wrong factors for near-64-bit value |
The following test script looks to show an(other?) off-by-2^^63 bug; I'll try to diagnose it too, but not sure how quick that'll go. (Embarrassingly, I found I was still on v0.28 when I spotted it, but the results are the same with v0.56 as the script demonstrates. I haven't tested against latest github version.)
% /path/to/perl testprog
source 12874555777890293787 (3 ^ 1 . 4243 ^ 2 . 488239 ^ 2)
dest 3651183741035517979 (19 ^ 4 . 28016848712299 ^ 1)
source hex b2ab9c44861a981b
dest hex 32ab9c44861a981b
% cat testprog
#!/path/to/perl -w
use strict;
use Math::GMP 2.11;
use Math::Prime::Util 0.56;
my $input_primes = [ [ 3, 1 ], [ 4243, 2 ], [ 488239, 2 ] ];
my $source = unfactor($input_primes);
my $source_hex = hexify($source);
my $output_primes = [ Math::Prime::Util::factor_exp($source) ];
my $dest = unfactor($output_primes);
my $dest_hex = hexify($dest);
print <<EOF;
source $source (@{[ _report($input_primes) ]})
dest $dest (@{[ _report($output_primes) ]})
source hex $source_hex
dest hex $dest_hex
EOF
sub unfactor {
my($f) = @_;
my $p = Math::GMP->new(1);
$p *= $_->[0] ** $_->[1] for @$f;
return $p;
}
sub hexify {
my($n) = @_;
my @dig;
do { push @dig, $n % 16; $n = int($n / 16) } while $n;
return join '', map [ 0 .. 9, 'a' .. 'f' ]->[$_], reverse @dig;
}
sub _report {
return join ' . ', map "$_->[0] ^ $_->[1]", @{ +shift };
}
% /path/to/perl -V
Summary of my perl5 (revision 5 version 18 subversion 4) configuration:
Platform:
osname=linux, osvers=3.13.0-37-generic, archname=x86_64-linux
uname='linux shad2 3.13.0-37-generic #64-ubuntu smp mon sep 22 21:28:38 utc 2014 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Dprefix=/opt/maths-5.18.4 -Doptimize=-g -O6 -Dusedevel -Uversiononly'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-g -O6',
cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.8.2', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.19'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -g -O6 -L/usr/local/lib -fstack-protector'
Characteristics of this binary (from libperl):
Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_MALLOC_WRAP
PERL_PRESERVE_IVUV PERL_SAWAMPERSAND PERL_USE_DEVEL
USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES
USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
Built under linux
Compiled at Oct 23 2014 13:41:14
@INC:
/opt/maths-5.18.4/lib/perl5/site_perl/5.18.4/x86_64-linux
/opt/maths-5.18.4/lib/perl5/site_perl/5.18.4
/opt/maths-5.18.4/lib/perl5/5.18.4/x86_64-linux
/opt/maths-5.18.4/lib/perl5/5.18.4
.
%