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

[perl #120363] perl-5.18.0 apparently miscalculates the NV 1e-298

Thread Next
From:
Sisyphus
Date:
October 25, 2013 10:54
Subject:
[perl #120363] perl-5.18.0 apparently miscalculates the NV 1e-298
Message ID:
rt-4.0.18-24732-1382698460-616.120363-75-0@perl.org
# New Ticket Created by  "Sisyphus" 
# Please include the string:  [perl #120363]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=120363 >


Hi,
On ubuntu-12.04LTS I have 2 builds of perl-5.18.0, both built by gcc-4.6.3.

One of those perls has nvtype of 'double', the other has nvtype of 'long 
double' (64-bit significand).

I run the following Inline::C script:

#######################

#!perl -l
use warnings;
use strict;
use Config;

#use Inline C => Config =>
#  USING => 'ParseRegExp',
#  BUILD_NOISY => 1;

use Inline C => <<'EOC';

SV * get_problem_val(long nvsize) {
   if(nvsize == 8) return newSVnv(1e-298);
   return newSVnv(1e-298L);
}

EOC

my $s = $Config{nvsize};
print "\n\$Config{nvtype}: $Config{nvtype}";
print "Different values" if 1e-298 != get_problem_val($s);

if($Config{nvsize} != 8) {
print scalar reverse unpack "b64", pack "D", 1e-298;
print scalar reverse unpack "b64", pack "D", get_problem_val($s);
}
else {
print scalar reverse unpack "b53", pack "F", 1e-298;
print scalar reverse unpack "b53", pack "F", get_problem_val($s);
};
}

#######################

When I run that on the "double" build of perl-5.18.0, it produces the 
following output:

$Config{nvtype}: double
Different values
10000101111100000100011010000010100100111111000011011
10000101111100000100011010000010100100111111000011101

When I run that on the "long double" build of perl-5.18.0, it produces:

$Config{nvtype}: long double
Different values
1000010111110000010001101000001010010011111100001110101101010000
1000010111110000010001101000001010010011111100001110101101001110

In both instances it's the second of the 2 values (ie the value returned 
from C, not the value that perl assigns) that's correct.

I presume there would be other values that also produce the discrepancy, 
but I haven't sought any out.

Here are the 'perl -V' outputs for both perls - firstly, the "double" build:

########################

This is perl 5, version 18, subversion 0 (v5.18.0) built for 
x86_64-linux-thread-multi

Copyright 1987-2013, Larry Wall

Perl may be copied only under the terms of either the Artistic License 
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

sisyphus@sisyphus5-desktop:~/pscrpt/inline$ perl -V
Summary of my perl5 (revision 5 version 18 subversion 0) configuration:

   Platform:
     osname=linux, osvers=3.5.0-34-generic, 
archname=x86_64-linux-thread-multi
     uname='linux sisyphus5-desktop 3.5.0-34-generic #55~precise1-ubuntu 
smp fri jun 7 16:25:50 utc 2013 x86_64 x86_64 x86_64 gnulinux '
     config_args='-des -Duse64bitint -Duse64bitall -Dusethreads 
-Dprefix=/home/sisyphus/perl518-multi'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=define, usemultiplicity=define
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=define, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing 
-pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64',
     optimize='-O2',
     cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe 
-fstack-protector -I/usr/local/include'
     ccversion='', gccversion='4.6.3', gccosandvers=''
     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
     libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib 
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib
     libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
     perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -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 MULTIPLICITY PERLIO_LAYERS
                         PERL_DONT_CREATE_GVSV
                         PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                         PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                         PERL_PRESERVE_IVUV PERL_SAWAMPERSAND USE_64_BIT_ALL
                         USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                         USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                         USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
                         USE_REENTRANT_API
   Built under linux
   Compiled at Jul  5 2013 19:03:19
   @INC:
/home/sisyphus/perl518-multi/lib/site_perl/5.18.0/x86_64-linux-thread-multi
     /home/sisyphus/perl518-multi/lib/site_perl/5.18.0
/home/sisyphus/perl518-multi/lib/5.18.0/x86_64-linux-thread-multi
     /home/sisyphus/perl518-multi/lib/5.18.0
     .

########################

and the "long double" build:

########################
This is perl 5, version 18, subversion 0 (v5.18.0) built for x86_64-linux-ld

Copyright 1987-2013, Larry Wall

Perl may be copied only under the terms of either the Artistic License 
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

sisyphus@sisyphus5-desktop:~/pscrpt/inline$ perl -V
Summary of my perl5 (revision 5 version 18 subversion 0) configuration:

   Platform:
     osname=linux, osvers=3.5.0-23-generic, archname=x86_64-linux-ld
     uname='linux sisyphus5-desktop 3.5.0-23-generic #35~precise1-ubuntu 
smp fri jan 25 17:13:26 utc 2013 x86_64 x86_64 x86_64 gnulinux '
     config_args='-des -Duse64bitint -Duse64bitall -Duselongdouble 
-Dprefix=/home/sisyphus/perl518'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=undef, usemultiplicity=undef
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=define, uselongdouble=define
     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=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='long double', nvsize=16, 
Off_t='off_t', lseeksize=8
     alignbytes=16, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
     libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib 
/usr/lib/x86_64-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_64_BIT_ALL
                         USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE
                         USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                         USE_LOCALE_NUMERIC USE_LONG_DOUBLE USE_PERLIO
                         USE_PERL_ATOF
   Built under linux
   Compiled at Jul  3 2013 20:20:11
   @INC:
     /home/sisyphus/perl518/lib/site_perl/5.18.0/x86_64-linux-ld
     /home/sisyphus/perl518/lib/site_perl/5.18.0
     /home/sisyphus/perl518/lib/5.18.0/x86_64-linux-ld
     /home/sisyphus/perl518/lib/5.18.0
     .

########################

Cheers,
Rob



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