Chris@16: // Copyright John Maddock 2010. Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_MATH_CONSTANTS_INFO_INCLUDED Chris@16: #define BOOST_MATH_CONSTANTS_INFO_INCLUDED Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost{ namespace math{ namespace constants{ Chris@16: Chris@16: namespace detail{ Chris@16: Chris@16: template Chris@16: const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) Chris@16: { Chris@16: return typeid(T).name(); Chris@16: } Chris@16: template <> Chris@16: const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float)) Chris@16: { Chris@16: return "float"; Chris@16: } Chris@16: template <> Chris@16: const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double)) Chris@16: { Chris@16: return "double"; Chris@16: } Chris@16: template <> Chris@16: const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double)) Chris@16: { Chris@16: return "long double"; Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: template Chris@16: void print_info_on_type(std::ostream& os = std::cout BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T) BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(Policy)) Chris@16: { Chris@16: using detail::nameof; Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable:4127) Chris@16: #endif Chris@16: os << Chris@16: "Information on the Implementation and Handling of \n" Chris@16: "Mathematical Constants for Type " << nameof() << Chris@16: "\n\n" Chris@16: "Checking for std::numeric_limits<" << nameof() << "> specialisation: " << Chris@16: (std::numeric_limits::is_specialized ? "yes" : "no") << std::endl; Chris@16: if(std::numeric_limits::is_specialized) Chris@16: { Chris@16: os << Chris@16: "std::numeric_limits<" << nameof() << ">::digits reports that the radix is " << std::numeric_limits::radix << ".\n"; Chris@16: if (std::numeric_limits::radix == 2) Chris@16: { Chris@16: os << Chris@16: "std::numeric_limits<" << nameof() << ">::digits reports that the precision is \n" << std::numeric_limits::digits << " binary digits.\n"; Chris@16: } Chris@16: else if (std::numeric_limits::radix == 10) Chris@16: { Chris@16: os << Chris@16: "std::numeric_limits<" << nameof() << ">::digits reports that the precision is \n" << std::numeric_limits::digits10 << " decimal digits.\n"; Chris@16: os << Chris@16: "std::numeric_limits<" << nameof() << ">::digits reports that the precision is \n" Chris@16: << std::numeric_limits::digits * 1000L /301L << " binary digits.\n"; // divide by log2(10) - about 3 bits per decimal digit. Chris@16: } Chris@16: else Chris@16: { Chris@16: os << "Unknown radix = " << std::numeric_limits::radix << "\n"; Chris@16: } Chris@16: } Chris@16: typedef typename boost::math::policies::precision::type precision_type; Chris@16: if(precision_type::value) Chris@16: { Chris@16: if (std::numeric_limits::radix == 2) Chris@16: { Chris@16: os << Chris@16: "boost::math::policies::precision<" << nameof() << ", " << nameof() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n"; Chris@16: } Chris@16: else if (std::numeric_limits::radix == 10) Chris@16: { Chris@16: os << Chris@16: "boost::math::policies::precision<" << nameof() << ", " << nameof() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n"; Chris@16: } Chris@16: else Chris@16: { Chris@16: os << "Unknown radix = " << std::numeric_limits::radix << "\n"; Chris@16: } Chris@16: } Chris@16: else Chris@16: { Chris@16: os << Chris@16: "boost::math::policies::precision<" << nameof() << ", Policy> \n" Chris@16: "reports that there is no compile type precision available.\n" Chris@16: "boost::math::tools::digits<" << nameof() << ">() \n" Chris@16: "reports that the current runtime precision is \n" << Chris@16: boost::math::tools::digits() << " binary digits.\n"; Chris@16: } Chris@16: Chris@16: typedef typename construction_traits::type construction_type; Chris@16: Chris@16: switch(construction_type::value) Chris@16: { Chris@16: case 0: Chris@16: os << Chris@16: "No compile time precision is available, the construction method \n" Chris@16: "will be decided at runtime and results will not be cached \n" Chris@16: "- this may lead to poor runtime performance.\n" Chris@16: "Current runtime precision indicates that\n"; Chris@16: if(boost::math::tools::digits() > max_string_digits) Chris@16: { Chris@16: os << "the constant will be recalculated on each call.\n"; Chris@16: } Chris@16: else Chris@16: { Chris@16: os << "the constant will be constructed from a string on each call.\n"; Chris@16: } Chris@16: break; Chris@16: case 1: Chris@16: os << Chris@16: "The constant will be constructed from a float.\n"; Chris@16: break; Chris@16: case 2: Chris@16: os << Chris@16: "The constant will be constructed from a double.\n"; Chris@16: break; Chris@16: case 3: Chris@16: os << Chris@16: "The constant will be constructed from a long double.\n"; Chris@16: break; Chris@16: case 4: Chris@16: os << Chris@16: "The constant will be constructed from a string (and the result cached).\n"; Chris@16: break; Chris@16: default: Chris@16: os << Chris@16: "The constant will be calculated (and the result cached).\n"; Chris@16: break; Chris@16: } Chris@16: os << std::endl; Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: } Chris@16: Chris@16: template Chris@16: void print_info_on_type(std::ostream& os = std::cout BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) Chris@16: { Chris@16: print_info_on_type >(os); Chris@16: } Chris@16: Chris@16: }}} // namespaces Chris@16: Chris@16: #endif // BOOST_MATH_CONSTANTS_INFO_INCLUDED