1 // { dg-add-options ieee }
2 
3 // 1999-08-23 bkoz
4 
5 // Copyright (C) 1999-2013 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library.  This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3.  If not see
20 // <http://www.gnu.org/licenses/>.
21 
22 // 18.2.1.1 template class numeric_limits
23 
24 #include <limits>
25 #include <limits.h>
26 #include <float.h>
27 #include <cwchar>
28 #include <testsuite_hooks.h>
29 
30 template<typename T>
31 struct extrema {
32   static T min;
33   static T max;
34 };
35 
36 
37 #define DEFINE_EXTREMA(T, m, M) \
38   template<> T extrema<T>::min = m; \
39   template<> T extrema<T>::max = M
40 
41 DEFINE_EXTREMA(char, CHAR_MIN, CHAR_MAX);
42 DEFINE_EXTREMA(signed char, SCHAR_MIN, SCHAR_MAX);
43 DEFINE_EXTREMA(unsigned char, 0, UCHAR_MAX);
44 DEFINE_EXTREMA(short, SHRT_MIN, SHRT_MAX);
45 DEFINE_EXTREMA(unsigned short, 0, USHRT_MAX);
46 DEFINE_EXTREMA(int, INT_MIN, INT_MAX);
47 DEFINE_EXTREMA(unsigned, 0U, UINT_MAX);
48 DEFINE_EXTREMA(long, LONG_MIN, LONG_MAX);
49 DEFINE_EXTREMA(unsigned long, 0UL, ULONG_MAX);
50 
51 #if _GLIBCXX_USE_WCHAR_T
52 DEFINE_EXTREMA(wchar_t, WCHAR_MIN, WCHAR_MAX);
53 #endif //_GLIBCXX_USE_WCHAR_T
54 
55 DEFINE_EXTREMA(float, FLT_MIN, FLT_MAX);
56 DEFINE_EXTREMA(double, DBL_MIN, DBL_MAX);
57 DEFINE_EXTREMA(long double, LDBL_MIN, LDBL_MAX);
58 
59 #undef DEFINE_EXTREMA
60 
61 template<typename T>
test_extrema()62 void test_extrema()
63 {
64   bool test __attribute__((unused)) = true;
65   T limits_min = std::numeric_limits<T>::min();
66   T limits_max = std::numeric_limits<T>::max();
67   T extrema_min = extrema<T>::min;
68   T extrema_max = extrema<T>::max;
69   VERIFY( extrema_min == limits_min );
70   VERIFY( extrema_max == limits_max );
71 }
72 
main()73 int main()
74 {
75   test_extrema<char>();
76   test_extrema<signed char>();
77   test_extrema<unsigned char>();
78 
79   test_extrema<short>();
80   test_extrema<unsigned short>();
81 
82   test_extrema<int>();
83   test_extrema<unsigned>();
84 
85   test_extrema<long>();
86   test_extrema<unsigned long>();
87 
88   test_extrema<float>();
89   test_extrema<double>();
90   test_extrema<long double>();
91 
92   return 0;
93 }
94