Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sprintf: %f rounding different in 5.24.0 and 5.26.0 #15997

Closed
p5pRT opened this issue Jun 4, 2017 · 14 comments
Closed

sprintf: %f rounding different in 5.24.0 and 5.26.0 #15997

p5pRT opened this issue Jun 4, 2017 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 4, 2017

Migrated from rt.perl.org#131506 (status was 'rejected')

Searchable as RT131506$

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2017

From wolf-dietrich_moeller@t-online.de

Hi,
when comparing output generated with Perl 5.24.0 and 5.26.0, I found the
following
difference for the test program
#############
my $x=44.625;print sprintf('%.2f %.25f',$x,$x);
#############

For Perl 5.24 the result is
44.63 44.6250000000000000000000000

while for Perl 5.26 the result is
44.62 44.6250000000000000000000000

Tested with downloaded strawberry perl versions on WinXP SP3​:
5.24​: "strawberry-perl-5.24.0.1-32bit.msi"
  and "strawberry-perl-no64-5.24.0.1-32bit-portable.zip"
5.26​: "strawberry-perl-5.26.0.1-32bit.msi"
  and "strawberry-perl-no64-5.26.0.1-32bit-portable.zip"

Is this change intended? This makes comparisons with old results very hard.
I did not find any remark on such a change in
<http​://search.cpan.org/dist/perl-5.26.0/pod/perldelta.pod>

Best regards
Wolf

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2017

From @Tux

On Sun, 04 Jun 2017 02​:40​:44 -0700, Wolf-Dietrich Moeller (via RT)
<perlbug-followup@​perl.org> wrote​:

my $x=44.625;print sprintf('%.2f %.25f',$x,$x);

on a Linux system I get consistent 44.62 for all 270 installed perl
versions​:

$ perl-all -e'my $x=44.625; printf "%7s %.2f %.25f\n", $], $x, $x;' |& grep ^5
5.006001 44.62 44.6250000000000000000000000
5.006001 44.62 44.6250000000000000000000000
5.006002 44.62 44.6250000000000000000000000
5.006002 44.62 44.6250000000000000000000000
5.008001 44.62 44.6250000000000000000000000
5.008001 44.62 44.6250000000000000000000000
5.008002 44.62 44.6250000000000000000000000
5.008002 44.62 44.6250000000000000000000000
5.008003 44.62 44.6250000000000000000000000
5.008003 44.62 44.6250000000000000000000000
5.008004 44.62 44.6250000000000000000000000
:
:
5.025011 44.62 44.6250000000000000000000000
5.025012 44.62 44.6250000000000000000000000
5.025012 44.62 44.6250000000000000000000000
5.026000 44.62 44.6250000000000000000000000
5.026000 44.62 44.6250000000000000000000000
5.027000 44.62 44.6250000000000000000000000
5.027000 44.62 44.6250000000000000000000000
5.010001 44.62 44.6250000000000000000000000

same result for print sprintf

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.27 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2017

From @shlomif

Hi Wolf!

On Sun, 04 Jun 2017 02​:40​:44 -0700
Wolf-Dietrich Moeller (via RT) <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Wolf-Dietrich Moeller
# Please include the string​: [perl #131506]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=131506 >

Hi,
when comparing output generated with Perl 5.24.0 and 5.26.0, I found the
following
difference for the test program
#############
my $x=44.625;print sprintf('%.2f %.25f',$x,$x);
#############

For Perl 5.24 the result is
44.63 44.6250000000000000000000000

while for Perl 5.26 the result is
44.62 44.6250000000000000000000000

On x86-64 Linux with perl-5.24.1 and perl-5.26.0 built using perlbrew I am
getting the "44.62" result in both cases. This may be dependent on the standard
C library anyway.

Tested with downloaded strawberry perl versions on WinXP SP3​:
5.24​: "strawberry-perl-5.24.0.1-32bit.msi"
and "strawberry-perl-no64-5.24.0.1-32bit-portable.zip"
5.26​: "strawberry-perl-5.26.0.1-32bit.msi"
and "strawberry-perl-no64-5.26.0.1-32bit-portable.zip"

Is this change intended? This makes comparisons with old results very hard.
I did not find any remark on such a change in
<http​://search.cpan.org/dist/perl-5.26.0/pod/perldelta.pod>

Best regards
Wolf

--


Shlomi Fish http​://www.shlomifish.org/

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2017

From @jkeenan

On Sun, 04 Jun 2017 09​:40​:44 GMT, wolf-dietrich_moeller@​t-online.de wrote​:

