OSDN Git Service

* testsuite/18_support/numeric_limits.cc: Add more tests.
authorgdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 14 Aug 2001 23:34:04 +0000 (23:34 +0000)
committergdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 14 Aug 2001 23:34:04 +0000 (23:34 +0000)
      * include/bits/std_limits.h (numeric_limits<char>::max): Fix
      typo.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44911 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/std_limits.h
libstdc++-v3/testsuite/18_support/numeric_limits.cc

index bee4b92..43743b8 100644 (file)
@@ -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>
  
        * configure.target (cpu_include_dir): Set to `config/cpu/s390'
index 06213ac..2d0804d 100644 (file)
@@ -1123,7 +1123,7 @@ namespace std
       static signed char min() throw()
       { return __glibcpp_signed_char_min; }
       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 digits10 = __glibcpp_signed_char_digits10;
index 6faaa92..0005779 100644 (file)
 // 18.2.1.1 template class numeric_limits
 
 #include <limits>
+#include <limits.h>
+#include <float.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>
   struct A 
@@ -96,5 +154,25 @@ int main()
 {
   test01();
   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;
 }