| 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 A |
| 32 | { |
| 33 | int key; |
| 34 | public: |
| 35 | A(int i = 0): key(i) { } |
| 36 | bool |
| 37 | operator==(int i) { return i == key; } |
| 38 | }; |
| 39 | |
| 40 | struct B |
| 41 | { |
| 42 | B(int = 0) { } |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | void test01() |
| 47 | { |
| 48 | std::numeric_limits< A<B> > obj; |
| 49 | |
| 50 | VERIFY( !obj.is_specialized ); |
| 51 | VERIFY( obj.min() == 0 ); |
| 52 | VERIFY( obj.max() == 0 ); |
| 53 | VERIFY( obj.digits == 0 ); |
| 54 | VERIFY( obj.digits10 == 0 ); |
| 55 | VERIFY( !obj.is_signed ); |
| 56 | VERIFY( !obj.is_integer ); |
| 57 | VERIFY( !obj.is_exact ); |
| 58 | VERIFY( obj.radix == 0 ); |
| 59 | VERIFY( obj.epsilon() == 0 ); |
| 60 | VERIFY( obj.round_error() == 0 ); |
| 61 | VERIFY( obj.min_exponent == 0 ); |
| 62 | VERIFY( obj.min_exponent10 == 0 ); |
| 63 | VERIFY( obj.max_exponent == 0 ); |
| 64 | VERIFY( obj.max_exponent10 == 0 ); |
| 65 | VERIFY( !obj.has_infinity ); |
| 66 | VERIFY( !obj.has_quiet_NaN ); |
| 67 | VERIFY( !obj.has_signaling_NaN ); |
| 68 | VERIFY( !obj.has_denorm ); |
| 69 | VERIFY( !obj.has_denorm_loss ); |
| 70 | VERIFY( obj.infinity() == 0 ); |
| 71 | VERIFY( obj.quiet_NaN() == 0 ); |
| 72 | VERIFY( obj.signaling_NaN() == 0 ); |
| 73 | VERIFY( obj.denorm_min() == 0 ); |
| 74 | VERIFY( !obj.is_iec559 ); |
| 75 | VERIFY( !obj.is_bounded ); |
| 76 | VERIFY( !obj.is_modulo ); |
| 77 | VERIFY( !obj.traps ); |
| 78 | VERIFY( !obj.tinyness_before ); |
| 79 | VERIFY( obj.round_style == std::round_toward_zero ); |
| 80 | } |
| 81 | |
| 82 | // test linkage of the generic bits |
| 83 | template struct std::numeric_limits<B>; |
| 84 | |
| 85 | void test02() |
| 86 | { |
| 87 | typedef std::numeric_limits<B> b_nl_type; |
| 88 | |
| 89 | // Should probably do all of them... |
| 90 | const int* __attribute__((unused)) pi1 = &b_nl_type::digits; |
| 91 | const int* __attribute__((unused)) pi2 = &b_nl_type::digits10; |
| 92 | const int* __attribute__((unused)) pi3 = &b_nl_type::max_exponent10; |
| 93 | const bool* __attribute__((unused)) pb1 = &b_nl_type::traps; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | int main() |
| 98 | { |
| 99 | test01(); |
| 100 | test02(); |
| 101 | |
| 102 | return 0; |
| 103 | } |