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

[perl #120378] Atof is broken for 64-bit mingw64 builds of perl

From:
Sisyphus
Date:
October 27, 2013 11:55
Subject:
[perl #120378] Atof is broken for 64-bit mingw64 builds of perl
Message ID:
rt-4.0.18-14233-1382874924-1031.120378-75-0@perl.org
# New Ticket Created by  "Sisyphus" 
# Please include the string:  [perl #120378]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=120378 >


Hi,

The perlclib documentation recommends that we use Atof() instead of atof(), 
and that we avoid strtod() altogether.
But, although the other two seem to be quite functional, Atof() itself is 
broken on (at least) the following builds of *64-bit* perl:

Strawberry Perl 5.16.0 (built by the SP project using gcc-4.6.3)
Strawberry Perl 5.18.0 (built by the SP project using gcc-4.6.3)
perl 5.16.0 (built by self using mingw64 port of gcc-4.7.0)
perl 5.18.0 (built by self using mingw64 port of gcc-4.7.0)
perl 5.18.0 (built by self using mingw64 port of gcc-4.8.1)

However, it's only the 64-bit builds -  there are *no* such problems with 
32-bit builds - including Strawberry Perls 5.16.0 and 5.18.0.

Here's the demo:

###########################
#! perl -l

use warnings;
use strict;

#use Inline C => Config =>
# BUILD_NOISY => 1;

use Inline C => <<'EOC';

SV * wrap_Atof (char * s) {
   return newSVnv(Atof(s));
}

SV * wrap_atof (char * s) {
   return newSVnv(atof(s));
}

SV * wrap_strtod (char * s) {
   char * ptr;
   return newSVnv(strtod(s, &ptr));
}

EOC

my $s = '9.99999999999999e-299';

print   wrap_Atof($s); #8.99999999999999e-299 wtf ???
print   wrap_atof($s); #9.99999999999999e-299 ok
print wrap_strtod($s); #9.99999999999999e-299 ok
###########################

Instead of the expected output of:

9.99999999999999e-299
9.99999999999999e-299
9.99999999999999e-299

I'm getting:

8.99999999999999e-299
9.99999999999999e-299
9.99999999999999e-299

All of those "problem" perls have essentially the same 'perl -V'. Here's the 
one for 64-bit Strawberry 5.18.0:

#################################
Summary of my perl5 (revision 5 version 18 subversion 0) configuration:

  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x64-multi-thread
    uname='Win32 strawberry-perl 5.18.0.1 #1 Sat May 18 19:40:33 2013 x64'
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=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='gcc', ccflags 
' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE  -DPERL_TEXTMODE_
SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fno-strict-aliasing 
 -mms-bitfields',
    optimize='-s -O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='4.6.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=8, 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='long 
long', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++.exe', ldflags 
='-s -L"C:\_64\strawberry518\perl\lib\CORE" -L"C:\_64\strawberry518\c\lib"'
    libpth=C:\_64\strawberry518\c\lib 
C:\_64\strawberry518\c\x86_64-w64-mingw32\lib
    libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion
-lodbc32 -lodbccp32 -lcomctl32
    perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion 
 -lodbc32 -lodbccp32 -lcomctl32
    libc=, so=dll, useshrplib=true, libperl=libperl518.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', 
lddlflags='-mdll -s -L"C:\_64\strawberry518\perl\lib\CORE" -
L"C:\_64\strawberry518\c\lib"'


Characteristics of this binary (from libperl):
  Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY
                        PERLIO_LAYERS PERL_DONT_CREATE_GVSV
                        PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                        PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
                        PERL_MALLOC_WRAP PERL_PRESERVE_IVUV 
PERL_SAWAMPERSAND
                        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
  Built under MSWin32
  Compiled at May 18 2013 19:45:54
  @INC:
    C:/_64/strawberry518/perl/site/lib
    C:/_64/strawberry518/perl/vendor/lib
    C:/_64/strawberry518/perl/lib
    .
#################################

Cheers,
Rob 




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About