1 // Copyright John Maddock 2010.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_MATH_CONSTANTS_INFO_INCLUDED
11 #define BOOST_MATH_CONSTANTS_INFO_INCLUDED
13 #include <boost/math/constants/constants.hpp>
18 namespace boost{ namespace math{ namespace constants{
23 const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
25 return typeid(T).name();
28 const char* nameof<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
33 const char* nameof<double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double))
38 const char* nameof<long double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))
45 template <class T, class Policy>
46 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))
51 #pragma warning(disable:4127)
54 "Information on the Implementation and Handling of \n"
55 "Mathematical Constants for Type " << nameof<T>() <<
57 "Checking for std::numeric_limits<" << nameof<T>() << "> specialisation: " <<
58 (std::numeric_limits<T>::is_specialized ? "yes" : "no") << std::endl;
59 if(std::numeric_limits<T>::is_specialized)
62 "std::numeric_limits<" << nameof<T>() << ">::digits reports that the radix is " << std::numeric_limits<T>::radix << ".\n";
63 if (std::numeric_limits<T>::radix == 2)
66 "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits << " binary digits.\n";
68 else if (std::numeric_limits<T>::radix == 10)
71 "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits10 << " decimal digits.\n";
73 "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n"
74 << std::numeric_limits<T>::digits * 1000L /301L << " binary digits.\n"; // divide by log2(10) - about 3 bits per decimal digit.
78 os << "Unknown radix = " << std::numeric_limits<T>::radix << "\n";
81 typedef typename boost::math::policies::precision<T, Policy>::type precision_type;
82 if(precision_type::value)
84 if (std::numeric_limits<T>::radix == 2)
87 "boost::math::policies::precision<" << nameof<T>() << ", " << nameof<Policy>() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
89 else if (std::numeric_limits<T>::radix == 10)
92 "boost::math::policies::precision<" << nameof<T>() << ", " << nameof<Policy>() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
96 os << "Unknown radix = " << std::numeric_limits<T>::radix << "\n";
102 "boost::math::policies::precision<" << nameof<T>() << ", Policy> \n"
103 "reports that there is no compile type precision available.\n"
104 "boost::math::tools::digits<" << nameof<T>() << ">() \n"
105 "reports that the current runtime precision is \n" <<
106 boost::math::tools::digits<T>() << " binary digits.\n";
109 typedef typename construction_traits<T, Policy>::type construction_type;
111 switch(construction_type::value)
115 "No compile time precision is available, the construction method \n"
116 "will be decided at runtime and results will not be cached \n"
117 "- this may lead to poor runtime performance.\n"
118 "Current runtime precision indicates that\n";
119 if(boost::math::tools::digits<T>() > max_string_digits)
121 os << "the constant will be recalculated on each call.\n";
125 os << "the constant will be constructed from a string on each call.\n";
130 "The constant will be constructed from a float.\n";
134 "The constant will be constructed from a double.\n";
138 "The constant will be constructed from a long double.\n";
142 "The constant will be constructed from a string (and the result cached).\n";
146 "The constant will be calculated (and the result cached).\n";
156 void print_info_on_type(std::ostream& os = std::cout BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
158 print_info_on_type<T, boost::math::policies::policy<> >(os);
163 #endif // BOOST_MATH_CONSTANTS_INFO_INCLUDED