Update copyright in libstdc++-v3.
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / numeric_limits / min_max.cc
blobc26e03f7390503240c8bf6ae50d3cb1580357a5e
1 // { dg-add-options ieee }
3 // 1999-08-23 bkoz
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.
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.
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/>.
22 // 18.2.1.1 template class numeric_limits
24 #include <limits>
25 #include <limits.h>
26 #include <float.h>
27 #include <cwchar>
28 #include <testsuite_hooks.h>
30 template<typename T>
31 struct extrema {
32 static T min;
33 static T max;
37 #define DEFINE_EXTREMA(T, m, M) \
38 template<> T extrema<T>::min = m; \
39 template<> T extrema<T>::max = M
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);
51 #if _GLIBCXX_USE_WCHAR_T
52 DEFINE_EXTREMA(wchar_t, WCHAR_MIN, WCHAR_MAX);
53 #endif //_GLIBCXX_USE_WCHAR_T
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);
59 #undef DEFINE_EXTREMA
61 template<typename T>
62 void test_extrema()
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 );
73 int main()
75 test_extrema<char>();
76 test_extrema<signed char>();
77 test_extrema<unsigned char>();
79 test_extrema<short>();
80 test_extrema<unsigned short>();
82 test_extrema<int>();
83 test_extrema<unsigned>();
85 test_extrema<long>();
86 test_extrema<unsigned long>();
88 test_extrema<float>();
89 test_extrema<double>();
90 test_extrema<long double>();
92 return 0;