1 | // Boost.Units - A C++ library for zero-overhead dimensional analysis and |
---|---|
2 | // unit/quantity manipulation and conversion |
3 | // |
4 | // Copyright (C) 2003-2008 Matthias Christian Schabel |
5 | // Copyright (C) 2008 Steven Watanabe |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See |
8 | // accompanying file LICENSE_1_0.txt or copy at |
9 | // http://www.boost.org/LICENSE_1_0.txt) |
10 | |
11 | /** |
12 | \file |
13 | |
14 | \brief test_limits.cpp |
15 | |
16 | \details |
17 | Test numeric_limits specialization. |
18 | |
19 | Output: |
20 | @verbatim |
21 | @endverbatim |
22 | **/ |
23 | |
24 | #include <complex> |
25 | #include <limits> |
26 | |
27 | #include <boost/units/limits.hpp> |
28 | #include <boost/units/cmath.hpp> |
29 | |
30 | #include "test_header.hpp" |
31 | |
32 | typedef boost::units::length unit_type; |
33 | using boost::units::quantity; |
34 | |
35 | template<bool> |
36 | struct check_quiet_NaN; |
37 | |
38 | template<> |
39 | struct check_quiet_NaN<true> { |
40 | template<class T> |
41 | static void apply() { |
42 | quantity<unit_type, T> q((std::numeric_limits<quantity<unit_type, T> >::quiet_NaN)()); |
43 | bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); |
44 | BOOST_TEST(test); |
45 | } |
46 | }; |
47 | |
48 | template<> |
49 | struct check_quiet_NaN<false> { |
50 | template<class T> |
51 | static void apply() {} |
52 | }; |
53 | |
54 | template<bool> |
55 | struct check_signaling_NaN; |
56 | |
57 | template<> |
58 | struct check_signaling_NaN<true> { |
59 | template<class T> |
60 | static void apply() { |
61 | quantity<unit_type, T> q((std::numeric_limits<quantity<unit_type, T> >::signaling_NaN)()); |
62 | bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); |
63 | BOOST_TEST(test); |
64 | } |
65 | }; |
66 | |
67 | template<> |
68 | struct check_signaling_NaN<false> { |
69 | template<class T> |
70 | static void apply() {} |
71 | }; |
72 | |
73 | template<class T> |
74 | void do_check() { |
75 | #define CHECK_FUNCTION(name) BOOST_TEST(((std::numeric_limits<T>::name)() == (std::numeric_limits<quantity<unit_type, T> >::name)().value())) |
76 | #define CHECK_CONSTANT(name) BOOST_TEST((std::numeric_limits<T>::name == std::numeric_limits<quantity<unit_type, T> >::name)) |
77 | CHECK_FUNCTION(min); |
78 | CHECK_FUNCTION(max); |
79 | CHECK_FUNCTION(epsilon); |
80 | CHECK_FUNCTION(round_error); |
81 | CHECK_FUNCTION(infinity); |
82 | CHECK_FUNCTION(denorm_min); |
83 | #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS |
84 | CHECK_FUNCTION(lowest); |
85 | #endif |
86 | |
87 | CHECK_CONSTANT(is_specialized); |
88 | CHECK_CONSTANT(digits); |
89 | CHECK_CONSTANT(digits10); |
90 | #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS |
91 | CHECK_CONSTANT(max_digits10); |
92 | #endif |
93 | CHECK_CONSTANT(is_signed); |
94 | CHECK_CONSTANT(is_integer); |
95 | CHECK_CONSTANT(is_exact); |
96 | CHECK_CONSTANT(radix); |
97 | CHECK_CONSTANT(min_exponent); |
98 | CHECK_CONSTANT(min_exponent10); |
99 | CHECK_CONSTANT(max_exponent); |
100 | CHECK_CONSTANT(max_exponent10); |
101 | CHECK_CONSTANT(has_infinity); |
102 | CHECK_CONSTANT(has_quiet_NaN); |
103 | CHECK_CONSTANT(has_signaling_NaN); |
104 | CHECK_CONSTANT(has_denorm); |
105 | CHECK_CONSTANT(has_denorm_loss); |
106 | CHECK_CONSTANT(is_iec559); |
107 | CHECK_CONSTANT(is_bounded); |
108 | CHECK_CONSTANT(is_modulo); |
109 | CHECK_CONSTANT(traps); |
110 | CHECK_CONSTANT(tinyness_before); |
111 | CHECK_CONSTANT(round_style); |
112 | |
113 | check_quiet_NaN<std::numeric_limits<quantity<unit_type, T> >::has_quiet_NaN>::template apply<T>(); |
114 | check_signaling_NaN<std::numeric_limits<quantity<unit_type, T> >::has_signaling_NaN>::template apply<T>(); |
115 | } |
116 | |
117 | int main() |
118 | { |
119 | do_check<float>(); |
120 | do_check<double>(); |
121 | do_check<int>(); |
122 | do_check<long>(); |
123 | do_check<unsigned>(); |
124 | do_check<std::complex<double> >(); |
125 | |
126 | return boost::report_errors(); |
127 | } |
128 |