Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
limits.cpp
Go to the documentation of this file.
1
30#include <limits> // for numeric_limits
31#include <iostream> // for cout
32
33#include <examples.h>
34
35
36std::ostream& operator<< (std::ostream &strm, std::float_denorm_style style)
37{
38 const char* name = "(unknown)";
39
40 switch (style) {
41 case std::denorm_absent: name = "std::denorm_absent"; break;
42 case std::denorm_indeterminate: name = "std::denorm_indeterminate"; break;
43 case std::denorm_present: name = "std::denorm_present"; break;
44 }
45
46 return strm << name;
47}
48
49
50template <class T>
51void print_limits (std::ostream &strm, const char *tname, T)
52{
53#define PRINT_MEMBER(type, member) \
54 strm << " static " << type << " " #member " = " \
55 << std::numeric_limits<T>::member << ";\n"
56
57 strm << "struct std::numeric_limits<" << tname << "> {\n";
58
59 PRINT_MEMBER ("const bool", is_specialized);
60
61 PRINT_MEMBER (tname, min ());
62 PRINT_MEMBER (tname, max ());
63
64 PRINT_MEMBER ("const int", digits);
65 PRINT_MEMBER ("const int", digits10);
66
67 PRINT_MEMBER ("const bool", is_signed);
68 PRINT_MEMBER ("const bool", is_integer);
69 PRINT_MEMBER ("const bool", is_exact);
70 PRINT_MEMBER ("const int", radix);
71
72 PRINT_MEMBER (tname, epsilon ());
73 PRINT_MEMBER ("int", round_error ());
74
75 PRINT_MEMBER ("const int", min_exponent);
76 PRINT_MEMBER ("const int", min_exponent10);
77 PRINT_MEMBER ("const int", max_exponent);
78 PRINT_MEMBER ("const int", max_exponent10);
79
80 PRINT_MEMBER ("const bool", has_infinity);
81 PRINT_MEMBER ("const bool", has_quiet_NaN);
82 PRINT_MEMBER ("const bool", has_signaling_NaN);
83 PRINT_MEMBER ("const std::float_denorm_style", has_denorm);
84
85 PRINT_MEMBER ("const bool", has_denorm_loss);
86
87 PRINT_MEMBER (tname, infinity ());
88 PRINT_MEMBER (tname, quiet_NaN ());
89 PRINT_MEMBER (tname, signaling_NaN ());
90 PRINT_MEMBER (tname, denorm_min ());
91
92 PRINT_MEMBER ("const bool", is_iec559);
93 PRINT_MEMBER ("const bool", is_bounded);
94 PRINT_MEMBER ("const bool", is_modulo);
95
96 PRINT_MEMBER ("const bool", traps);
97 PRINT_MEMBER ("const bool", tinyness_before);
98
99 PRINT_MEMBER ("const int", round_style);
100
101 strm << "};\n";
102}
103
104
105int main ()
106{
107#define PRINT_LIMITS(T) print_limits (std::cout, #T, T ())
108
109 // print bool values as "false" and "true"
110 std::cout.setf (std::cout.boolalpha);
111
112 // print the numeric limits for an integer type
113 PRINT_LIMITS (int);
114
115 std::cout << '\n';
116
117 // print the numeric limits for a floating point type
118 PRINT_LIMITS (double);
119
120 return 0;
121}
#define T
Definition 17.names.cpp:163
#define strm
Definition 17.names.cpp:549
bool is_modulo(T _max)
#define boolalpha
const char * name
Definition codecvt1.cpp:72
std::ostream & operator<<(std::ostream &strm, std::float_denorm_style style)
Definition limits.cpp:36
void print_limits(std::ostream &strm, const char *tname, T)
Definition limits.cpp:51
#define PRINT_LIMITS(T)
#define PRINT_MEMBER(type, member)
int main()
Definition limits.cpp:105
constexpr bool is_integer
Metafunction for determining if a type is, or is a reference to, a int64_t or toml::value<int64_t>.
#define min(a, b)
#define max(a, b)