Front page | perl.perl5.porters |
Postings from February 2003
[perl #20827] Unexpected scientific notation.
Thread Previous
|
Thread Next
From:
perlbug-followup
Date:
February 11, 2003 13:01
Subject:
[perl #20827] Unexpected scientific notation.
Message ID:
rt-20827-50767.19.6923305511423@bugs6.perl.org
# New Ticket Created by abigail@abigail.nl
# Please include the string: [perl #20827]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=20827 >
This is a bug report for perl from abigail@abigail.nl
generated with the help of perlbug 1.34 running under perl v5.8.0.
-----------------------------------------------------------------
[Please enter your report here]
$ perl -wle 'print 1597009560 * 1597009560'
2550439534731393600
$ perl -wle '$x = 1597009560; print $x * $x'
2550439534731393600
$ perl -wle 'print 1597009560 ** 2'
2550439534731393600
$ perl -wle '$x = 1597009560; print $x ** 2'
2.5504395347313936e+18
I would have expected all outputs to be the same.
The fact that 2550439534731393600 is numerically the same as
2.5504395347313936e+18 doesn't do me any good, as it's the
stringifaction that gives the unexpected results:
$ perl -wle '$x = 1597009560; print "$x ** 2 = @{[$x ** 2]}"'
1597009560 ** 2 = 2.5504395347313936e+18
This is probably caused by the fact that $x ** 2 becomes an NV,
but neither 1597009560 ** 2 nor $x * $x do:
$ perl -MDevel::Peek -wle '$x = 1597009560; $y = $x * $x; $z = $x ** 2;
$w = 1597009560 ** 2; Dump ($x); Dump ($y); Dump ($z); Dump ($w)'
SV = PVNV(0x8195fe8) at 0x8184adc
REFCNT = 1
FLAGS = (IOK,NOK,pIOK,pNOK)
IV = 1597009560
NV = 1597009560
PV = 0
SV = IV(0x81845cc) at 0x8184ae8
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2550439534731393600
SV = NV(0x8197ecc) at 0x8184b18
REFCNT = 1
FLAGS = (NOK,pNOK)
NV = 2.5504395347313936e+18
SV = PVNV(0x8196008) at 0x819441c
REFCNT = 1
FLAGS = (IOK,NOK,pIOK,pNOK)
IV = 2550439534731393600
NV = 2.5504395347313936e+18
PV = 0
It seems like in one case (at compile time?), Perl seems to be smart enough
to realize that 1597009560 ** 2 can be represented as an integer, while
in another case, it doesn't figure it out.
There's a work around, by using (s)printf "%d", but that isn't satisfying.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.8.0:
Configured by abigail at Mon Jul 22 13:26:11 CEST 2002.
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.5, archname=i686-linux-64int-ld
uname='linux hermione 2.4.5 #6 fri jun 22 01:38:20 pdt 2001 i686 unknown '
config_args='-des -Uversiononly -Dmydomain=.foad.org -Dcf_email=abigail@foad.org -Dperladmin=abigail@foad.org -Doptimize=-g -Dusemorebits -Dusedevel -Dusen=false -Dprefix=/opt/perl'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=undef uselongdouble=define
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/opt/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-g',
cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/opt/local/include'
ccversion='', gccversion='2.95.3 20010315 (release)', 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='long double', nvsize=12, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib -L/opt/local/lib'
libpth=/usr/local/lib /opt/local/lib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldl -lm -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
libc=/lib/libc-2.2.3.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.3'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib -L/opt/local/lib'
Locally applied patches:
---
@INC for perl v5.8.0:
/home/abigail/Perl
/home/abigail/Sybase
/opt/perl/lib/5.8.0/i686-linux-64int-ld
/opt/perl/lib/5.8.0
/opt/perl/lib/site_perl/5.8.0/i686-linux-64int-ld
/opt/perl/lib/site_perl/5.8.0
/opt/perl/lib/site_perl
.
---
Environment for perl v5.8.0:
HOME=/home/abigail
LANG (unset)
LANGUAGE (unset)
LC_ALL=POSIX
LD_LIBRARY_PATH=/home/abigail/Lib:/usr/local/lib:/usr/lib:/lib:/usr/X11R6/lib:/opt/gnome/lib
LOGDIR (unset)
PATH=/home/abigail/Bin:/opt/perl/bin:/usr/local/bin:/usr/local/X11/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/games:/opt/povray/bin:/opt/gnome/bin:/opt/opera/bin:/usr/share/texmf/bin:/opt/Acrobat4/bin:/opt/java/blackdown/j2sdk1.3.1/bin:/usr/local/games/bin:/opt/gnuplot/bin:/opt/mysql/bin
PERL5LIB=/home/abigail/Perl:/home/abigail/Sybase
PERLDIR=/opt/perl
PERL_BADLANG (unset)
SHELL=/usr/bin/bash
Thread Previous
|
Thread Next