Hi,
when comparing output generated with Perl 5.24.0 and 5.26.0, I found the
following
difference for the test program
#############
my $x=44.625;print sprintf('%.2f %.25f',$x,$x);
#############

For Perl 5.24 the result is
44.63 44.6250000000000000000000000

while for Perl 5.26 the result is
44.62 44.6250000000000000000000000

Tested with downloaded strawberry perl versions on WinXP SP3​:
5.24​: "strawberry-perl-5.24.0.1-32bit.msi"
and "strawberry-perl-no64-5.24.0.1-32bit-portable.zip"
5.26​: "strawberry-perl-5.26.0.1-32bit.msi"
and "strawberry-perl-no64-5.26.0.1-32bit-portable.zip"

Is this change intended? This makes comparisons with old results very hard.
I did not find any remark on such a change in
<http​://search.cpan.org/dist/perl-5.26.0/pod/perldelta.pod>

Best regards
Wolf

I suspect your change is platform-specific. Here's what I get on FreeBSD-10.3​:

#####
[perl] $ perl -v | head -2 | tail -1
This is perl 5, version 20, subversion 3 (v5.20.3) built for amd64-freebsd-thread-multi

[perl] $ perl -e 'my $x=44.625;print sprintf("%.2f %.25f\n",$x,$x);'
44.62 44.6250000000000000000000000

[perl] $ ./perl -v | head -2 | tail -1
This is perl 5, version 27, subversion 1 (v5.27.1 (v5.27.0-94-gbb5b17c)) built for amd64-freebsd-thread-multi

[perl] $ ./perl -e 'my $x=44.625;print sprintf("%.2f %.25f\n",$x,$x);'
44.62 44.6250000000000000000000000
#####

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2017

From @sisyphus

when comparing output generated with Perl 5.24.0 and 5.26.0, I found the
following difference for the test program
#############
my $x=44.625;print sprintf('%.2f %.25f',$x,$x);
#############

For Perl 5.24 the result is
44.63 44.6250000000000000000000000

while for Perl 5.26 the result is
44.62 44.6250000000000000000000000

perl-5.26.0 is the first 32-bit Strawberry Perl to have been built
with -D__USE_MINGW_ANSI_STDIO and it's seemingly the defining of this symbol
that has fixed the error you've been seeing in perl-5.24.x and earlier.

For my own 32-bit Windows builds of perl-5.26.0 (also built
with -D__USE_MINGW_ANSI_STDIO) I'm also getting​:

C​:\_32>perl -le "printf '%.2f', 44.625;"
44.62

But the error re-appears when I build perl-5.26.0 without defining that
symbol​:

C​:\_32>\temp\bin\perl -le "printf '%.2f', 44.625;"
44.63

You'll find that there are other (s)printf corrections attributable
to -D__USE_MINGW_ANSI_STDIO .... and hopefully no regressions.

Cheers,
Rob

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2019

From @tonycoz

On Sun, 04 Jun 2017 06​:42​:39 -0700, sisyphus wrote​:

when comparing output generated with Perl 5.24.0 and 5.26.0, I found
the
following difference for the test program
#############
my $x=44.625;print sprintf('%.2f %.25f',$x,$x);
#############

For Perl 5.24 the result is
44.63 44.6250000000000000000000000

while for Perl 5.26 the result is
44.62 44.6250000000000000000000000

perl-5.26.0 is the first 32-bit Strawberry Perl to have been built
with -D__USE_MINGW_ANSI_STDIO and it's seemingly the defining of this
symbol
that has fixed the error you've been seeing in perl-5.24.x and
earlier.

For my own 32-bit Windows builds of perl-5.26.0 (also built
with -D__USE_MINGW_ANSI_STDIO) I'm also getting​:

If I understand correctly, this is a Strawberry perl specific issue rather than core perl itself?

Is that right?

If so this ticket can be closed.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2019

From @sisyphus

Yes - please feel free to close it.

Both win32/GNUmakefile and win32/makefile.mk now accommodate the defining
of __USE_MINGW_ANSI_STDIO for "double" builds of perl, though the default
is to NOT define that symbol. (I actually think it should be the other way
around - ie defined by default, with an option to NOT define it.)
With "long double" builds, __USE_MINGW_ANSI_STDIO is defined by default. I
don't think it would make sense to NOT define the symbol when building with
"long double" support.

Cheers,
Rob

On Mon, Jan 7, 2019 at 2​:08 PM Tony Cook via RT <perlbug-followup@​perl.org>
wrote​:

On Sun, 04 Jun 2017 06​:42​:39 -0700, sisyphus wrote​:

