Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:34

0001 //  Copyright John Maddock 2010.
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifdef _MSC_VER
0007 #  pragma once
0008 #endif
0009 
0010 #ifndef BOOST_MATH_CONSTANTS_INFO_INCLUDED
0011 #define BOOST_MATH_CONSTANTS_INFO_INCLUDED
0012 
0013 #include <boost/math/constants/constants.hpp>
0014 #include <iostream>
0015 #include <iomanip>
0016 #include <typeinfo>
0017 
0018 namespace boost{ namespace math{ namespace constants{
0019 
0020    namespace detail{
0021 
0022       template <class T>
0023       const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
0024       {
0025          return typeid(T).name();
0026       }
0027       template <>
0028       const char* nameof<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
0029       {
0030          return "float";
0031       }
0032       template <>
0033       const char* nameof<double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double))
0034       {
0035          return "double";
0036       }
0037       template <>
0038       const char* nameof<long double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))
0039       {
0040          return "long double";
0041       }
0042 
0043    }
0044 
0045 template <class T, class Policy>
0046 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))
0047 {
0048    using detail::nameof;
0049 #ifdef _MSC_VER
0050 #pragma warning(push)
0051 #pragma warning(disable:4127)
0052 #endif
0053    os <<
0054       "Information on the Implementation and Handling of \n"
0055       "Mathematical Constants for Type " << nameof<T>() <<
0056       "\n\n"
0057       "Checking for std::numeric_limits<" << nameof<T>() << "> specialisation: " <<
0058       (std::numeric_limits<T>::is_specialized ? "yes" : "no") << std::endl;
0059    if(std::numeric_limits<T>::is_specialized)
0060    {
0061       os <<
0062          "std::numeric_limits<" << nameof<T>() << ">::digits reports that the radix is " << std::numeric_limits<T>::radix << ".\n";
0063       if (std::numeric_limits<T>::radix == 2)
0064       {
0065       os <<
0066          "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits << " binary digits.\n";
0067       }
0068       else if (std::numeric_limits<T>::radix == 10)
0069       {
0070          os <<
0071          "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits10 << " decimal digits.\n";
0072          os <<
0073          "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n"
0074          << std::numeric_limits<T>::digits * 1000L /301L << " binary digits.\n";  // divide by log2(10) - about 3 bits per decimal digit.
0075       }
0076       else
0077       {
0078         os << "Unknown radix = " << std::numeric_limits<T>::radix << "\n";
0079       }
0080    }
0081    typedef typename boost::math::policies::precision<T, Policy>::type precision_type;
0082    if(precision_type::value)
0083    {
0084       if (std::numeric_limits<T>::radix == 2)
0085       {
0086        os <<
0087        "boost::math::policies::precision<" << nameof<T>() << ", " << nameof<Policy>() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
0088       }
0089       else if (std::numeric_limits<T>::radix == 10)
0090       {
0091          os <<
0092          "boost::math::policies::precision<" << nameof<T>() << ", " << nameof<Policy>() << " reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
0093       }
0094       else
0095       {
0096         os << "Unknown radix = " << std::numeric_limits<T>::radix <<  "\n";
0097       }
0098    }
0099    else
0100    {
0101       os <<
0102          "boost::math::policies::precision<" << nameof<T>() << ", Policy> \n"
0103          "reports that there is no compile type precision available.\n"
0104          "boost::math::tools::digits<" << nameof<T>() << ">() \n"
0105          "reports that the current runtime precision is \n" <<
0106          boost::math::tools::digits<T>() << " binary digits.\n";
0107    }
0108 
0109    typedef typename construction_traits<T, Policy>::type construction_type;
0110 
0111    switch(construction_type::value)
0112    {
0113    case 0:
0114       os <<
0115          "No compile time precision is available, the construction method \n"
0116          "will be decided at runtime and results will not be cached \n"
0117          "- this may lead to poor runtime performance.\n"
0118          "Current runtime precision indicates that\n";
0119       if(boost::math::tools::digits<T>() > max_string_digits)
0120       {
0121          os << "the constant will be recalculated on each call.\n";
0122       }
0123       else
0124       {
0125          os << "the constant will be constructed from a string on each call.\n";
0126       }
0127       break;
0128    case 1:
0129       os <<
0130          "The constant will be constructed from a float.\n";
0131       break;
0132    case 2:
0133       os <<
0134          "The constant will be constructed from a double.\n";
0135       break;
0136    case 3:
0137       os <<
0138          "The constant will be constructed from a long double.\n";
0139       break;
0140    case 4:
0141       os <<
0142          "The constant will be constructed from a string (and the result cached).\n";
0143       break;
0144    default:
0145       os <<
0146          "The constant will be calculated (and the result cached).\n";
0147       break;
0148    }
0149    os << std::endl;
0150 #ifdef _MSC_VER
0151 #pragma warning(pop)
0152 #endif
0153 }
0154 
0155 template <class T>
0156 void print_info_on_type(std::ostream& os = std::cout BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
0157 {
0158    print_info_on_type<T, boost::math::policies::policy<> >(os);
0159 }
0160 
0161 }}} // namespaces
0162 
0163 #endif // BOOST_MATH_CONSTANTS_INFO_INCLUDED