Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66844 - in sandbox/math_constants: boost/math/constants libs/math/test
From: john_at_[hidden]
Date: 2010-11-29 12:01:15


Author: johnmaddock
Date: 2010-11-29 12:01:12 EST (Mon, 29 Nov 2010)
New Revision: 66844
URL: http://svn.boost.org/trac/boost/changeset/66844

Log:
Add diagnostic info on how constants for some type T are handled.
Added:
   sandbox/math_constants/boost/math/constants/info.hpp (contents, props changed)
   sandbox/math_constants/libs/math/test/test_print_info_on_type.cpp (contents, props changed)
Text files modified:
   sandbox/math_constants/boost/math/constants/constants.hpp | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: sandbox/math_constants/boost/math/constants/constants.hpp
==============================================================================
--- sandbox/math_constants/boost/math/constants/constants.hpp (original)
+++ sandbox/math_constants/boost/math/constants/constants.hpp 2010-11-29 12:01:12 EST (Mon, 29 Nov 2010)
@@ -9,6 +9,7 @@
 
 #include <boost/math/tools/config.hpp>
 #include <boost/math/policies/policy.hpp>
+#include <boost/math/tools/precision.hpp>
 #ifdef BOOST_MSVC
 #pragma warning(push)
 #pragma warning(disable: 4127 4701)

Added: sandbox/math_constants/boost/math/constants/info.hpp
==============================================================================
--- (empty file)
+++ sandbox/math_constants/boost/math/constants/info.hpp 2010-11-29 12:01:12 EST (Mon, 29 Nov 2010)
@@ -0,0 +1,120 @@
+// Copyright John Maddock 2010.
+// Use, modification and distribution are subject to 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)
+
+#ifndef BOOST_MATH_CONSTANTS_INFO_INCLUDED
+#define BOOST_MATH_CONSTANTS_INFO_INCLUDED
+
+#include <boost/math/constants/constants.hpp>
+#include <iostream>
+#include <iomanip>
+#include <typeinfo>
+
+namespace boost{ namespace math{ namespace constants{
+
+ namespace detail{
+
+ template <class T>
+ const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
+ {
+ return typeid(T).name();
+ }
+ template <>
+ const char* nameof<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
+ {
+ return "float";
+ }
+ template <>
+ const char* nameof<double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double))
+ {
+ return "double";
+ }
+ template <>
+ const char* nameof<long double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))
+ {
+ return "long double";
+ }
+
+ }
+
+template <class T, class Policy>
+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))
+{
+ using detail::nameof;
+
+ os <<
+ "Information on the Implementation and Handling of \n"
+ "Mathematical Constants for Type " << nameof<T>() <<
+ "\n\n"
+ "Checking for std::numeric_limits<" << nameof<T>() << "> specialisation: " <<
+ (std::numeric_limits<T>::is_specialized ? "yes" : "no") << std::endl;
+ if(std::numeric_limits<T>::is_specialized)
+ {
+ os <<
+ "std::numeric_limits<" << nameof<T>() << ">::digits reports that the precision is \n" << std::numeric_limits<T>::digits << " binary digits.\n";
+ }
+ typedef typename boost::math::policies::precision<T, Policy>::type precision_type;
+ if(precision_type::value)
+ {
+ os <<
+ "boost::math::policies::precision<" << nameof<T>() << ", Policy> reports that the compile time precision is \n" << precision_type::value << " binary digits.\n";
+ }
+ else
+ {
+ os <<
+ "boost::math::policies::precision<" << nameof<T>() << ", Policy> \n"
+ "reports that there is no compile type precision available.\n"
+ "boost::math::tools::digits<" << nameof<T>() << ">() \n"
+ "reports that the current runtime precision is \n" <<
+ boost::math::tools::digits<T>() << " binary digits.\n";
+ }
+
+ typedef typename construction_traits<T, Policy>::type construction_type;
+
+ switch(construction_type::value)
+ {
+ case 0:
+ os <<
+ "No compile time precision is available, the construction method \n"
+ "will be decided at runtime and results will not be cached \n"
+ "- this may lead to poor runtime performance.\n"
+ "Current runtime precision indicates that\n";
+ if(boost::math::tools::digits<T>() > max_string_digits)
+ {
+ os << "the constant will be recalculated on each call.\n";
+ }
+ else
+ {
+ os << "the constant will be constructed from a string on each call.\n";
+ }
+ break;
+ case 1:
+ os <<
+ "The constant will be constructed from a float.\n";
+ break;
+ case 2:
+ os <<
+ "The constant will be constructed from a double.\n";
+ break;
+ case 3:
+ os <<
+ "The constant will be constructed from a long double.\n";
+ break;
+ case 4:
+ os <<
+ "The constant will be constructed from a string (and the result cached).\n";
+ break;
+ }
+ os << std::endl;
+}
+
+template <class T>
+void print_info_on_type(std::ostream& os = std::cout BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
+{
+ print_info_on_type<T, boost::math::policies::policy<> >(os);
+}
+
+}}} // namespaces
+
+#endif // BOOST_MATH_CONSTANTS_INFO_INCLUDED

Added: sandbox/math_constants/libs/math/test/test_print_info_on_type.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_constants/libs/math/test/test_print_info_on_type.cpp 2010-11-29 12:01:12 EST (Mon, 29 Nov 2010)
@@ -0,0 +1,21 @@
+// Copyright John Maddock 2010.
+
+// Use, modification and distribution are subject to 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)
+
+#include <boost/math/constants/info.hpp>
+#include <boost/math/concepts/real_concept.hpp>
+
+
+int main()
+{
+ boost::math::constants::print_info_on_type<float>();
+ boost::math::constants::print_info_on_type<double>();
+ boost::math::constants::print_info_on_type<long double>();
+ boost::math::constants::print_info_on_type<boost::math::concepts::real_concept>();
+
+ return 0;
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk