GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 14220 - [3.5] num_put::do_put() undesired float/double behavior
Summary: [3.5] num_put::do_put() undesired float/double behavior
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.2.3
: P3 minor
Target Milestone: 4.0.0
Assignee: Paolo Carlini
URL:
Keywords:
: 14969 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-02-20 01:38 UTC by sadfate
Modified: 2004-07-29 22:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-02-20 12:11:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sadfate 2004-02-20 01:38:03 UTC
When a float or double is streamed to output in fixed-point format, rounding up
occurs well before the precision specified by the stream.

5.55555555e-17, when streamed to a stream with the scientific flag set and a
precision of 25 will print 5.55555555[#'s-up-to-20]e-17.  When streamed with the
fixed flag set, it will print out 0.0000000000000000560000000.  If the number is
especially small (e-20+), it will print out as all zeroes.

I looked at the code in 3.2.3 and 3.4 versions of g++, and saw that it was
because the max_digits is being set from the numeric_limits<double>::digits10
field.  The precision is then set to be less than or equal to the max_digits. 
So on my platform, where digits10 is 16 (+2), the precision will get set to 18,
max.  That works fine for scientific values, but I would argue that if I ask a
stream for 25 places of precision, and put a float/double into it that should be
represented by 0.0000000000000000555555555, that I would see that value, not a
rounded version.

My understanding is that the numeric_limits<double>::digits10 value for a
float/double amounts to the significant digits if it were in scientific
notation.  If that is the case, then the max_digits for fixed number would be
digits10 + the number of preceding zeroes, which is probably max_exponent10.

This was seen on Solaris 8 and Irix 6.5.22.
Comment 1 Paolo Carlini 2004-02-20 12:11:22 UTC
Confirmed. Actually, basing on the standard (22.2.2.2.2, p8-11-13), I think that
simply the precision passed down to the printing code must not be clipped at all.
Comment 2 CVS Commits 2004-02-22 15:00:46 UTC
Subject: Bug 14220

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	aj@gcc.gnu.org	2004-02-22 15:00:40

Modified files:
	libstdc++-v3/include/bits: locale_facets.tcc 
	libstdc++-v3   : ChangeLog.hammer 

Log message:
	2004-02-22  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/14220
	* include/bits/locale_facets.tcc (num_put<>::_M_convert_float):
	Don't clip the precision passed down to __convert_from_v:
	22.2.2.2.2 nowhere says so.
	
	2004-02-22  Paolo Carlini  <pcarlini@suse.de>
	
	* include/bits/locale_facets.tcc (_M_extract_float,
	_M_extract_int): Remove a wrong comment and simplify
	the corresponding code using char_traits::find().

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.82.2.11&r2=1.82.2.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.3&r2=1.1.2.4

Comment 3 CVS Commits 2004-02-22 15:33:05 UTC
Subject: Bug 14220

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	aj@gcc.gnu.org	2004-02-22 15:33:00

Modified files:
	libstdc++-v3/include/bits: locale_facets.tcc 
	libstdc++-v3   : ChangeLog.hammer 

Log message:
	2004-02-22  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/14220
	* include/bits/locale_facets.tcc (num_put<>::_M_convert_float):
	Fix previous commit: in case of non-fixed outputs __max_digits
	is still needed in order to upper bound the size of the buffer.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.82.2.12&r2=1.82.2.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.4&r2=1.1.2.5

Comment 4 CVS Commits 2004-02-22 17:57:27 UTC
Subject: Bug 14220

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	paolo@gcc.gnu.org	2004-02-22 17:57:21

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc 

Log message:
	2004-02-22  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/14220
	* include/bits/locale_facets.tcc (num_put<>::_M_convert_float):
	Don't clip the precision passed down to __convert_from_v:
	22.2.2.2.2 nowhere says so.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1464.2.181&r2=1.1464.2.182
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.82.4.18&r2=1.82.4.19

Comment 5 Paolo Carlini 2004-04-15 19:39:33 UTC
*** Bug 14969 has been marked as a duplicate of this bug. ***
Comment 6 CVS Commits 2004-04-30 17:46:57 UTC
Subject: Bug 14220

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	paolo@gcc.gnu.org	2004-04-30 17:46:52

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc 
Added files:
	libstdc++-v3/testsuite/22_locale/num_put/put/char: 14220.cc 
	libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t: 14220.cc 

Log message:
	2004-04-30  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/14220
	* include/bits/locale_facets.tcc (num_put<>::_M_insert_float):
	Don't clip the precision passed down to __convert_from_v:
	22.2.2.2.2 nowhere says so.
	* testsuite/22_locale/num_put/put/char/14220.cc: New.
	* testsuite/22_locale/num_put/put/wchar_t/14220.c: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2224.2.93&r2=1.2224.2.94
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.166.2.10&r2=1.166.2.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/char/14220.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/14220.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 7 Mark Mitchell 2004-06-12 22:57:49 UTC
Marked as 3.5 only, so retargeting at 3.5.0.
Comment 8 Paolo Carlini 2004-06-13 08:34:14 UTC
Actually, this is already fixed for 3.4.1. I want to put the fix on hold for 3.5
only because with Benjamin we have a plan to branch a separate 7.0 branch where a
pending invasive patch will interfere with this fix... 
Comment 9 Mark Mitchell 2004-06-18 23:55:20 UTC
Really retargeting at 3.5.0 this time.
Comment 10 CVS Commits 2004-07-29 22:11:23 UTC
Subject: Bug 14220

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2004-07-29 22:11:05

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc 
Added files:
	libstdc++-v3/testsuite/22_locale/num_put/put/char: 14220.cc 
	libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t: 14220.cc 

Log message:
	2004-07-29  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/14220
	* include/bits/locale_facets.tcc (num_put<>::_M_insert_float):
	Don't clip the precision passed down to __convert_from_v:
	22.2.2.2.2 nowhere says so.
	* testsuite/22_locale/num_put/put/char/14220.cc: New.
	* testsuite/22_locale/num_put/put/wchar_t/14220.c: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2592&r2=1.2593
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&r1=1.196&r2=1.197
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/char/14220.cc.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/14220.cc.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 11 Paolo Carlini 2004-07-29 22:14:23 UTC
Fixed everywhere.