| 1 |
// { dg-add-options ieee } |
| 2 |
|
| 3 |
// 1999-08-23 bkoz |
| 4 |
|
| 5 |
// Copyright (C) 1999-2025 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 defined WCHAR_MIN && defined WCHAR_MAX |
| 52 |
DEFINE_EXTREMA(wchar_t, WCHAR_MIN, WCHAR_MAX); |
| 53 |
#endif |
| 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> |
| 62 |
void test_extrema() |
| 63 |
{ |
| 64 |
T limits_min = std::numeric_limits<T>::min(); |
| 65 |
T limits_max = std::numeric_limits<T>::max(); |
| 66 |
T extrema_min = extrema<T>::min; |
| 67 |
T extrema_max = extrema<T>::max; |
| 68 |
VERIFY( extrema_min == limits_min ); |
| 69 |
VERIFY( extrema_max == limits_max ); |
| 70 |
} |
| 71 |
|
| 72 |
int main() |
| 73 |
{ |
| 74 |
test_extrema<char>(); |
| 75 |
test_extrema<signed char>(); |
| 76 |
test_extrema<unsigned char>(); |
| 77 |
|
| 78 |
test_extrema<short>(); |
| 79 |
test_extrema<unsigned short>(); |
| 80 |
|
| 81 |
test_extrema<int>(); |
| 82 |
test_extrema<unsigned>(); |
| 83 |
|
| 84 |
test_extrema<long>(); |
| 85 |
test_extrema<unsigned long>(); |
| 86 |
|
| 87 |
test_extrema<float>(); |
| 88 |
test_extrema<double>(); |
| 89 |
test_extrema<long double>(); |
| 90 |
|
| 91 |
return 0; |
| 92 |
} |