From c5dee8ee69e23298b3230e008daa64bac06517c3 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 25 Jan 2013 12:49:55 +0000 Subject: [PATCH] Fix gcc build failures and warnings [SVN r82604] --- .../boost/multiprecision/debug_adaptor.hpp | 3 +- .../boost/multiprecision/logged_adaptor.hpp | 9 ++- include/boost/multiprecision/mpfr.hpp | 78 +++++++++++++++---- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/include/boost/multiprecision/debug_adaptor.hpp b/include/boost/multiprecision/debug_adaptor.hpp index d7987a12..b112a574 100644 --- a/include/boost/multiprecision/debug_adaptor.hpp +++ b/include/boost/multiprecision/debug_adaptor.hpp @@ -7,6 +7,7 @@ #define BOOST_MATH_DEBUG_ADAPTER_HPP #include +#include namespace boost{ namespace multiprecision{ @@ -412,7 +413,7 @@ struct number_category > : public number_catego namespace std{ template -class numeric_limits, ExpressionTemplates> > +class numeric_limits, ExpressionTemplates> > : public std::numeric_limits > { typedef std::numeric_limits > base_type; diff --git a/include/boost/multiprecision/logged_adaptor.hpp b/include/boost/multiprecision/logged_adaptor.hpp index ebc558ee..790610ae 100644 --- a/include/boost/multiprecision/logged_adaptor.hpp +++ b/include/boost/multiprecision/logged_adaptor.hpp @@ -7,6 +7,7 @@ #define BOOST_MATH_LOGGED_ADAPTER_HPP #include +#include namespace boost{ namespace multiprecision{ @@ -398,7 +399,7 @@ inline void eval_bit_set(const logged_adaptor& arg, unsigned a) using default_ops::eval_bit_set; log_prefix_event(arg.value(), a, "bit-set"); eval_bit_set(arg.value(), a); - log_postfix_event(arg.value(), r, "bit-set"); + log_postfix_event(arg.value(), arg, "bit-set"); } template inline void eval_bit_unset(const logged_adaptor& arg, unsigned a) @@ -406,7 +407,7 @@ inline void eval_bit_unset(const logged_adaptor& arg, unsigned a) using default_ops::eval_bit_unset; log_prefix_event(arg.value(), a, "bit-unset"); eval_bit_unset(arg.value(), a); - log_postfix_event(arg.value(), r, "bit-unset"); + log_postfix_event(arg.value(), arg, "bit-unset"); } template inline void eval_bit_flip(const logged_adaptor& arg, unsigned a) @@ -414,7 +415,7 @@ inline void eval_bit_flip(const logged_adaptor& arg, unsigned a) using default_ops::eval_bit_flip; log_prefix_event(arg.value(), a, "bit-flip"); eval_bit_flip(arg.value(), a); - log_postfix_event(arg.value(), r, "bit-flip"); + log_postfix_event(arg.value(), arg, "bit-flip"); } NON_MEMBER_OP3(gcd, "gcd"); @@ -466,7 +467,7 @@ struct number_category > : public number_categ namespace std{ template -class numeric_limits, ExpressionTemplates> > +class numeric_limits, ExpressionTemplates> > : public std::numeric_limits > { typedef std::numeric_limits > base_type; diff --git a/include/boost/multiprecision/mpfr.hpp b/include/boost/multiprecision/mpfr.hpp index 7ea55dd1..4a811e7c 100644 --- a/include/boost/multiprecision/mpfr.hpp +++ b/include/boost/multiprecision/mpfr.hpp @@ -1246,14 +1246,14 @@ inline void eval_pow(mpfr_float_backend& result, const m #endif template -inline typename enable_if, mpl::bool_ > >::type +inline typename enable_if, mpl::bool_ > >::type eval_pow(mpfr_float_backend& result, const mpfr_float_backend& b, const Integer& e) { mpfr_pow_si(result.data(), b.data(), e, GMP_RNDN); } template -inline typename enable_if, mpl::bool_ > >::type +inline typename enable_if, mpl::bool_ > >::type eval_pow(mpfr_float_backend& result, const mpfr_float_backend& b, const Integer& e) { mpfr_pow_ui(result.data(), b.data(), e, GMP_RNDN); @@ -1392,15 +1392,47 @@ template struct constant_ln_two; template struct constant_euler; template struct constant_catalan; +namespace detail{ + + template + struct mpfr_constant_initializer + { + static void force_instantiate() + { + init.force_instantiate(); + } + private: + struct initializer + { + initializer() + { + T::get(mpl::int_()); + } + void force_instantiate()const{} + }; + static const initializer init; + }; + + template + typename mpfr_constant_initializer::initializer const mpfr_constant_initializer::init; + +} + template struct constant_pi, ExpressionTemplates> > { typedef boost::multiprecision::number, ExpressionTemplates> result_type; template - static inline result_type get(const mpl::int_&) + static inline const result_type& get(const mpl::int_&) { - result_type result; - mpfr_const_pi(result.backend().data(), GMP_RNDN); + detail::mpfr_constant_initializer, ExpressionTemplates> >, N>::force_instantiate(); + static result_type result; + static bool has_init = false; + if(!has_init) + { + mpfr_const_pi(result.backend().data(), GMP_RNDN); + has_init = true; + } return result; } }; @@ -1409,10 +1441,16 @@ struct constant_ln_two, ExpressionTemplates> result_type; template - static inline result_type get(const mpl::int_&) + static inline const result_type& get(const mpl::int_&) { - result_type result; - mpfr_const_log2(result.backend().data(), GMP_RNDN); + detail::mpfr_constant_initializer, ExpressionTemplates> >, N>::force_instantiate(); + static result_type result; + static bool init = false; + if(!init) + { + mpfr_const_log2(result.backend().data(), GMP_RNDN); + init = true; + } return result; } }; @@ -1421,10 +1459,16 @@ struct constant_euler, ExpressionTemplates> result_type; template - static inline result_type get(const mpl::int_&) + static inline const result_type& get(const mpl::int_&) { - result_type result; - mpfr_const_euler(result.backend().data(), GMP_RNDN); + detail::mpfr_constant_initializer, ExpressionTemplates> >, N>::force_instantiate(); + static result_type result; + static bool init = false; + if(!init) + { + mpfr_const_euler(result.backend().data(), GMP_RNDN); + init = true; + } return result; } }; @@ -1433,10 +1477,16 @@ struct constant_catalan, ExpressionTemplates> result_type; template - static inline result_type get(const mpl::int_&) + static inline const result_type& get(const mpl::int_&) { - result_type result; - mpfr_const_catalan(result.backend().data(), GMP_RNDN); + detail::mpfr_constant_initializer, ExpressionTemplates> >, N>::force_instantiate(); + static result_type result; + static bool init = false; + if(!init) + { + mpfr_const_catalan(result.backend().data(), GMP_RNDN); + init = true; + } return result; } };