info.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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)
  5. #ifdef _MSC_VER
  6. # pragma once
  7. #endif
  8. #ifndef BOOST_MATH_CONSTANTS_INFO_INCLUDED
  9. #define BOOST_MATH_CONSTANTS_INFO_INCLUDED
  10. #include <boost/math/constants/constants.hpp>
  11. #include <iostream>
  12. #include <iomanip>
  13. #include <typeinfo>
  14. namespace boost{ namespace math{ namespace constants{
  15. namespace detail{
  16. template <class T>
  17. const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
  18. {
  19. return typeid(T).name();
  20. }
  21. template <>
  22. const char* nameof<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
  23. {
  24. return "float";
  25. }
  26. template <>
  27. const char* nameof<double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double))
  28. {
  29. return "double";
  30. }
  31. template <>
  32. const char* nameof<long double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))
  33. {
  34. return "long double";
  35. }
  36. }
  37. template <class T, class Policy>
  38. 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))
  39. {
  40. using detail::nameof;
  41. #ifdef BOOST_MSVC
  42. #pragma warning(push)
  43. #pragma warning(disable:4127)
  44. #endif
  45. os <<
  46. "Information on the Implementation and Handling of \n"
  47. "Mathematical Constants for Type " << nameof<T>() <<
  48. "\n\n"
  49. "Checking for std::numeric_limits<" << nameof<T>() << "> specialisation: " <<
  50. (std::numeric_limits<T>::is_specialized ? "yes" : "no") << std::endl;
  51. if(std::numeric_limits<T>::is_specialized)
  52. {
  53. os <<
  54. "std::numeric_limits<" << nameof<T>() << ">::digits reports that the radix is " << std::numeric_limits<T>::radix << ".\n";
  55. if (std::numeric_limits<T>::radix == 2)
  56. {
  57. os <<
  58. "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits << " binary digits.\n";
  59. }
  60. else if (std::numeric_limits<T>::radix == 10)
  61. {
  62. os <<
  63. "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits10 << " decimal digits.\n";
  64. os <<
  65. "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n"
  66. << std::numeric_limits<T>::digits * 1000L /301L << " binary digits.\n"; // divide by log2(10) - about 3 bits per decimal digit.
  67. }
  68. else
  69. {
  70. os << "Unknown radix = " << std::numeric_limits<T>::radix << "\n";
  71. }
  72. }
  73. typedef typename boost::math::policies::precision<T, Policy>::type precision_type;
  74. if(precision_type::value)
  75. {
  76. if (std::numeric_limits<T>::radix == 2)
  77. {
  78. os <<
  79. "boost::math::policies::precision<" << nameof<T>() << ", " << nameof<Policy>() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
  80. }
  81. else if (std::numeric_limits<T>::radix == 10)
  82. {
  83. os <<
  84. "boost::math::policies::precision<" << nameof<T>() << ", " << nameof<Policy>() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
  85. }
  86. else
  87. {
  88. os << "Unknown radix = " << std::numeric_limits<T>::radix << "\n";
  89. }
  90. }
  91. else
  92. {
  93. os <<
  94. "boost::math::policies::precision<" << nameof<T>() << ", Policy> \n"
  95. "reports that there is no compile type precision available.\n"
  96. "boost::math::tools::digits<" << nameof<T>() << ">() \n"
  97. "reports that the current runtime precision is \n" <<
  98. boost::math::tools::digits<T>() << " binary digits.\n";
  99. }
  100. typedef typename construction_traits<T, Policy>::type construction_type;
  101. switch(construction_type::value)
  102. {
  103. case 0:
  104. os <<
  105. "No compile time precision is available, the construction method \n"
  106. "will be decided at runtime and results will not be cached \n"
  107. "- this may lead to poor runtime performance.\n"
  108. "Current runtime precision indicates that\n";
  109. if(boost::math::tools::digits<T>() > max_string_digits)
  110. {
  111. os << "the constant will be recalculated on each call.\n";
  112. }
  113. else
  114. {
  115. os << "the constant will be constructed from a string on each call.\n";
  116. }
  117. break;
  118. case 1:
  119. os <<
  120. "The constant will be constructed from a float.\n";
  121. break;
  122. case 2:
  123. os <<
  124. "The constant will be constructed from a double.\n";
  125. break;
  126. case 3:
  127. os <<
  128. "The constant will be constructed from a long double.\n";
  129. break;
  130. case 4:
  131. os <<
  132. "The constant will be constructed from a string (and the result cached).\n";
  133. break;
  134. default:
  135. os <<
  136. "The constant will be calculated (and the result cached).\n";
  137. break;
  138. }
  139. os << std::endl;
  140. #ifdef BOOST_MSVC
  141. #pragma warning(pop)
  142. #endif
  143. }
  144. template <class T>
  145. void print_info_on_type(std::ostream& os = std::cout BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
  146. {
  147. print_info_on_type<T, boost::math::policies::policy<> >(os);
  148. }
  149. }}} // namespaces
  150. #endif // BOOST_MATH_CONSTANTS_INFO_INCLUDED