// Boost.Units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2008 Matthias Christian Schabel // Copyright (C) 2008 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) /** \file \brief test_limits.cpp \details Test numeric_limits specialization. Output: @verbatim @endverbatim **/ #include #include #include #include #include "test_header.hpp" typedef boost::units::length unit_type; using boost::units::quantity; template struct check_quiet_NaN; template<> struct check_quiet_NaN { template static void apply() { quantity q((std::numeric_limits >::quiet_NaN)()); bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); BOOST_CHECK(test); } }; template<> struct check_quiet_NaN { template static void apply() {} }; template struct check_signaling_NaN; template<> struct check_signaling_NaN { template static void apply() { quantity q((std::numeric_limits >::signaling_NaN)()); bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); BOOST_CHECK(test); } }; template<> struct check_signaling_NaN { template static void apply() {} }; template void do_check() { #define CHECK_FUNCTION(name) BOOST_CHECK(((std::numeric_limits::name)() == (std::numeric_limits >::name)().value())) #define CHECK_CONSTANT(name) BOOST_CHECK((std::numeric_limits::name == std::numeric_limits >::name)) CHECK_FUNCTION(min); CHECK_FUNCTION(max); CHECK_FUNCTION(epsilon); CHECK_FUNCTION(round_error); CHECK_FUNCTION(infinity); CHECK_FUNCTION(denorm_min); #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS CHECK_FUNCTION(lowest); #endif CHECK_CONSTANT(is_specialized); CHECK_CONSTANT(digits); CHECK_CONSTANT(digits10); #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS CHECK_CONSTANT(max_digits10); #endif CHECK_CONSTANT(is_signed); CHECK_CONSTANT(is_integer); CHECK_CONSTANT(is_exact); CHECK_CONSTANT(radix); CHECK_CONSTANT(min_exponent); CHECK_CONSTANT(min_exponent10); CHECK_CONSTANT(max_exponent); CHECK_CONSTANT(max_exponent10); CHECK_CONSTANT(has_infinity); CHECK_CONSTANT(has_quiet_NaN); CHECK_CONSTANT(has_signaling_NaN); CHECK_CONSTANT(has_denorm); CHECK_CONSTANT(has_denorm_loss); CHECK_CONSTANT(is_iec559); CHECK_CONSTANT(is_bounded); CHECK_CONSTANT(is_modulo); CHECK_CONSTANT(traps); CHECK_CONSTANT(tinyness_before); CHECK_CONSTANT(round_style); check_quiet_NaN >::has_quiet_NaN>::template apply(); check_signaling_NaN >::has_signaling_NaN>::template apply(); } int test_main(int,char *[]) { do_check(); do_check(); do_check(); do_check(); do_check(); do_check >(); return(0); }