develooper Front page | perl.perl5.porters | Postings from March 2007

[perl #42260] power-of two differences in minus operation

Thread Next
From:
jhh
Date:
March 31, 2007 16:47
Subject:
[perl #42260] power-of two differences in minus operation
Message ID:
rt-3.6.HEAD-1687-1175372773-820.42260-75-0@perl.org
# New Ticket Created by  jhh 
# Please include the string:  [perl #42260]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42260 >


This is a bug report for perl from jan-perl@h-i-s.nl,
generated with the help of perlbug 1.35 running under perl v5.8.8.


-----------------------------------------------------------------
[Please enter your report here]

The minus operator creates strange results for the given example.
Using bignum or bigint does not change the results.
For the given program, running perl v5.6.1 on an old pentium-90 gave the
expected output in the last two colums: the samen value as in the first
column, and zero respectively.
The example program reads a multiplier from the first line, and then
verifies the relation $val[4] == $val[0] * mult + $val[1]

example program:

#!/usr/bin/perl -w

$mul=<STDIN>;
$mul+=0;
$hdrlin=<STDIN>;
    print "${mul}\n${hdrlin}";
while ($readlin = <STDIN> ) {
    @vals =split(/\t/,$readlin);
    my $diff= ($vals[4] - $vals[1] ) - $vals[0]*$mul;
    my $v1m=sprintf ("%.0f",$vals[0]*$mul);
    my $v1c=sprintf ("%.0f",($vals[0]*$mul+$vals[1]));
    my $d1=sprintf ("%.0f", ($vals[4] - $vals[1] ) );
    print "$vals[0]\t$vals[1]\t$v1m\t$v1c\t$vals[4]\t$d1\t$diff\n";
}

example input:

4294967296
v1	v2	v1m	v1c	v1g	d1	diff
104712103	50	449735057880383488	449735057880383552	449735057880383538	0	-64
108391849	154	465539446607970304	465539446607970432
465539446607970458	192	64
108391849	159	465539446607970304	465539446607970432
465539446607970463	192	64
108391849	219	465539446607970304	465539446607970496
465539446607970523	256	64
112424657	21	482860225079017472	482860225079017472	482860225079017493	64	64
112424657	25	482860225079017472	482860225079017472	482860225079017497	64	64
113036199	53	485486777969147904	485486777969147968	485486777969147957	128	64
113036199	56	485486777969147904	485486777969147968	485486777969147960	128	64
114286490	102	490856736924631040	490856736924631168
490856736924631142	64	-64
114286490	105	490856736924631040	490856736924631168
490856736924631145	64	-64
114286490	108	490856736924631040	490856736924631168
490856736924631148	64	-64
114286490	114	490856736924631040	490856736924631168
490856736924631154	64	-64
114286490	98	490856736924631040	490856736924631168	490856736924631138	64	-64
116114550	207	498708194839756800	498708194839756992
498708194839757007	256	64
1454437274	498	6246760525913391104	6246760525913391104
6246760525913391602	1024	1024
1685221006	5	7237969107302219776	7237969107302219776
7237969107302219781	0	-1024
1689676942	5	7257107206695288832	7257107206695288832
7257107206695288837	0	1024

example output (WRONG, from given perl version)

4294967296
v1	v2	v1m	v1c	v1g	d1	diff
104712103	50	449735057880383488	449735057880383552	449735057880383538
449735057880383424	-64
108391849	154	465539446607970304	465539446607970432
465539446607970458	465539446607970368	64
108391849	159	465539446607970304	465539446607970432
465539446607970463	465539446607970368	64
108391849	219	465539446607970304	465539446607970496
465539446607970523	465539446607970368	64
112424657	21	482860225079017472	482860225079017472	482860225079017493
482860225079017536	64
112424657	25	482860225079017472	482860225079017472	482860225079017497
482860225079017536	64
113036199	53	485486777969147904	485486777969147968	485486777969147957
485486777969147968	64
113036199	56	485486777969147904	485486777969147968	485486777969147960
485486777969147968	64
114286490	102	490856736924631040	490856736924631168
490856736924631142	490856736924630976	-64
114286490	105	490856736924631040	490856736924631168
490856736924631145	490856736924630976	-64
114286490	108	490856736924631040	490856736924631168
490856736924631148	490856736924630976	-64
114286490	114	490856736924631040	490856736924631168
490856736924631154	490856736924630976	-64
114286490	98	490856736924631040	490856736924631168	490856736924631138
490856736924630976	-64
116114550	207	498708194839756800	498708194839756992
498708194839757007	498708194839756864	64
1454437274	498	6246760525913391104	6246760525913391104
6246760525913391602	6246760525913392128	1024
1685221006	5	7237969107302219776	7237969107302219776
7237969107302219781	7237969107302218752	-1024
1689676942	5	7257107206695288832	7257107206695288832
7257107206695288837	7257107206695289856	1024


Correct output (as from the old perl on the old computer)

4294967296
v1	v2	v1m	v1c	v1g	d1	diff
104712103	50	449735057880383488	449735057880383552	449735057880383538
449735057880383488	0
108391849	154	465539446607970304	465539446607970432
465539446607970458	465539446607970304	0
108391849	159	465539446607970304	465539446607970432
465539446607970463	465539446607970304	0
108391849	219	465539446607970304	465539446607970496
465539446607970523	465539446607970304	0
112424657	21	482860225079017472	482860225079017472	482860225079017493
482860225079017472	0
112424657	25	482860225079017472	482860225079017472	482860225079017497
482860225079017472	0
113036199	53	485486777969147904	485486777969147968	485486777969147957
485486777969147904	0
113036199	56	485486777969147904	485486777969147968	485486777969147960
485486777969147904	0
114286490	102	490856736924631040	490856736924631168
490856736924631142	490856736924631040	0
114286490	105	490856736924631040	490856736924631168
490856736924631145	490856736924631040	0
114286490	108	490856736924631040	490856736924631168
490856736924631148	490856736924631040	0
114286490	114	490856736924631040	490856736924631168
490856736924631154	490856736924631040	0
114286490	98	490856736924631040	490856736924631168	490856736924631138
490856736924631040	0
116114550	207	498708194839756800	498708194839756992
498708194839757007	498708194839756800	0
1454437274	498	6246760525913391104	6246760525913391104
6246760525913391602	6246760525913391104	0
1685221006	5	7237969107302219776	7237969107302219776
7237969107302219781	7237969107302219776	0
1689676942	5	7257107206695288832	7257107206695288832
7257107206695288837	7257107206695288832	0






[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
     category=core
     severity=high
---
Site configuration information for perl v5.8.8:

Configured by Debian Project at Fri Jul  7 18:20:22 UTC 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
   Platform:
     osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
     uname='linux rothera 2.6.15.7 #1 smp tue jun 27 18:34:43 utc 2006
i686 gnulinux '
     config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN
-Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr
-Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8
-Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5
-Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local
-Dsitelib=/usr/local/share/perl/5.8.8
-Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1
-Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1
-Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl
-Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm
-Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=undef use64bitall=undef uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
     optimize='-O2',
     cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN
-fno-strict-aliasing -pipe -I/usr/local/include'
     ccversion='', gccversion='4.1.2 20060613 (prerelease) (Ubuntu
4.1.1-2ubuntu5)', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
     alignbytes=4, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -L/usr/local/lib'
     libpth=/usr/local/lib /lib /usr/lib
     libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
     perllibs=-ldl -lm -lpthread -lc -lcrypt
     libc=/lib/libc-2.4.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
     gnulibc_version='2.4'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
     cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.8:
     /etc/perl
     /usr/local/lib/perl/5.8.8
     /usr/local/share/perl/5.8.8
     /usr/lib/perl5
     /usr/share/perl5
     /usr/lib/perl/5.8
     /usr/share/perl/5.8
     /usr/local/lib/site_perl
     .

---
Environment for perl v5.8.8:
     HOME=/home/jhh
     LANG=en_US.UTF-8
     LANGUAGE=en_NL:en
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
     PERL_BADLANG (unset)
     SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About