when comparing output generated with Perl 5.24.0 and 5.26.0, I found
the
following difference for the test program
#############
my $x=44.625;print sprintf('%.2f %.25f',$x,$x);
#############

For Perl 5.24 the result is
44.63 44.6250000000000000000000000

while for Perl 5.26 the result is
44.62 44.6250000000000000000000000

perl-5.26.0 is the first 32-bit Strawberry Perl to have been built
with -D__USE_MINGW_ANSI_STDIO and it's seemingly the defining of this
symbol
that has fixed the error you've been seeing in perl-5.24.x and
earlier.

For my own 32-bit Windows builds of perl-5.26.0 (also built
with -D__USE_MINGW_ANSI_STDIO) I'm also getting​:

If I understand correctly, this is a Strawberry perl specific issue rather
than core perl itself?

Is that right?

If so this ticket can be closed.

Tony

---
via perlbug​: queue​: perl5 status​: open
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=131506

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2019

From @tonycoz

On Sun, 06 Jan 2019 20​:38​:45 -0800, sisyphus359@​gmail.com wrote​:

Yes - please feel free to close it.

Thanks, closing.

Both win32/GNUmakefile and win32/makefile.mk now accommodate the defining
of __USE_MINGW_ANSI_STDIO for "double" builds of perl, though the default
is to NOT define that symbol. (I actually think it should be the other way
around - ie defined by default, with an option to NOT define it.)
With "long double" builds, __USE_MINGW_ANSI_STDIO is defined by default. I
don't think it would make sense to NOT define the symbol when building with
"long double" support.

Are there any negatives to defining it?

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2019

@tonycoz - Status changed from 'open' to 'rejected'

@p5pRT p5pRT closed this as completed Jan 7, 2019
@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2019

From @tonycoz

On Mon, 07 Jan 2019 14​:04​:45 -0800, tonyc wrote​:

Both win32/GNUmakefile and win32/makefile.mk now accommodate the
defining
of __USE_MINGW_ANSI_STDIO for "double" builds of perl, though the
default
is to NOT define that symbol. (I actually think it should be the
other way
around - ie defined by default, with an option to NOT define it.)
With "long double" builds, __USE_MINGW_ANSI_STDIO is defined by
default. I
don't think it would make sense to NOT define the symbol when
building with
"long double" support.

Are there any negatives to defining it?

And should they instead define _GNU_SOURCE?

https://rt-archive.perl.org/perl5/Ticket/Display.html?id=130447#txn-1461711

https://gmplib.org/list-archives/gmp-bugs/2017-May/004162.html

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2019

From @sisyphus

The only negative I've come across is the one expressed here by the OP -
namely that behaviour has changed.
But I think the vast majority would consider this to be a change for the
better, so it's not really a negative at all.

I've not tried defining _GNU_SOURCE. I've instead always defined
__USE_MINGW_ANSI_STDIO which seems to be broadly recommended.
The advice from the mingw-w64 developers continues to be to define
__USE_MINGW_ANSI_STDIO.
So I don't think it's going to stop doing the job any time soon and I'd be
a little reticent to replace it with something that hasn't been widely used.

Attached are patches to win32/GNUmakefile and win32/makefile.mk, that make
defining of __USE_MINGW_ANSI_STDIO the default.
They do the right thing for me with gcc-8.1.0, but I'm not set up to test
them with MSVC.

Cheers,
Rob

On Tue, Jan 8, 2019 at 10​:25 AM Tony Cook via RT <perlbug-followup@​perl.org>
wrote​:

On Mon, 07 Jan 2019 14​:04​:45 -0800, tonyc wrote​:

Both win32/GNUmakefile and win32/makefile.mk now accommodate the
defining
of __USE_MINGW_ANSI_STDIO for "double" builds of perl, though the
default
is to NOT define that symbol. (I actually think it should be the
other way
around - ie defined by default, with an option to NOT define it.)
With "long double" builds, __USE_MINGW_ANSI_STDIO is defined by
default. I
don't think it would make sense to NOT define the symbol when
building with
"long double" support.

Are there any negatives to defining it?

And should they instead define _GNU_SOURCE?

https://rt-archive.perl.org/perl5/Ticket/Display.html?id=130447#txn-1461711

https://gmplib.org/list-archives/gmp-bugs/2017-May/004162.html

Tony

---
via perlbug​: queue​: perl5 status​: rejected
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=131506

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2019

From @sisyphus

