mirror of git://gcc.gnu.org/git/gcc.git
numeric_limits.cc: Add more tests.
* testsuite/18_support/numeric_limits.cc: Add more tests.
* include/bits/std_limits.h (numeric_limits<char>::max): Fix
typo.
From-SVN: r44911
This commit is contained in:
parent
abb788ba5b
commit
1489e3241e
|
|
@ -1,3 +1,9 @@
|
||||||
|
2001-08-15 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
|
||||||
|
|
||||||
|
* testsuite/18_support/numeric_limits.cc: Add more tests.
|
||||||
|
* include/bits/std_limits.h (numeric_limits<char>::max): Fix
|
||||||
|
typo.
|
||||||
|
|
||||||
2001-08-14 Ulrich Weigand <uweigand@de.ibm.com>
|
2001-08-14 Ulrich Weigand <uweigand@de.ibm.com>
|
||||||
|
|
||||||
* configure.target (cpu_include_dir): Set to `config/cpu/s390'
|
* configure.target (cpu_include_dir): Set to `config/cpu/s390'
|
||||||
|
|
|
||||||
|
|
@ -1123,7 +1123,7 @@ namespace std
|
||||||
static signed char min() throw()
|
static signed char min() throw()
|
||||||
{ return __glibcpp_signed_char_min; }
|
{ return __glibcpp_signed_char_min; }
|
||||||
static signed char max() throw()
|
static signed char max() throw()
|
||||||
{ return __glibcpp_signed_char_min; }
|
{ return __glibcpp_signed_char_max; }
|
||||||
|
|
||||||
static const int digits = __glibcpp_signed_char_digits;
|
static const int digits = __glibcpp_signed_char_digits;
|
||||||
static const int digits10 = __glibcpp_signed_char_digits10;
|
static const int digits10 = __glibcpp_signed_char_digits10;
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,66 @@
|
||||||
// 18.2.1.1 template class numeric_limits
|
// 18.2.1.1 template class numeric_limits
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct extrema {
|
||||||
|
static T min;
|
||||||
|
static T max;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define DEFINE_EXTREMA(T, m, M) \
|
||||||
|
template<> T extrema<T>::min = m; \
|
||||||
|
template<> T extrema<T>::max = M
|
||||||
|
|
||||||
|
DEFINE_EXTREMA(char, CHAR_MIN, CHAR_MAX);
|
||||||
|
DEFINE_EXTREMA(signed char, SCHAR_MIN, SCHAR_MAX);
|
||||||
|
DEFINE_EXTREMA(unsigned char, 0, UCHAR_MAX);
|
||||||
|
DEFINE_EXTREMA(short, SHRT_MIN, SHRT_MAX);
|
||||||
|
DEFINE_EXTREMA(unsigned short, 0, USHRT_MAX);
|
||||||
|
DEFINE_EXTREMA(int, INT_MIN, INT_MAX);
|
||||||
|
DEFINE_EXTREMA(unsigned, 0U, UINT_MAX);
|
||||||
|
DEFINE_EXTREMA(long, LONG_MIN, LONG_MAX);
|
||||||
|
DEFINE_EXTREMA(unsigned long, 0UL, ULONG_MAX);
|
||||||
|
|
||||||
|
DEFINE_EXTREMA(float, FLT_MIN, FLT_MAX);
|
||||||
|
DEFINE_EXTREMA(double, DBL_MIN, DBL_MAX);
|
||||||
|
DEFINE_EXTREMA(long double, LDBL_MIN, LDBL_MAX);
|
||||||
|
|
||||||
|
#undef DEFINE_EXTREMA
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void test_extrema()
|
||||||
|
{
|
||||||
|
VERIFY( extrema<T>::min == std::numeric_limits<T>::min() );
|
||||||
|
VERIFY( extrema<T>::max == std::numeric_limits<T>::max() );
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __CHAR_UNSIGNED__
|
||||||
|
#define char_is_signed false
|
||||||
|
#else
|
||||||
|
#define char_is_signed true
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void test_sign()
|
||||||
|
{
|
||||||
|
VERIFY( std::numeric_limits<char>::is_signed == char_is_signed );
|
||||||
|
VERIFY( std::numeric_limits<signed char>::is_signed == true );
|
||||||
|
VERIFY( std::numeric_limits<unsigned char>::is_signed == false );
|
||||||
|
VERIFY( std::numeric_limits<short>::is_signed == true );
|
||||||
|
VERIFY( std::numeric_limits<unsigned short>::is_signed == false );
|
||||||
|
VERIFY( std::numeric_limits<int>::is_signed == true );
|
||||||
|
VERIFY( std::numeric_limits<unsigned>::is_signed == false );
|
||||||
|
VERIFY( std::numeric_limits<long>::is_signed == true );
|
||||||
|
VERIFY( std::numeric_limits<unsigned long>::is_signed == false );
|
||||||
|
VERIFY( std::numeric_limits<float>::is_signed == true );
|
||||||
|
VERIFY( std::numeric_limits<double>::is_signed == true );
|
||||||
|
VERIFY( std::numeric_limits<long double>::is_signed == true );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct A
|
struct A
|
||||||
|
|
@ -96,5 +154,25 @@ int main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
test02();
|
test02();
|
||||||
return 0;
|
|
||||||
|
test_extrema<char>();
|
||||||
|
test_extrema<signed char>();
|
||||||
|
test_extrema<unsigned char>();
|
||||||
|
|
||||||
|
test_extrema<short>();
|
||||||
|
test_extrema<unsigned short>();
|
||||||
|
|
||||||
|
test_extrema<int>();
|
||||||
|
test_extrema<unsigned>();
|
||||||
|
|
||||||
|
test_extrema<long>();
|
||||||
|
test_extrema<unsigned long>();
|
||||||
|
|
||||||
|
test_extrema<float>();
|
||||||
|
test_extrema<double>();
|
||||||
|
test_extrema<long double>();
|
||||||
|
|
||||||
|
test_sign();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue