1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
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)
14 \brief test_limits.cpp
17 Test numeric_limits specialization.
27 #include <boost/units/limits.hpp>
28 #include <boost/units/cmath.hpp>
30 #include "test_header.hpp"
32 typedef boost::units::length unit_type;
33 using boost::units::quantity;
36 struct check_quiet_NaN;
39 struct check_quiet_NaN<true> {
42 quantity<unit_type, T> q((std::numeric_limits<quantity<unit_type, T> >::quiet_NaN)());
43 bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q);
49 struct check_quiet_NaN<false> {
51 static void apply() {}
55 struct check_signaling_NaN;
58 struct check_signaling_NaN<true> {
61 quantity<unit_type, T> q((std::numeric_limits<quantity<unit_type, T> >::signaling_NaN)());
62 bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q);
68 struct check_signaling_NaN<false> {
70 static void apply() {}
75 #define CHECK_FUNCTION(name) BOOST_CHECK(((std::numeric_limits<T>::name)() == (std::numeric_limits<quantity<unit_type, T> >::name)().value()))
76 #define CHECK_CONSTANT(name) BOOST_CHECK((std::numeric_limits<T>::name == std::numeric_limits<quantity<unit_type, T> >::name))
79 CHECK_FUNCTION(epsilon);
80 CHECK_FUNCTION(round_error);
81 CHECK_FUNCTION(infinity);
82 CHECK_FUNCTION(denorm_min);
84 CHECK_CONSTANT(is_specialized);
85 CHECK_CONSTANT(digits);
86 CHECK_CONSTANT(digits10);
87 CHECK_CONSTANT(is_signed);
88 CHECK_CONSTANT(is_integer);
89 CHECK_CONSTANT(is_exact);
90 CHECK_CONSTANT(radix);
91 CHECK_CONSTANT(min_exponent);
92 CHECK_CONSTANT(min_exponent10);
93 CHECK_CONSTANT(max_exponent);
94 CHECK_CONSTANT(max_exponent10);
95 CHECK_CONSTANT(has_infinity);
96 CHECK_CONSTANT(has_quiet_NaN);
97 CHECK_CONSTANT(has_signaling_NaN);
98 CHECK_CONSTANT(has_denorm);
99 CHECK_CONSTANT(has_denorm_loss);
100 CHECK_CONSTANT(is_iec559);
101 CHECK_CONSTANT(is_bounded);
102 CHECK_CONSTANT(is_modulo);
103 CHECK_CONSTANT(traps);
104 CHECK_CONSTANT(tinyness_before);
105 CHECK_CONSTANT(round_style);
107 check_quiet_NaN<std::numeric_limits<quantity<unit_type, T> >::has_quiet_NaN>::template apply<T>();
108 check_signaling_NaN<std::numeric_limits<quantity<unit_type, T> >::has_signaling_NaN>::template apply<T>();
111 int test_main(int,char *[])
117 do_check<unsigned>();
118 do_check<std::complex<double> >();