Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81871 - trunk/boost/multiprecision
From: john_at_[hidden]
Date: 2012-12-12 08:18:07


Author: johnmaddock
Date: 2012-12-12 08:18:06 EST (Wed, 12 Dec 2012)
New Revision: 81871
URL: http://svn.boost.org/trac/boost/changeset/81871

Log:
Update mpfr.hpp to use MPFR native constants when used with Boost.Math.
Text files modified:
   trunk/boost/multiprecision/mpfr.hpp | 60 +++++++++++++++++++++++++++++++++++++++
   1 files changed, 59 insertions(+), 1 deletions(-)

Modified: trunk/boost/multiprecision/mpfr.hpp
==============================================================================
--- trunk/boost/multiprecision/mpfr.hpp (original)
+++ trunk/boost/multiprecision/mpfr.hpp 2012-12-12 08:18:06 EST (Wed, 12 Dec 2012)
@@ -1383,7 +1383,65 @@
    return boost::multiprecision::backends::detail::get_default_precision();
 }
 
-}
+} // namespace tools
+
+namespace constants{ namespace detail{
+
+template <class T> struct constant_pi;
+template <class T> struct constant_ln_two;
+template <class T> struct constant_euler;
+template <class T> struct constant_catalan;
+
+template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
+struct constant_pi<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
+{
+ typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
+ template<int N>
+ static inline result_type get(const mpl::int_<N>&)
+ {
+ result_type result;
+ mpfr_const_pi(result.backend().data(), GMP_RNDN);
+ return result;
+ }
+};
+template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
+struct constant_ln_two<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
+{
+ typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
+ template<int N>
+ static inline result_type get(const mpl::int_<N>&)
+ {
+ result_type result;
+ mpfr_const_log2(result.backend().data(), GMP_RNDN);
+ return result;
+ }
+};
+template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
+struct constant_euler<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
+{
+ typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
+ template<int N>
+ static inline result_type get(const mpl::int_<N>&)
+ {
+ result_type result;
+ mpfr_const_euler(result.backend().data(), GMP_RNDN);
+ return result;
+ }
+};
+template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
+struct constant_catalan<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
+{
+ typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
+ template<int N>
+ static inline result_type get(const mpl::int_<N>&)
+ {
+ result_type result;
+ mpfr_const_catalan(result.backend().data(), GMP_RNDN);
+ return result;
+ }
+};
+
+}} // namespaces
 
 }} // namespaces
 


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