Ross Smith <r-smith@ihug.co.nz> Paolo Carlini <pcarlini@unitus.it>

2001-12-12  Philip Martin  <philip@codematters.co.uk>
            Ross Smith     <r-smith@ihug.co.nz>
            Paolo Carlini  <pcarlini@unitus.it>

	libstdc++/5045
	* include/bits/std_limits.h (defines, numeric_limits<bool>::digits10):
	Fix digits10 values for integral types.
	* include/bits/locale_facets.tcc (num_get::do_get for integral types):
	Tweak _M_extract_int call.
	* testsuite/27_io/istream_extractor_arith.cc (test13, test12_aux):
	Tweak overflowing number of digits.
	* testsuite/18_support/numeric_limits.cc (test03): New testcase.

Co-Authored-By: Paolo Carlini <pcarlini@unitus.it>
Co-Authored-By: Ross Smith <r-smith@ihug.co.nz>

From-SVN: r47947
This commit is contained in:
Philip Martin 2001-12-12 20:23:30 +00:00 committed by Paolo Carlini
parent 2bee604524
commit cb93dfb4a0
5 changed files with 59 additions and 18 deletions

View file

@ -1,3 +1,16 @@
2001-12-12 Philip Martin <philip@codematters.co.uk>
Ross Smith <r-smith@ihug.co.nz>
Paolo Carlini <pcarlini@unitus.it>
libstdc++/5045
* include/bits/std_limits.h (defines, numeric_limits<bool>::digits10):
Fix digits10 values for integral types.
* include/bits/locale_facets.tcc (num_get::do_get for integral types):
Tweak _M_extract_int call.
* testsuite/27_io/istream_extractor_arith.cc (test13, test12_aux):
Tweak overflowing number of digits.
* testsuite/18_support/numeric_limits.cc (test03): New testcase.
2001-12-11 Benjamin Kosnik <bkoz@redhat.com>
* config/os/generic/bits/ctype_inline.h: Remove spaces.

View file

@ -390,8 +390,12 @@ namespace std
// integral types
char __xtrc[32];
int __base;
// According to 18.2.1.2.9, digits10 is "Number of base 10 digits
// that can be represented without change" so we have to add 1 to it
// in order to obtain the max number of digits. The same for the
// other do_get for integral types below.
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<bool>::digits10, __base);
numeric_limits<bool>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -456,7 +460,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<long>::digits10, __base);
numeric_limits<long>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -482,7 +486,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<unsigned short>::digits10, __base);
numeric_limits<unsigned short>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -509,7 +513,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<unsigned int>::digits10, __base);
numeric_limits<unsigned int>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -536,7 +540,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<unsigned long>::digits10, __base);
numeric_limits<unsigned long>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -563,7 +567,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<long long>::digits10, __base);
numeric_limits<long long>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -589,7 +593,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<unsigned long long>::digits10, __base);
numeric_limits<unsigned long long>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;
@ -718,7 +722,7 @@ namespace std
char __xtrc[32];
int __base;
_M_extract_int(__beg, __end, __io, __err, __xtrc,
numeric_limits<unsigned long>::digits10, __base);
numeric_limits<unsigned long>::digits10 + 1, __base);
// Stage 2: convert and store results.
char* __sanity;

View file

@ -144,31 +144,31 @@
#define __glibcpp_s8_max 127
#define __glibcpp_s8_min (-__glibcpp_s8_max - 1)
#define __glibcpp_s8_digits 7
#define __glibcpp_s8_digits10 3
#define __glibcpp_s8_digits10 2
#define __glibcpp_u8_min 0U
#define __glibcpp_u8_max (__glibcpp_s8_max * 2 + 1)
#define __glibcpp_u8_digits 8
#define __glibcpp_u8_digits10 3
#define __glibcpp_u8_digits10 2
#define __glibcpp_s16_max 32767
#define __glibcpp_s16_min (-__glibcpp_s16_max - 1)
#define __glibcpp_s16_digits 15
#define __glibcpp_s16_digits10 5
#define __glibcpp_s16_digits10 4
#define __glibcpp_u16_min 0U
#define __glibcpp_u16_max (__glibcpp_s16_max * 2 + 1)
#define __glibcpp_u16_digits 16
#define __glibcpp_u16_digits10 5
#define __glibcpp_u16_digits10 4
#define __glibcpp_s32_max 2147483647L
#define __glibcpp_s32_min (-__glibcpp_s32_max - 1)
#define __glibcpp_s32_digits 31
#define __glibcpp_s32_digits10 10
#define __glibcpp_s32_digits10 9
#define __glibcpp_u32_min 0UL
#define __glibcpp_u32_max (__glibcpp_s32_max * 2U + 1)
#define __glibcpp_u32_digits 32
#define __glibcpp_u32_digits10 10
#define __glibcpp_u32_digits10 9
#define __glibcpp_s64_max 9223372036854775807LL
#define __glibcpp_s64_min (-__glibcpp_s64_max - 1)
#define __glibcpp_s64_digits 63
#define __glibcpp_s64_digits10 19
#define __glibcpp_s64_digits10 18
#define __glibcpp_u64_min 0ULL
#define __glibcpp_u64_max (__glibcpp_s64_max * 2ULL + 1)
#define __glibcpp_u64_digits 64
@ -1033,7 +1033,7 @@ namespace std
{ return true; }
static const int digits = __glibcpp_bool_digits;
static const int digits10 = 1;
static const int digits10 = 0;
static const bool is_signed = false;
static const bool is_integer = true;
static const bool is_exact = true;

View file

@ -155,10 +155,34 @@ void test02()
const bool* pb1 = &b_nl_type::traps;
}
// libstdc++/5045
bool test03()
{
bool test = true;
VERIFY( std::numeric_limits<bool>::digits10 == 0 );
VERIFY( __glibcpp_s8_digits10 == 2 );
VERIFY( __glibcpp_u8_digits10 == 2 );
VERIFY( __glibcpp_s16_digits10 == 4 );
VERIFY( __glibcpp_u16_digits10 == 4 );
VERIFY( __glibcpp_s32_digits10 == 9 );
VERIFY( __glibcpp_u32_digits10 == 9 );
VERIFY( __glibcpp_s64_digits10 == 18 );
VERIFY( __glibcpp_u64_digits10 == 19 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
}
int main()
{
test01();
test02();
test03();
test_extrema<char>();
test_extrema<signed char>();

View file

@ -523,7 +523,7 @@ bool test12_aux(bool integer_type)
int digits_overflow;
if (integer_type)
// This many digits will overflow integer types in base 10.
digits_overflow = std::numeric_limits<T>::digits10 + 1;
digits_overflow = std::numeric_limits<T>::digits10 + 2;
else
// This might do it, unsure.
digits_overflow = std::numeric_limits<T>::max_exponent10 + 1;
@ -573,7 +573,7 @@ void test13()
// 2
// quick test for failbit on maximum length extraction.
int i;
int max_digits = numeric_limits<int>::digits10;
int max_digits = numeric_limits<int>::digits10 + 1;
string digits;
for (int j = 0; j < max_digits; ++j)
digits += '1';