///////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
+// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_MATH_DEBUG_ADAPTER_HPP
#define BOOST_MATH_DEBUG_ADAPTER_HPP
#include <boost/multiprecision/traits/extract_exponent_type.hpp>
#include <boost/multiprecision/detail/integer_ops.hpp>
-namespace boost{
-namespace multiprecision{
-namespace backends{
+namespace boost {
+namespace multiprecision {
+namespace backends {
#ifdef BOOST_MSVC
#pragma warning(push)
-#pragma warning(disable:4127) // conditional expression is constant
+#pragma warning(disable : 4127) // conditional expression is constant
#endif
-
- template <class Backend>
+
+template <class Backend>
struct debug_adaptor
{
- typedef typename Backend::signed_types signed_types;
- typedef typename Backend::unsigned_types unsigned_types;
- typedef typename Backend::float_types float_types;
+ typedef typename Backend::signed_types signed_types;
+ typedef typename Backend::unsigned_types unsigned_types;
+ typedef typename Backend::float_types float_types;
typedef typename extract_exponent_type<
- Backend, number_category<Backend>::value>::type exponent_type;
+ Backend, number_category<Backend>::value>::type exponent_type;
-private:
+ private:
std::string debug_value;
- Backend m_value;
-public:
+ Backend m_value;
+
+ public:
void update_view()
{
#ifndef BOOST_NO_EXCEPTIONS
debug_value = m_value.str(0, static_cast<std::ios_base::fmtflags>(0));
#ifndef BOOST_NO_EXCEPTIONS
}
- catch(const std::exception& e)
+ catch (const std::exception& e)
{
debug_value = "String conversion failed with message: \"";
debug_value += e.what();
debug_adaptor(const debug_adaptor& o) : debug_value(o.debug_value), m_value(o.m_value)
{
}
- debug_adaptor& operator = (const debug_adaptor& o)
+ debug_adaptor& operator=(const debug_adaptor& o)
{
debug_value = o.debug_value;
- m_value = o.m_value;
+ m_value = o.m_value;
return *this;
}
template <class T>
debug_adaptor(const T& i, const typename enable_if_c<is_convertible<T, Backend>::value>::type* = 0)
- : m_value(i)
+ : m_value(i)
{
update_view();
}
template <class T>
debug_adaptor(const T& i, const T& j)
- : m_value(i, j)
+ : m_value(i, j)
{
update_view();
}
template <class T>
- typename enable_if_c<is_arithmetic<T>::value || is_convertible<T, Backend>::value, debug_adaptor&>::type operator = (const T& i)
+ typename enable_if_c<is_arithmetic<T>::value || is_convertible<T, Backend>::value, debug_adaptor&>::type operator=(const T& i)
{
m_value = i;
update_view();
return *this;
}
- debug_adaptor& operator = (const char* s)
+ debug_adaptor& operator=(const char* s)
{
m_value = s;
update_view();
std::swap(m_value, o.value());
std::swap(debug_value, o.debug_value);
}
- std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
+ std::string str(std::streamsize digits, std::ios_base::fmtflags f) const
{
return m_value.str(digits, f);
}
m_value.negate();
update_view();
}
- int compare(const debug_adaptor& o)const
+ int compare(const debug_adaptor& o) const
{
return m_value.compare(o.value());
}
template <class T>
- int compare(const T& i)const
+ int compare(const T& i) const
{
return m_value.compare(i);
}
{
return m_value;
}
- const Backend& value()const
+ const Backend& value() const
{
return m_value;
}
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
- ar & m_value;
+ ar & boost::make_nvp("value", m_value);
typedef typename Archive::is_loading tag;
- if(tag::value)
+ if (tag::value)
update_view();
}
static unsigned default_precision() BOOST_NOEXCEPT
{
Backend::default_precision(v);
}
- unsigned precision()const BOOST_NOEXCEPT
+ unsigned precision() const BOOST_NOEXCEPT
{
return value().precision();
}
return val;
}
-#define NON_MEMBER_OP1(name, str) \
- template <class Backend>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value());\
- result.update_view();\
+#define NON_MEMBER_OP1(name, str) \
+ template <class Backend> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value()); \
+ result.update_view(); \
}
-#define NON_MEMBER_OP2(name, str) \
- template <class Backend, class T>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const T& a)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a));\
- result.update_view();\
- }\
- template <class Backend>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a));\
- result.update_view();\
+#define NON_MEMBER_OP2(name, str) \
+ template <class Backend, class T> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const T& a) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a)); \
+ result.update_view(); \
+ } \
+ template <class Backend> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a)); \
+ result.update_view(); \
}
-#define NON_MEMBER_OP3(name, str) \
- template <class Backend, class T, class U>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const T& a, const U& b)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b));\
- result.update_view();\
- }\
- template <class Backend, class T>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a, const T& b)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b));\
- result.update_view();\
- }\
- template <class Backend, class T>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const T& a, const debug_adaptor<Backend>& b)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b));\
- result.update_view();\
- }\
- template <class Backend>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a, const debug_adaptor<Backend>& b)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b));\
- result.update_view();\
+#define NON_MEMBER_OP3(name, str) \
+ template <class Backend, class T, class U> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const T& a, const U& b) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b)); \
+ result.update_view(); \
+ } \
+ template <class Backend, class T> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a, const T& b) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b)); \
+ result.update_view(); \
+ } \
+ template <class Backend, class T> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const T& a, const debug_adaptor<Backend>& b) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b)); \
+ result.update_view(); \
+ } \
+ template <class Backend> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a, const debug_adaptor<Backend>& b) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b)); \
+ result.update_view(); \
}
-#define NON_MEMBER_OP4(name, str) \
- template <class Backend, class T, class U, class V>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const T& a, const U& b, const V& c)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c));\
- result.update_view();\
- }\
- template <class Backend, class T>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a, const debug_adaptor<Backend>& b, const T& c)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c));\
- result.update_view();\
- }\
- template <class Backend, class T>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a, const T& b, const debug_adaptor<Backend>& c)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c));\
- result.update_view();\
- }\
- template <class Backend, class T>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const T& a, const debug_adaptor<Backend>& b, const debug_adaptor<Backend>& c)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c));\
- result.update_view();\
- }\
- template <class Backend>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a, const debug_adaptor<Backend>& b, const debug_adaptor<Backend>& c)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c));\
- result.update_view();\
- }\
- template <class Backend, class T, class U>\
- inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend>& result, const debug_adaptor<Backend>& a, const T& b, const U& c)\
- {\
- using default_ops::BOOST_JOIN(eval_, name);\
- BOOST_JOIN(eval_, name)(result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c));\
- result.update_view();\
- }\
+#define NON_MEMBER_OP4(name, str) \
+ template <class Backend, class T, class U, class V> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const T& a, const U& b, const V& c) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c)); \
+ result.update_view(); \
+ } \
+ template <class Backend, class T> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a, const debug_adaptor<Backend>& b, const T& c) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c)); \
+ result.update_view(); \
+ } \
+ template <class Backend, class T> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a, const T& b, const debug_adaptor<Backend>& c) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c)); \
+ result.update_view(); \
+ } \
+ template <class Backend, class T> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const T& a, const debug_adaptor<Backend>& b, const debug_adaptor<Backend>& c) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c)); \
+ result.update_view(); \
+ } \
+ template <class Backend> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a, const debug_adaptor<Backend>& b, const debug_adaptor<Backend>& c) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c)); \
+ result.update_view(); \
+ } \
+ template <class Backend, class T, class U> \
+ inline void BOOST_JOIN(eval_, name)(debug_adaptor<Backend> & result, const debug_adaptor<Backend>& a, const T& b, const U& c) \
+ { \
+ using default_ops::BOOST_JOIN(eval_, name); \
+ BOOST_JOIN(eval_, name) \
+ (result.value(), unwrap_debug_type(a), unwrap_debug_type(b), unwrap_debug_type(c)); \
+ result.update_view(); \
+ }
NON_MEMBER_OP2(add, "+=")
NON_MEMBER_OP2(subtract, "-=")
{
using default_ops::eval_left_shift;
eval_left_shift(arg.value(), a);
- arg.update_view();\
+ arg.update_view();
}
template <class Backend>
inline void eval_left_shift(debug_adaptor<Backend>& arg, const debug_adaptor<Backend>& a, std::size_t b)
{
using default_ops::eval_left_shift;
eval_left_shift(arg.value(), a.value(), b);
- arg.update_view();\
+ arg.update_view();
}
template <class Backend>
inline void eval_right_shift(debug_adaptor<Backend>& arg, std::size_t a)
{
using default_ops::eval_right_shift;
eval_right_shift(arg.value(), a);
- arg.update_view();\
+ arg.update_view();
}
template <class Backend>
inline void eval_right_shift(debug_adaptor<Backend>& arg, const debug_adaptor<Backend>& a, std::size_t b)
{
using default_ops::eval_right_shift;
eval_right_shift(arg.value(), a.value(), b);
- arg.update_view();\
+ arg.update_view();
}
template <class Backend, class T>
{
using default_ops::eval_bit_set;
eval_bit_set(arg.value(), a);
- arg.update_view();\
+ arg.update_view();
}
template <class Backend>
inline void eval_bit_unset(const debug_adaptor<Backend>& arg, unsigned a)
{
using default_ops::eval_bit_unset;
eval_bit_unset(arg.value(), a);
- arg.update_view();\
+ arg.update_view();
}
template <class Backend>
inline void eval_bit_flip(const debug_adaptor<Backend>& arg, unsigned a)
{
using default_ops::eval_bit_flip;
eval_bit_flip(arg.value(), a);
- arg.update_view();\
+ arg.update_view();
}
NON_MEMBER_OP3(gcd, "gcd")
NON_MEMBER_OP3(lcm, "lcm")
-NON_MEMBER_OP4(powm, "powm");
+NON_MEMBER_OP4(powm, "powm")
/*********************************************************************
*
using backends::debug_adaptor;
-template<class Backend>
-struct number_category<backends::debug_adaptor<Backend> > : public number_category<Backend> {};
+template <class Backend>
+struct number_category<backends::debug_adaptor<Backend> > : public number_category<Backend>
+{};
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
-}} // namespaces
+}} // namespace boost::multiprecision
-namespace std{
+namespace std {
template <class Backend, boost::multiprecision::expression_template_option ExpressionTemplates>
class numeric_limits<boost::multiprecision::number<boost::multiprecision::backends::debug_adaptor<Backend>, ExpressionTemplates> >
- : public std::numeric_limits<boost::multiprecision::number<Backend, ExpressionTemplates> >
+ : public std::numeric_limits<boost::multiprecision::number<Backend, ExpressionTemplates> >
{
- typedef std::numeric_limits<boost::multiprecision::number<Backend, ExpressionTemplates> > base_type;
+ typedef std::numeric_limits<boost::multiprecision::number<Backend, ExpressionTemplates> > base_type;
typedef boost::multiprecision::number<boost::multiprecision::backends::debug_adaptor<Backend>, ExpressionTemplates> number_type;
-public:
- static number_type (min)() BOOST_NOEXCEPT { return (base_type::min)(); }
- static number_type (max)() BOOST_NOEXCEPT { return (base_type::max)(); }
+
+ public:
+ static number_type(min)() BOOST_NOEXCEPT { return (base_type::min)(); }
+ static number_type(max)() BOOST_NOEXCEPT { return (base_type::max)(); }
static number_type lowest() BOOST_NOEXCEPT { return -(max)(); }
static number_type epsilon() BOOST_NOEXCEPT { return base_type::epsilon(); }
static number_type round_error() BOOST_NOEXCEPT { return epsilon() / 2; }
} // namespace std
-namespace boost{ namespace math{
+namespace boost {
+namespace math {
-namespace policies{
+namespace policies {
template <class Backend, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
-struct precision< boost::multiprecision::number<boost::multiprecision::debug_adaptor<Backend>, ExpressionTemplates>, Policy>
- : public precision<boost::multiprecision::number<Backend, ExpressionTemplates>, Policy>
+struct precision<boost::multiprecision::number<boost::multiprecision::debug_adaptor<Backend>, ExpressionTemplates>, Policy>
+ : public precision<boost::multiprecision::number<Backend, ExpressionTemplates>, Policy>
{};
#undef NON_MEMBER_OP1
#undef NON_MEMBER_OP3
#undef NON_MEMBER_OP4
-} // namespace policies
-
-}} // namespaces boost::math
+}
+}} // namespace boost::math::policies
#endif