From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1782 invoked by alias); 7 Dec 2001 18:26:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 1736 invoked by uid 71); 7 Dec 2001 18:26:02 -0000 Date: Fri, 07 Dec 2001 10:26:00 -0000 Message-ID: <20011207182602.1732.qmail@sources.redhat.com> To: bkoz@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Philip Martin Subject: Re: libstdc++/3720: Problems with num_get Reply-To: Philip Martin X-SW-Source: 2001-12/txt/msg00432.txt.bz2 List-Id: The following reply was made to PR libstdc++/3720; it has been noted by GNATS. From: Philip Martin To: bkoz@gcc.gnu.org Cc: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, schmid@snake.iap.physik.tu-darmstadt.de Subject: Re: libstdc++/3720: Problems with num_get Date: 07 Dec 2001 18:21:13 +0000 bkoz@gcc.gnu.org writes: > Synopsis: Problems with num_get > > State-Changed-From-To: analyzed->feedback > State-Changed-By: bkoz > State-Changed-When: Fri Dec 7 01:11:50 2001 > State-Changed-Why: > Try this: > > 2001-12-06 Benjamin Kosnik > > libstdc++/3720 > * include/bits/locale_facets.tcc (num_put): Clean. > (num_get::_M_extract_float): Change argument to string. > (num_get::do_get(float)): Fixup. > (num_get::do_get(double)): Same. > (num_get::do_get(long double)): Same. > (num_get::_M_extract_int): Add maximum length parameter, __max. > (num_get::_M_extract_float): Correct zeros, use string. > * include/bits/locale_facets.h (num_get::_M_extract_float): Change > declaration here. > * src/locale.cc (__num_base::_S_atoms): Remove x, X. > * testsuite/27_io/istream_extractor_arith.cc (test13): Add. > > 2001-12-06 Philip Martin > > * testsuite/27_io/istream_extractor_arith.cc > (test12): Add > tests for excess input digits. > > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=3720&database=gcc 1. Looking at the code, there are two calls to log() per integer input in _M_extract_int() in locale_facets.tcc // Figure out the maximum number of digits that can be extracted // for the given type, using the determined base. int __max_digits; if (__base != 10) __max_digits = static_cast(ceil(__max * log(10.0) /log(static_cast(__base)))); else __max_digits = __max; All standard input is in base 8, 10, or 16, so how about something based on if (__base == 10) __max_digits = __max; else if (__base == 8) __max_digits = 1 + __max * 11073 / 10000; // approx. log(10)/log(8) else if (__base == 16) __max_digits = 1 + __max * 8305 / 10000; // approx. log(10)/log(16) else ??? I haven't fully checked if this is accurate enough, however with the truncation to an int no great accuracy is required. 2. You aren't calling test13() from main() in testsuite/27_io/istream_extractor_arith.cc 3. Trying the code, input of std::numeric_limits::max() in octal or hex doesn't appear to work for integers, e.g. reading 017777777777 into a long on x86 doesn't work, it appears to accept one character too few. Decimal works. Philip