
perlbug-followup at perl
Jan 18, 2007, 6:57 AM
Post #1 of 4
(266 views)
Permalink
|
|
[perl #41288] integer-valued float not treated as int
|
|
# New Ticket Created by Zefram # Please include the string: [perl #41288] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41288 > This is a bug report for perl from zefram [at] fysh, generated with the help of perlbug 1.35 running under perl v5.8.8. ----------------------------------------------------------------- [Please enter your report here] On a Perl with 64-bit IV and 64-bit NV (1+52 bit significand): $ perl -lwe '$a = 18446744073709549568; printf "%u\n", $a-1' 18446744073709549567 $ perl -lwe '$a = 2**64 - 2**11; printf "%u\n", $a-1' 18446744073709549568 $a gets the same numerical value in both cases, but the first time it is as a native integer and the second time as a native float. perlnumber(1) says: # The binary operators ... "-" ... will attempt to convert arguments to # integers. If both conversions are possible without loss of precision, # and the operation can be performed without loss of precision then the # integer result is used. So I'd expect that in both cases the subtraction would be done in integer arithmetic and yield a mathematically exact integer result. That actually only happens in the first case. In the second case it appears that the subtraction was done in float arithmetic, where the exact result is not representable. This only happens at the extreme positive end of the native integer range. Around +2^63 everything works nominally, and also around -2^63 at the extreme negative end of the native integer range. [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=medium --- Site configuration information for perl v5.8.8: Configured by zefram at Tue Jan 16 13:21:19 GMT 2007. Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=linux, osvers=2.6.14-gentoo-r5, archname=i686-linux-thread-multi-64int uname='linux shilling.local 2.6.14-gentoo-r5 #1 smp preempt thu jan 12 11:40:10 gmt 2006 i686 intel(r) pentium(r) 4 cpu 3.20ghz genuineintel gnulinux ' config_args='-des -Darchname=i686-linux-thread -Dcccdlflags=-fPIC -Dccdlflags=-rdynamic -Dcc=i686-pc-linux-gnu-gcc -Dprefix=/home/zefram/tmp/perl64i -Dlocincpth= -Doptimize=-O3 -march=pentium4 -mtune=pentium4 --force-addr -momit-leaf-frame-pointer -fomit-frame-pointer -ftracer -pipe -Duselargefiles -Dd_semctl_semun -Dman1ext=1 -Dman3ext=3pm -Ud_csh -Dusethreads -Di_ndbm -Di_gdbm -Di_db -Duse64bitint' 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=define use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='i686-pc-linux-gnu-gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O3 -march=pentium4 -mtune=pentium4 --force-addr -momit-leaf-frame-pointer -fomit-frame-pointer -ftracer -pipe', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -Wdeclaration-after-statement' ccversion='', gccversion='3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='i686-pc-linux-gnu-gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.3.6.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.6' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: --- @INC for perl v5.8.8: /home/zefram/tmp/perl64i/lib/5.8.8/i686-linux-thread-multi-64int /home/zefram/tmp/perl64i/lib/5.8.8 /home/zefram/tmp/perl64i/lib/site_perl/5.8.8/i686-linux-thread-multi-64int /home/zefram/tmp/perl64i/lib/site_perl/5.8.8 /home/zefram/tmp/perl64i/lib/site_perl . --- Environment for perl v5.8.8: HOME=/home/zefram LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/zefram/pub/i686-pc-linux-gnu/bin:/home/zefram/pub/common/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/local/bin:/usr/games/bin:/opt/exim/bin:/opt/opera/bin:/opt/sun-jdk-1.4.2.10/bin:/opt/tomcat5/bin PERL_BADLANG (unset) SHELL=/home/zefram/pub/i686-pc-linux-gnu/bin/zsh
|