develooper Front page | perl.perl5.porters | Postings from October 2013

Re: [perl #120405] Wrong results for unpack "f"

Thread Previous | Thread Next
From:
Victor Efimov
Date:
October 29, 2013 19:01
Subject:
Re: [perl #120405] Wrong results for unpack "f"
Message ID:
CAF7QZD4eumfu0vw3w+R0sjdABbLf9E-Z4e5BN5dsV1iHyzG98A@mail.gmail.com
there is another failure report for linux x86
http://www.cpantesters.org/cpan/report/7211af00-409d-11e3-9864-19736521ead1

however I cannot reproduce on linux 32bit (Linode) with perlbrew perls.

perl-5.10.1
==========
279.117156982422

perl-5.10.1-64int
==========
279.117156982422

perl-5.10.1-ld
==========
279.117156982421875

perl-5.10.1-ld-64int
==========
279.117156982421875

perl-5.10.1-thread-multi
==========
279.117156982422

perl-5.10.1-thread-multi-64int
==========
279.117156982422

perl-5.10.1-thread-multi-ld
==========
279.117156982421875

perl-5.10.1-thread-multi-ld-64int
==========
279.117156982421875

perl-5.12.5
==========
279.117156982422

perl-5.12.5-64int
==========
279.117156982422

perl-5.12.5-ld
==========
279.117156982421875

perl-5.12.5-ld-64int
==========
279.117156982421875

perl-5.12.5-thread-multi
==========
279.117156982422

perl-5.12.5-thread-multi-64int
==========
279.117156982422

perl-5.12.5-thread-multi-ld
==========
279.117156982421875

perl-5.12.5-thread-multi-ld-64int
==========
279.117156982421875

perl-5.14.4
==========
279.117156982422

perl-5.14.4-64int
==========
279.117156982422

perl-5.14.4-ld
==========
279.117156982421875

perl-5.14.4-ld-64int
==========
279.117156982421875

perl-5.14.4-thread-multi
==========
279.117156982422

perl-5.14.4-thread-multi-64int
==========
279.117156982422

perl-5.14.4-thread-multi-ld
==========
279.117156982421875

perl-5.14.4-thread-multi-ld-64int
==========
279.117156982421875

perl-5.16.3
==========
279.117156982422

perl-5.16.3-64int
==========
279.117156982422

perl-5.16.3-ld
==========
279.117156982421875

perl-5.16.3-ld-64int
==========
279.117156982421875

perl-5.16.3-thread-multi
==========
279.117156982422

perl-5.16.3-thread-multi-64int
==========
279.117156982422

perl-5.16.3-thread-multi-ld
==========
279.117156982421875

perl-5.16.3-thread-multi-ld-64int
==========
279.117156982421875

perl-5.18.1
==========
279.117156982422

perl-5.18.1-64int
==========
279.117156982422

perl-5.18.1-ld
==========
279.117156982421875

perl-5.18.1-ld-64int
==========
279.117156982421875

perl-5.18.1-thread-multi
==========
279.117156982422

perl-5.18.1-thread-multi-64int
==========
279.117156982422

perl-5.18.1-thread-multi-ld
==========
279.117156982421875

perl-5.18.1-thread-multi-ld-64int
==========
279.117156982421875

perl-5.19.3
==========
279.117156982422

perl-5.19.3-64int
==========
279.117156982422

perl-5.19.3-ld
==========
279.117156982421875

perl-5.19.3-ld-64int
==========
279.117156982421875

perl-5.19.3-thread-multi
==========
279.117156982422

perl-5.19.3-thread-multi-64int
==========
279.117156982422

perl-5.19.3-thread-multi-ld
==========
279.117156982421875

perl-5.19.3-thread-multi-ld-64int
==========
279.117156982421875

Example "-V" output for 5.18.1

perl-5.18.1
==========
Summary of my perl5 (revision 5 version 18 subversion 1) configuration:

  Platform:
    osname=linux, osvers=3.9.3-x86-linode52, archname=i686-linux
    uname='linux li488-134 3.9.3-x86-linode52 #1 smp mon may 20 09:32:28
edt 2013 i686 i686 i386 gnulinux '
    config_args='-de
-Dprefix=/home/perltest/perl5/perlbrew/perls/perl-5.18.1
-Aeval:scriptdir=/home/perltest/perl5/perlbrew/perls/perl-5.18.1/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, 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='-O2',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
    ccversion='', gccversion='4.6.3', 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 =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/i386-linux-gnu /lib/../lib
/usr/lib/i386-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.15'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -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 USE_LARGE_FILES
                        USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
  Built under linux
  Compiled at Sep  5 2013 10:02:26
  %ENV:
    PERL5LIB=""
    PERLBREW_BASHRC_VERSION="0.66"
    PERLBREW_HOME="/home/perltest/.perlbrew"
    PERLBREW_MANPATH="/home/perltest/perl5/perlbrew/perls/perl-5.18.1/man"

PERLBREW_PATH="/home/perltest/perl5/perlbrew/bin:/home/perltest/perl5/perlbrew/perls/perl-5.18.1/bin"
    PERLBREW_PERL="perl-5.18.1"
    PERLBREW_ROOT="/home/perltest/perl5/perlbrew"
    PERLBREW_VERSION="0.66"
  @INC:

/home/perltest/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/i686-linux
    /home/perltest/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1
    /home/perltest/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/i686-linux
    /home/perltest/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1
    .





2013/10/29 Slaven Rezic <slaven@rezic.de>

> Tony Cook <tony@develop-help.com> writes:
>
> > On Tue, Oct 29, 2013 at 10:06:30AM +0100, Lukas Mai wrote:
> >> On 29.10.2013 10:00, slaven@rezic.de (via RT) wrote:
> >> > # New Ticket Created by  slaven@rezic.de
> >> > # Please include the string:  [perl #120405]
> >> > # in the subject line of all future correspondence about this issue.
> >> > # <URL: https://rt.perl.org/Ticket/Display.html?id=120405 >
> >> >
> >> >
> >> > The problem is described in the StackOverflow article
> http://stackoverflow.com/questions/18969702/perl-strange-behaviour-on-unpack-of-floating-value
> >>
> >> Short version (copied into this bug for easier access):
> >> -----------------------------------------------------------------------
> >>
> >> $ perl -e "print unpack('f>', pack ('f>', 279.117156982422));"
> >> 279.617156982422
> >
> > I don't reproduce this here on Debian stable:
> >
> > tony@mars:.../git/bse$ ~/perl/5.18.0-thr/bin/perl -le "print
> unpack('f>', pack ('f>', 279.117156982422));"
> > 279.117156982422
> > tony@mars:.../git/bse$ perl -le "print unpack('f>', pack ('f>',
> 279.117156982422));"
> > 279.117156982422
> >
> > perl -V output might be useful.
>
> It's difficult to reproduce. Apparently it happens only on 32bit
> systems. I created a CPAN distribution with this problem as a test case,
> to get the results of CPAN testers, and there was only one fail report
> at all (using Strawberry Perl under Windows 8.1 Preview). See here:
>
>     http://matrix.cpantesters.org/?dist=Acme-Study-SREZIC%202.00
>     http://matrix.cpantesters.org/?dist=Acme-Study-SREZIC%202.00;reports=1
>
> And a direct link to the FAIL report (with perl -V included):
>
>
> http://www.cpantesters.org/cpan/report/5f5ba05e-3e82-11e3-94cf-57ac40c32a75
>
> Regards,
>     Slaven
>
> >
> >> Definitely a bug in Perl's unpacking. It has difficulty in handling
> >> floats in the binary form xxxxyyFF at least in a 32-bit platform, where
> >> 80 <= yy <= BF. The packed result will become xxxxzzFF, where zz = yy +
> >> 40 (all in hexadecimal). And this is not a problem of endianness, as you
> >> could see here:
> >>
> >> $ perl -e "print unpack('H8', pack ('f', unpack('f', pack('H8',
> >> '000088ff'))));";
> >> 0000c8ff
> >
> > I'm pretty sure this isn't a bug, but the FPU converting a signalling
> > NaN into a quiet NaN, which the Intel CPU manual implies it does.
> >
> > ie. this might happen when the float from pack() is converted into
> > double or long double, whichever representation perl uses for an NV.
> >
> > That said, the compiler might be depending on aliasing rules and
> > loading afloat into an FPU register early, changing that code to use a
> > union as was done in 275663fa07 for NVs might fix the problem.
> >
> > Tony
> >
>
> --
> Slaven Rezic - slaven <at> rezic <dot> de
>   BBBike - route planner for cyclists in Berlin
>   WWW version:                           http://www.bbbike.de
>   Perl/Tk version for Unix and Windows:  http://bbbike.sourceforge.net
>

Thread Previous | 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