0001-Make-D__USE_MINGW_ANSI_STDIO-Win32-default.patch
From 74f9a9a754261e0bdebb9e8a33838024a48ab108 Mon Sep 17 00:00:00 2001
From: sisyphus <sisyphus@cpan.org>
Date: Tue, 8 Jan 2019 17:23:42 +1100
Subject: [PATCH 1/2] Make -D__USE_MINGW_ANSI_STDIO Win32 default

---
 win32/GNUmakefile | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/win32/GNUmakefile b/win32/GNUmakefile
index 8aa1fc5..a9ebb53 100644
--- a/win32/GNUmakefile
+++ b/win32/GNUmakefile
@@ -137,12 +137,15 @@ USE_LARGE_FILES	:= define
 #USE_LONG_DOUBLE := define
 
 #
-# Uncomment this if you want to build perl with __USE_MINGW_ANSI_STDIO defined.
-# (If you're building perl with USE_LONG_DOUBLE defined then
-# __USE_MINGW_ANSI_STDIO will be defined whether or not this is uncommented.)
-# This option is not supported for MSVC builds.
+# Comment this out if you want to build perl without __USE_MINGW_ANSI_STDIO
+# defined.
+# For GCC builds, if you're building perl with USE_LONG_DOUBLE defined then
+# __USE_MINGW_ANSI_STDIO will be defined, irrespective of whether or not this
+# is uncommented.
+# For MSVC builds, __USE_MINGW_ANSI_STDIO will NOT be defined, irrespective of
+# whether or not this is uncommented.
 #
-#USE_MINGW_ANSI_STDIO := define
+USE_MINGW_ANSI_STDIO := define
 
 #
 # Comment this out if you want the legacy default behavior of including '.' at
@@ -455,10 +458,11 @@ ifeq ($(CCTYPE),MSVC60)
 USE_64_BIT_INT	= undef
 endif
 
-# Disable the long double option for MSVC builds since that compiler
-# does not support it.
+# Disable both the USE_LONG_DOUBLE and USE_MINGW_ANSI_STDIO options for MSVC
+# builds since that compiler does not support those options.
 ifneq ($(CCTYPE),GCC)
 USE_LONG_DOUBLE	= undef
+USE_MINGW_ANSI_STDIO = undef
 endif
 
 ARCHITECTURE = $(PROCESSOR_ARCHITECTURE)
-- 
2.1.4

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2019

From @sisyphus

0002-Make-D__USE_MINGW_ANSI_STDIO-Win32-default.patch
From 76cb4879827c4b792fef31dcddb2c70c23921994 Mon Sep 17 00:00:00 2001
From: sisyphus <sisyphus@cpan.org>
Date: Tue, 8 Jan 2019 17:24:03 +1100
Subject: [PATCH 2/2] Make -D__USE_MINGW_ANSI_STDIO Win32 default

---
 win32/makefile.mk | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/win32/makefile.mk b/win32/makefile.mk
index 267099f..e013bb7 100644
--- a/win32/makefile.mk
+++ b/win32/makefile.mk
@@ -109,12 +109,15 @@ USE_LARGE_FILES	*= define
 #USE_LONG_DOUBLE *= define
 
 #
-# Uncomment this if you want to build perl with __USE_MINGW_ANSI_STDIO defined.
-# (If you're building perl with USE_LONG_DOUBLE defined then
-# __USE_MINGW_ANSI_STDIO will be defined whether or not this is uncommented.)
-# This option is not supported for MSVC builds.
+# Comment this out if you want to build perl without __USE_MINGW_ANSI_STDIO
+# defined.
+# For GCC builds, if you're building perl with USE_LONG_DOUBLE defined then
+# __USE_MINGW_ANSI_STDIO will be defined, irrespective of whether or not this
+# is uncommented.
+# For MSVC builds, __USE_MINGW_ANSI_STDIO will NOT be defined, irrespective of
+# whether or not this is uncommented.
 #
-#USE_MINGW_ANSI_STDIO *= define
+USE_MINGW_ANSI_STDIO *= define
 
 #
 # Comment this out if you want the legacy default behavior of including '.' at
@@ -440,10 +443,11 @@ CCTYPE		= SDK2003SP1
 USE_64_BIT_INT	!= undef
 .ENDIF
 
-# Disable the long double option for MSVC builds since that compiler
-# does not support it.
+# Disable both the USE_LONG_DOUBLE and USE_MINGW_ANSI_STDIO options for MSVC
+# builds since that compiler does not support those options.
 .IF "$(CCTYPE)" != "GCC"
 USE_LONG_DOUBLE	!= undef
+USE_MINGW_ANSI_STDIO != undef
 .ENDIF
 
 ARCHITECTURE = $(PROCESSOR_ARCHITECTURE)
-- 
2.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant