develooper Front page | perl.perl5.porters | Postings from February 2000

[ID 20000229.007] printf() does not respect use integer,big numbers lose precision

Thread Next
February 29, 2000 16:50
[ID 20000229.007] printf() does not respect use integer,big numbers lose precision
Message ID:
This is a bug report for perl from,
generated with the help of perlbug 1.26 running under perl 5.00503.

[Please enter your report here]

On my DEC Alpha, this program:

use integer;
$bigquad = pack "VV", 0xc5ac9b81, 0xc998806b;
printf "%016lx %08x %08x\n", (unpack "Q", $bigquad), (unpack "VV", $bigquad)

prints this:

c998806bc5ac9800 c5ac9b81 c998806b

Unfortunately it's not possible to reproduce this on 32-bit systems.
However the cause of it is pretty clear - the integer returned by
unpack "Q" is being "upgraded" to a floating poing number by printf(),
but since 'double' and 'long' types are both 64 bits on Alpha, it loses
precision when it gets converted to a floating-point number.

It's definitely printf and not unpack, as you can see here:

[dhd@doppelbock]:~$ perl -Minteger -e 'printf "%016lx\n", 0xc998806bc5ac9b81'

[Please do not change anything below this line]

Site configuration information for perl 5.00503:

Configured by chris at Wed Jan 26 22:28:31 EST 2000.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
    osname=linux, osvers=2.2.14pre9, archname=alpha-linux
    uname='linux spawn 2.2.14pre9 #2 wed dec 15 00:24:37 est 1999 alpha unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
    cc='cc', optimize='-O2 -mieee', gccversion=2.95.2 20000116 (Debian GNU/Linux)
    cppflags='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=8, ptrsize=8, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  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 5.00503:

Environment for perl 5.00503:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About