Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^7: Windows / Linux puzzler

by syphilis (Bishop)
on Mar 26, 2020 at 23:33 UTC ( #11114694=note: print w/replies, xml ) Need Help??

in reply to Re^6: Windows / Linux puzzler
in thread Windows / Linux puzzler

there are pertinent differences in the libraries between mingw and gcc

I think that with mingw, the MS runtime is still used by default for formatting of values.
However, that is avoided (by building with -D__USE_MINGW_ANSI_STDIO) in recent versions of Strawberry Perl, beginning perl-5.26.0.
(Look for "-D__USE_MINGW_ANSI_STDIO" in perl -V:ccflags)

Of course, ActiveState don't build with -D__USE_MINGW_ANSI_STDIO.


Replies are listed 'Best First'.
Re^8: Windows / Linux puzzler
by ikegami (Pope) on Mar 27, 2020 at 01:46 UTC

    Nope, that doesn't make differences go away, seeing as I was using SP 5.30.2 downloaded and installed less than a week ago. That's newer than 5.26, yet the output was different that the perl built gcc on Unbuntu on WSL on the same machine. The SP build does have -D__USE_MINGW_ANSI_STDIO

    Strawberry Perl 5.30.2 on Windows:

    >perl -e"CORE::say $^X" C:\progs\sp5302x64\perl\bin\perl.exe >perl -v | find "This is" This is perl 5, version 30, subversion 2 (v5.30.2) built for MSWin32-x +64-multi-thread >perl -V:nvsize nvsize='8'; >perl -V:ccflags ccflags=' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANSI_STD +IO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SY +S -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'; >perl -e"CORE::say sprintf '%.20g', 0.1" 0.10000000000000000555

    Self-built Perl 5.30.2 on Ubuntu 18.04 LTS on WSL on Windows:

    $ uname -a Linux tribble 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 + PST 2019 x86_64 x86_64 x86_64 GNU/Linux $ perl -v | grep 'This is' This is perl 5, version 30, subversion 2 (v5.30.2) built for x86_64-li +nux-thread-multi $ perl -V:nvsize nvsize='8'; $ perl -e'CORE::say sprintf "%.20g", 0.1' 0.10000000000000001
      Interesting - thanks for persisting.

      When I revert to an older Strawberry Perl that wasn't built with -D__USE_MINGW_ANSI_STDIO (5.24.1 / MSWin32-x64-multi-thread) I get the same as on Ubuntu:
      C:\_64\strawberry5.24.1>perl -e"CORE::say sprintf '%.20g', 0.1" 0.10000000000000001 C:\_64\strawberry5.24.1>
      I don't think that there's a lot of significance in the output of '%.20g' formatting of doubles.
      As you're probably aware, both 0.10000000000000001 and 0.10000000000000000555 will assign to the same double anyway.
      Both a 20-decimal-digit value, and that same value rounded to 17 decimal digits, will assign to the same double (unless something is buggy).

      If the intention of "%.20g" formatting of 0.1 is to get the closest 20-decimal digit approximation to the double 0.1, then the latter is correct, and the former (ie the value consistently provided by Ubuntu) is incorrect:
      C:\>perl -MMath::MPFR=":mpfr" -le "$x=Math::MPFR->new('0.1'); $base=10 +; $digits=20; Rmpfr_out_str($x, $base, $digits, MPFR_RNDN);" 1.0000000000000000555e-1 C:\>
      Perhaps Linux has some catching up to do.
      Even VC++ 2017 and later are "getting it right". On perl-5.30.0, MSWin32-x64-multi-thread, built with VC++ 2019:
      C:\>perl -e"CORE::say sprintf '%.20g', 0.1" 0.10000000000000000555 C:\>
      I'm not exactly sure when VC++ started "getting it right". I know it was some time after VC++ 2010.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114694]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2020-06-01 12:49 GMT
Find Nodes?
    Voting Booth?

    No recent polls found