Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
18.limits.cvqual.cpp
Go to the documentation of this file.
1
33#include <limits>
34
35#include <rw_driver.h>
36
37
39template <class T>
41{
42 const T val_;
43
44 UserType (T val = T ()): val_ (val) { /* empty */}
45
46 operator T () const { return val_; }
47};
48
49
50template <class T, class CVQualifiedT>
51void test_limits (const volatile T*, CVQualifiedT*,
52 const char *tname,
53 const char *quals)
54{
55#ifndef _RWSTD_NO_EXT_CV_QUALIFIED_LIMITS
56
57 typedef std::numeric_limits<T> limits;
58 typedef std::numeric_limits<CVQualifiedT> cv_limits;
59
60 // verify that the member has the same value as the same member
61 // of a specialization of numeric_limits on the cv-qualified T
62# define TEST(member) \
63 rw_assert (limits::member == cv_limits::member, 0, __LINE__, \
64 "numeric_limits<%s>::%s == numeric_limits<%s %1$s>::%2$s", \
65 tname, #member, quals)
66#else // if defined (_RWSTD_NO_EXT_CV_QUALIFIED_LIMITS)
67
68 typedef std::numeric_limits<UserType<T> > limits;
69 typedef std::numeric_limits<CVQualifiedT> cv_limits;
70
71 // verify that the member has the same value as the same member
72 // of a specialization of numeric_limits on some user-defined T
73 // (i.e., the primary template)
74# define TEST(member) \
75 rw_assert (limits::member == cv_limits::member, 0, __LINE__, \
76 "numeric_limits<%s>::%s == numeric_limits<%s %1$s>::%2$s", \
77 tname, #member, quals)
78#endif // _RWSTD_NO_EXT_CV_QUALIFIED_LIMITS
79
80 TEST (is_specialized);
81 TEST (min ());
82 TEST (max ());
83 TEST (digits);
84 TEST (digits10);
85 TEST (is_signed);
87 TEST (is_exact);
88 TEST (radix);
89
90 TEST (epsilon ());
91 TEST (round_error ());
92
93 TEST (min_exponent);
94 TEST (min_exponent10);
95 TEST (max_exponent);
96 TEST (max_exponent10);
97
98 TEST (has_infinity);
99 TEST (has_quiet_NaN);
100 TEST (has_signaling_NaN);
101 TEST (has_denorm);
102 TEST (has_denorm_loss);
103
104 TEST (infinity ());
105
106 if (limits::is_integer) {
107 TEST (quiet_NaN ());
108 TEST (signaling_NaN ());
109 }
110 else {
111 const bool expect = limits::has_quiet_NaN;
112
113 rw_assert (expect == (limits::quiet_NaN () != cv_limits::quiet_NaN ()),
114 0, __LINE__,
115 "numeric_limits<%s>::qNaN() %{?}!=%{:}==%{;} "
116 "numeric_limits<%s %1$s>::qNaN ()",
117 tname, expect, quals);
118 }
119
120 TEST (denorm_min ());
121
122 TEST (is_iec559);
123 TEST (is_bounded);
124 TEST (is_modulo);
125 TEST (traps);
126 TEST (tinyness_before);
127 TEST (round_style);
128}
129
130
132template <class T>
133void test_limits (const volatile T*, const char *tname)
134{
135 typedef const T const_T;
136 typedef volatile T volatile_T;
137 typedef const volatile T const_volatile_T;
138
139 rw_info (0, 0, __LINE__,
140 "std::numeric_limits<T> with T = cv-qualified %s", tname);
141
142 test_limits ((T*)0, (const_T*)0, tname, "const");
143 test_limits ((T*)0, (volatile_T*)0, tname, "volatile");
144 test_limits ((T*)0, (const_volatile_T*)0, tname, "const volatile");
145}
146
147
149static int
150run_test (int, char*[])
151{
152#undef TEST
153#define TEST(T) test_limits ((T*)0, _RWSTD_STRSTR (T))
154
155#ifndef _RWSTD_NO_NATIVE_BOOL
156 TEST (bool);
157#endif // _RWSTD_NO_NATIVE_BOOL
158
159 TEST (char);
160 TEST (signed char);
161 TEST (unsigned char);
162
163 TEST (short);
164 TEST (unsigned short);
165
166 TEST (int);
167 TEST (unsigned);
168
169 TEST (long);
170 TEST (unsigned long);
171
172#ifdef _RWSTD_LONG_LONG
174 TEST (unsigned _RWSTD_LONG_LONG);
175#endif
176
177 TEST (float);
178 TEST (double);
179
180#ifndef _RWSTD_NO_LONG_DOUBLE
181 TEST (long double);
182#endif // _RWSTD_NO_LONG_DOUBLE
183
184#ifndef _RWSTD_NO_NATIVE_WCHAR_T
185 TEST (wchar_t);
186#endif // _RWSTD_NO_NATIVE_WCHAR_T
187
188 return 0;
189}
190
191
193int main (int argc, char *argv[])
194{
195 return rw_test (argc, argv, __FILE__,
196 "lib.numeric.limits",
197
198#ifdef _RWSTD_NO_EXT_CV_QUALIFIED_LIMITS
199 "testing the absence of "
200#endif // _RWSTD_NO_EXT_CV_QUALIFIED_LIMITS
201 "specializations on cv-qualifed types",
202 run_test,
203 0,
204 (void*)0);
205}
#define T
Definition 17.names.cpp:163
#define val
Definition 17.names.cpp:570
#define TEST(member)
void test_limits(const volatile T *, CVQualifiedT *, const char *tname, const char *quals)
bool is_modulo(T _max)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define _RWSTD_LONG_LONG
constexpr bool is_integer
Metafunction for determining if a type is, or is a reference to, a int64_t or toml::value<int64_t>.
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
UserType(T val=T())
#define min(a, b)
#define max(a, b)