diff --git a/include/boost/multiprecision/concepts/mp_number_archetypes.hpp b/include/boost/multiprecision/concepts/mp_number_archetypes.hpp index bb2c8678..f06c9577 100644 --- a/include/boost/multiprecision/concepts/mp_number_archetypes.hpp +++ b/include/boost/multiprecision/concepts/mp_number_archetypes.hpp @@ -197,7 +197,12 @@ inline int eval_fpclassify(const mp_number_backend_float_architype& arg) typedef boost::multiprecision::number mp_number_float_architype; -}}} // namespaces +} // namespace + +template<> +struct number_category : public mpl::int_{}; + +}} // namespaces namespace std{ diff --git a/include/boost/multiprecision/cpp_dec_float.hpp b/include/boost/multiprecision/cpp_dec_float.hpp index f8115b4a..7232fed8 100644 --- a/include/boost/multiprecision/cpp_dec_float.hpp +++ b/include/boost/multiprecision/cpp_dec_float.hpp @@ -26,6 +26,16 @@ namespace boost{ namespace multiprecision{ namespace backends{ +template +class cpp_dec_float; + +} // namespace + +template +struct number_category > : public mpl::int_{}; + +namespace backends{ + template class cpp_dec_float { diff --git a/include/boost/multiprecision/cpp_int.hpp b/include/boost/multiprecision/cpp_int.hpp index dd745e04..8e0a4574 100644 --- a/include/boost/multiprecision/cpp_int.hpp +++ b/include/boost/multiprecision/cpp_int.hpp @@ -1943,7 +1943,7 @@ void divide_unsigned_helper(cpp_int_backend* // if(r_order <= y_order) { - if((r_order < y_order) || (r.compare(y) < 0)) + if((r_order < y_order) || (r.compare_unsigned(y) < 0)) { return; } diff --git a/include/boost/multiprecision/detail/integer_ops.hpp b/include/boost/multiprecision/detail/integer_ops.hpp index ad041533..08b66352 100644 --- a/include/boost/multiprecision/detail/integer_ops.hpp +++ b/include/boost/multiprecision/detail/integer_ops.hpp @@ -38,6 +38,11 @@ inline Integer eval_integer_modulus(const Backend& x, Integer val) return maybe_abs(result); } +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4127) +#endif + template inline void eval_gcd(B& result, const B& a, const B& b) { @@ -100,6 +105,10 @@ inline void eval_gcd(B& result, const B& a, const B& b) eval_left_shift(result, shift); } +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + template inline void eval_lcm(B& result, const B& a, const B& b) { diff --git a/include/boost/multiprecision/detail/no_et_ops.hpp b/include/boost/multiprecision/detail/no_et_ops.hpp index 28c7c6d4..23a8b4ac 100644 --- a/include/boost/multiprecision/detail/no_et_ops.hpp +++ b/include/boost/multiprecision/detail/no_et_ops.hpp @@ -40,7 +40,7 @@ inline number operator + (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator + (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -50,7 +50,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator + (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -71,7 +71,7 @@ inline number operator - (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator - (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -81,7 +81,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator - (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -102,7 +102,7 @@ inline number operator * (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator * (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -112,7 +112,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator * (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -133,7 +133,7 @@ inline number operator / (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator / (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -143,7 +143,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator / (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -164,7 +164,7 @@ inline number operator % (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator % (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -174,7 +174,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator % (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -195,7 +195,7 @@ inline number operator | (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator | (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -205,7 +205,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator | (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -226,7 +226,7 @@ inline number operator ^ (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator ^ (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -236,7 +236,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator ^ (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -257,7 +257,7 @@ inline number operator & (const number& a, const number -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator & (const number& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -267,7 +267,7 @@ inline typename enable_if, number >::type return BOOST_MP_MOVE(result); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator & (const V& a, const number& b) { typedef typename detail::canonical::type canonical_type; @@ -347,7 +347,7 @@ inline number operator + (number&& a, number&& b) return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator + (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -356,7 +356,7 @@ inline typename enable_if, number >::type return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator + (const V& a, number&& b) { typedef typename detail::canonical::type canonical_type; @@ -390,7 +390,7 @@ inline number operator - (number&& a, number&& b) return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator - (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -399,7 +399,7 @@ inline typename enable_if, number >::type return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator - (const V& a, number&& b) { typedef typename detail::canonical::type canonical_type; @@ -433,7 +433,7 @@ inline number operator * (number&& a, number&& b) return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator * (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -442,7 +442,7 @@ inline typename enable_if, number >::type return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator * (const V& a, number&& b) { typedef typename detail::canonical::type canonical_type; @@ -461,7 +461,7 @@ inline number operator / (number&& a, const number return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator / (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -480,7 +480,7 @@ inline number operator % (number&& a, const number return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator % (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -513,7 +513,7 @@ inline number operator | (number&& a, number&& b) return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator | (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -522,7 +522,7 @@ inline typename enable_if, number >::type return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator | (const V& a, number&& b) { typedef typename detail::canonical::type canonical_type; @@ -555,7 +555,7 @@ inline number operator ^ (number&& a, number&& b) return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator ^ (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -564,7 +564,7 @@ inline typename enable_if, number >::type return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator ^ (const V& a, number&& b) { typedef typename detail::canonical::type canonical_type; @@ -597,7 +597,7 @@ inline number operator & (number&& a, number&& b) return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator & (number&& a, const V& b) { typedef typename detail::canonical::type canonical_type; @@ -606,7 +606,7 @@ inline typename enable_if, number >::type return static_cast&&>(a); } template -inline typename enable_if, number >::type +inline typename enable_if >, number >::type operator & (const V& a, number&& b) { typedef typename detail::canonical::type canonical_type; diff --git a/include/boost/multiprecision/detail/number_base.hpp b/include/boost/multiprecision/detail/number_base.hpp index 29f5379a..1c1267df 100644 --- a/include/boost/multiprecision/detail/number_base.hpp +++ b/include/boost/multiprecision/detail/number_base.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace boost{ namespace multiprecision{ @@ -36,6 +37,14 @@ struct is_mp_number_expression : public mpl::false_ {}; template struct is_mp_number_expression > : public mpl::true_ {}; +template +struct is_compatible_arithmetic_type + : public mpl::bool_< + is_convertible::value + && !is_mp_number::value + && !is_mp_number_expression::value> +{}; + namespace detail{ // // Workaround for missing abs(long long) on some compilers: @@ -67,7 +76,7 @@ struct has_enough_bits template struct canonical_imp { - typedef Val type; + typedef typename decay::type type; }; template struct canonical_imp > @@ -604,13 +613,13 @@ inline detail::expression, number, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator + (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator + (const V& a, const number& b) { return detail::expression >(a, b); @@ -634,13 +643,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator + (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator + (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -673,17 +682,23 @@ inline detail::expression, number, number >(b, a.left_ref()); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator + (const detail::expression >& a, const V& b) { return detail::expression >(b, a.left_ref()); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator + (const V& a, const detail::expression >& b) { return detail::expression, number >(a, b.left_ref()); } +template +inline detail::expression, number > > + operator + (const detail::expression >& a, const detail::expression >& b) +{ + return detail::expression, number > >(detail::expression, number >(a.left_ref(), b.left_ref())); +} // // Subtraction: // @@ -694,13 +709,13 @@ inline detail::expression, number, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator - (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator - (const V& a, const number& b) { return detail::expression >(a, b); @@ -724,13 +739,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator - (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator - (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -765,13 +780,13 @@ inline detail::expression, number >(b, a.left_ref())); } template -inline typename enable_if, detail::expression, V > > >::type +inline typename enable_if >, detail::expression, V > > >::type operator - (const detail::expression >& a, const V& b) { return detail::expression, V > >(detail::expression, V >(a.left_ref(), b)); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator - (const V& a, const detail::expression >& b) { return detail::expression >(a, b.left_ref()); @@ -786,13 +801,13 @@ inline detail::expression, number, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator * (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator * (const V& a, const number& b) { return detail::expression >(a, b); @@ -816,13 +831,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator * (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator * (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -859,14 +874,14 @@ inline detail::expression, number >(b, a.left_ref())); } template -inline typename enable_if, detail::expression, V > > >::type +inline typename enable_if >, detail::expression, V > > >::type operator * (const detail::expression >& a, const V& b) { return detail::expression, V > > ( detail::expression, V >(a.left_ref(), b)); } template -inline typename enable_if, detail::expression, V > > >::type +inline typename enable_if >, detail::expression, V > > >::type operator * (const V& a, const detail::expression >& b) { return detail::expression, V > >( @@ -882,13 +897,13 @@ inline detail::expression, number, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator / (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator / (const V& a, const number& b) { return detail::expression >(a, b); @@ -912,13 +927,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator / (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator / (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -955,14 +970,14 @@ inline detail::expression, number >(a.left_ref(), b)); } template -inline typename enable_if, detail::expression, V > > >::type +inline typename enable_if >, detail::expression, V > > >::type operator / (const detail::expression >& a, const V& b) { return detail::expression, V > >( detail::expression, V>(a.left_ref(), b)); } template -inline typename enable_if, detail::expression > > >::type +inline typename enable_if >, detail::expression > > >::type operator / (const V& a, const detail::expression >& b) { return detail::expression > >( @@ -978,13 +993,13 @@ inline detail::expression, number, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator % (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator % (const V& a, const number& b) { return detail::expression >(a, b); @@ -1008,13 +1023,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator % (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator % (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -1059,13 +1074,13 @@ inline detail::expression, numbe return detail::expression, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator & (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator & (const V& a, const number& b) { return detail::expression >(a, b); @@ -1089,13 +1104,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator & (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator & (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -1110,13 +1125,13 @@ inline detail::expression, number return detail::expression, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator| (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator| (const V& a, const number& b) { return detail::expression >(a, b); @@ -1140,13 +1155,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator| (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator| (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -1161,13 +1176,13 @@ inline detail::expression, numbe return detail::expression, number >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if >, detail::expression, V > >::type operator^ (const number& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if >, detail::expression > >::type operator^ (const V& a, const number& b) { return detail::expression >(a, b); @@ -1191,13 +1206,13 @@ inline detail::expression, detail::expression >(a, b); } template -inline typename enable_if, detail::expression, V > >::type +inline typename enable_if::result_type>, detail::expression, V > >::type operator^ (const detail::expression& a, const V& b) { return detail::expression, V >(a, b); } template -inline typename enable_if, detail::expression > >::type +inline typename enable_if::result_type>, detail::expression > >::type operator^ (const V& a, const detail::expression& b) { return detail::expression >(a, b); @@ -1208,6 +1223,7 @@ inline typename enable_if, detail::expression -struct number_category : public mpl::int_ {}; +struct number_category : public mpl::int_::is_integer ? number_kind_integer : (std::numeric_limits::max_exponent ? number_kind_floating_point : number_kind_unknown)> {}; template struct number_category > : public number_category{}; template diff --git a/include/boost/multiprecision/gmp.hpp b/include/boost/multiprecision/gmp.hpp index 6a21bc86..cfdea145 100644 --- a/include/boost/multiprecision/gmp.hpp +++ b/include/boost/multiprecision/gmp.hpp @@ -29,7 +29,19 @@ namespace backends{ template struct gmp_float; +struct gmp_int; +struct gmp_rational; +} // namespace backends + +template<> +struct number_category : public mpl::int_{}; +template<> +struct number_category : public mpl::int_{}; +template +struct number_category > : public mpl::int_{}; + +namespace backends{ // // Within this file, the only functions we mark as noexcept are those that manipulate // (but don't create) an mpf_t. All other types may allocate at pretty much any time @@ -394,21 +406,21 @@ struct gmp_float : public detail::gmp_float_imp gmp_float& operator=(const gmp_float& o); gmp_float& operator=(const gmp_int& o); gmp_float& operator=(const gmp_rational& o); - gmp_float& operator=(const mpf_t& val) BOOST_NOEXCEPT + gmp_float& operator=(const mpf_t val) BOOST_NOEXCEPT { if(this->m_data[0]._mp_d == 0) mpf_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); mpf_set(this->m_data, val); return *this; } - gmp_float& operator=(const mpz_t& val) BOOST_NOEXCEPT + gmp_float& operator=(const mpz_t val) BOOST_NOEXCEPT { if(this->m_data[0]._mp_d == 0) mpf_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); mpf_set_z(this->m_data, val); return *this; } - gmp_float& operator=(const mpq_t& val) BOOST_NOEXCEPT + gmp_float& operator=(const mpq_t val) BOOST_NOEXCEPT { if(this->m_data[0]._mp_d == 0) mpf_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); @@ -485,21 +497,21 @@ struct gmp_float<0> : public detail::gmp_float_imp<0> } gmp_float& operator=(const gmp_int& o); gmp_float& operator=(const gmp_rational& o); - gmp_float& operator=(const mpf_t& val) + gmp_float& operator=(const mpf_t val) { if(this->m_data[0]._mp_d == 0) mpf_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L); mpf_set(this->m_data, val); return *this; } - gmp_float& operator=(const mpz_t& val) + gmp_float& operator=(const mpz_t val) { if(this->m_data[0]._mp_d == 0) mpf_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L); mpf_set_z(this->m_data, val); return *this; } - gmp_float& operator=(const mpq_t& val) + gmp_float& operator=(const mpq_t val) { if(this->m_data[0]._mp_d == 0) mpf_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L); @@ -1130,21 +1142,21 @@ struct gmp_int mpz_set_ui(m_data, 0); return *this; } - gmp_int& operator=(const mpf_t& val) + gmp_int& operator=(const mpf_t val) { if(m_data[0]._mp_d == 0) mpz_init(this->m_data); mpz_set_f(this->m_data, val); return *this; } - gmp_int& operator=(const mpz_t& val) + gmp_int& operator=(const mpz_t val) { if(m_data[0]._mp_d == 0) mpz_init(this->m_data); mpz_set(this->m_data, val); return *this; } - gmp_int& operator=(const mpq_t& val) + gmp_int& operator=(const mpq_t val) { if(m_data[0]._mp_d == 0) mpz_init(this->m_data); @@ -1789,14 +1801,14 @@ struct gmp_rational mpq_set_z(m_data, o.data()); return *this; } - gmp_rational& operator=(const mpq_t& o) + gmp_rational& operator=(const mpq_t o) { if(m_data[0]._mp_den._mp_d == 0) mpq_init(m_data); mpq_set(m_data, o); return *this; } - gmp_rational& operator=(const mpz_t& o) + gmp_rational& operator=(const mpz_t o) { if(m_data[0]._mp_den._mp_d == 0) mpq_init(m_data); @@ -2077,11 +2089,6 @@ struct component_type > typedef number type; }; -template<> -struct number_category : public mpl::int_{}; -template<> -struct number_category : public mpl::int_{}; - typedef number > mpf_float_50; typedef number > mpf_float_100; typedef number > mpf_float_500; diff --git a/include/boost/multiprecision/mpfr.hpp b/include/boost/multiprecision/mpfr.hpp index 859e51b3..ce8209a6 100644 --- a/include/boost/multiprecision/mpfr.hpp +++ b/include/boost/multiprecision/mpfr.hpp @@ -23,6 +23,13 @@ namespace backends{ template struct mpfr_float_backend; +} // namespace backends + +template +struct number_category > : public mpl::int_{}; + +namespace backends{ + namespace detail{ inline long get_default_precision() { return 50; } @@ -387,22 +394,22 @@ struct mpfr_float_backend : public detail::mpfr_float_imp *static_cast*>(this) = v; return *this; } - mpfr_float_backend& operator=(const mpfr_t& val)BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpfr_t val)BOOST_NOEXCEPT { mpfr_set(this->m_data, val, GMP_RNDN); return *this; } - mpfr_float_backend& operator=(const mpf_t& val)BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpf_t val)BOOST_NOEXCEPT { mpfr_set_f(this->m_data, val, GMP_RNDN); return *this; } - mpfr_float_backend& operator=(const mpz_t& val)BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpz_t val)BOOST_NOEXCEPT { mpfr_set_z(this->m_data, val, GMP_RNDN); return *this; } - mpfr_float_backend& operator=(const mpq_t& val)BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpq_t val)BOOST_NOEXCEPT { mpfr_set_q(this->m_data, val, GMP_RNDN); return *this; @@ -508,22 +515,22 @@ struct mpfr_float_backend<0> : public detail::mpfr_float_imp<0> *static_cast*>(this) = v; return *this; } - mpfr_float_backend& operator=(const mpfr_t& val) BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpfr_t val) BOOST_NOEXCEPT { mpfr_set(this->m_data, val, GMP_RNDN); return *this; } - mpfr_float_backend& operator=(const mpf_t& val) BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpf_t val) BOOST_NOEXCEPT { mpfr_set_f(this->m_data, val, GMP_RNDN); return *this; } - mpfr_float_backend& operator=(const mpz_t& val) BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpz_t val) BOOST_NOEXCEPT { mpfr_set_z(this->m_data, val, GMP_RNDN); return *this; } - mpfr_float_backend& operator=(const mpq_t& val) BOOST_NOEXCEPT + mpfr_float_backend& operator=(const mpq_t val) BOOST_NOEXCEPT { mpfr_set_q(this->m_data, val, GMP_RNDN); return *this; diff --git a/include/boost/multiprecision/number.hpp b/include/boost/multiprecision/number.hpp index 15096180..40af6746 100644 --- a/include/boost/multiprecision/number.hpp +++ b/include/boost/multiprecision/number.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include // stream operators #include // EOF @@ -43,18 +44,38 @@ public: BOOST_FORCEINLINE BOOST_CONSTEXPR number(const number& e) BOOST_NOEXCEPT_IF(noexcept(Backend(static_cast(std::declval())))) : m_backend(e.m_backend){} template BOOST_FORCEINLINE number(V v, typename enable_if_c< - (boost::is_arithmetic::value || is_same::value || is_convertible::value) - && !is_convertible::type, Backend>::value >::type* = 0) + (boost::is_arithmetic::value || is_same::value || is_convertible::value) + && !is_convertible::type, Backend>::value + && !detail::is_restricted_conversion::type, Backend>::value + >::type* = 0) { m_backend = canonical_value(v); } template BOOST_FORCEINLINE BOOST_CONSTEXPR number(V v, typename enable_if_c< - (boost::is_arithmetic::value || is_same::value || is_convertible::value) - && is_convertible::type, Backend>::value >::type* = 0) + (boost::is_arithmetic::value || is_same::value || is_convertible::value) + && is_convertible::type, Backend>::value + && !detail::is_restricted_conversion::type, Backend>::value + >::type* = 0) : m_backend(canonical_value(v)) {} BOOST_FORCEINLINE BOOST_CONSTEXPR number(const number& e, unsigned digits10) : m_backend(e.m_backend, digits10){} + template + explicit BOOST_FORCEINLINE number(V v, typename enable_if_c< + (boost::is_arithmetic::value || is_same::value || is_convertible::value) + && !is_convertible::type, Backend>::value + && detail::is_restricted_conversion::type, Backend>::value + >::type* = 0) + { + m_backend = canonical_value(v); + } + template + explicit BOOST_FORCEINLINE BOOST_CONSTEXPR number(V v, typename enable_if_c< + (boost::is_arithmetic::value || is_same::value || is_convertible::value) + && is_convertible::type, Backend>::value + && detail::is_restricted_conversion::type, Backend>::value + >::type* = 0) + : m_backend(canonical_value(v)) {} /* // // This conflicts with component based initialization (for rational and complex types) @@ -71,12 +92,25 @@ public: BOOST_FORCEINLINE BOOST_CONSTEXPR number(const number& val) BOOST_NOEXCEPT_IF(noexcept(Backend(static_cast(std::declval())))) : m_backend(val.m_backend) {} template - BOOST_FORCEINLINE number(const number& val, typename enable_if >::type* = 0) BOOST_NOEXCEPT_IF(noexcept(std::declval() = std::declval())) + BOOST_FORCEINLINE number(const number& val, typename enable_if_c<(boost::is_convertible::value && !detail::is_restricted_conversion::value)>::type* = 0) BOOST_NOEXCEPT_IF(noexcept(std::declval() = std::declval())) { m_backend = val.backend(); } template - number(const number& val, typename disable_if >::type* = 0) + number(const number& val, typename enable_if_c<(!boost::is_convertible::value && !detail::is_restricted_conversion::value)>::type* = 0) + { + // + // Attempt a generic interconvertion: + // + detail::generic_interconvert(backend(), val.backend(), number_category(), number_category()); + } + template + explicit BOOST_FORCEINLINE number(const number& val, typename enable_if_c<(boost::is_convertible::value && detail::is_restricted_conversion::value)>::type* = 0) BOOST_NOEXCEPT_IF(noexcept(std::declval() = std::declval())) + { + m_backend = val.backend(); + } + template + explicit number(const number& val, typename enable_if_c<(!boost::is_convertible::value && detail::is_restricted_conversion::value)>::type* = 0) { // // Attempt a generic interconvertion: @@ -102,27 +136,40 @@ public: : m_backend(v){} template - number& operator=(const detail::expression& e) + typename enable_if::result_type, self_type>, number&>::type operator=(const detail::expression& e) { typedef typename is_same::result_type>::type tag_type; do_assign(e, tag_type()); return *this; } - + template + number& assign(const detail::expression& e) + { + typedef typename is_same::result_type>::type tag_type; + do_assign(e, tag_type()); + return *this; + } +/* BOOST_FORCEINLINE number& operator=(const number& e) BOOST_NOEXCEPT_IF(noexcept(std::declval() = static_cast(std::declval()))) { m_backend = e.m_backend; return *this; } - + */ template - BOOST_FORCEINLINE typename enable_if, is_same, is_convertible >, number& >::type + BOOST_FORCEINLINE typename enable_if, number& >::type operator=(const V& v) BOOST_NOEXCEPT_IF(noexcept(std::declval() = std::declval::type>())) { m_backend = canonical_value(v); return *this; } - + template + BOOST_FORCEINLINE number& assign(const V& v) BOOST_NOEXCEPT_IF(noexcept(std::declval() = std::declval::type>())) + { + m_backend = canonical_value(v); + return *this; + } + /* template BOOST_FORCEINLINE typename enable_if, mpl::not_, is_same, is_convertible > > >, number& >::type operator=(const V& v) BOOST_NOEXCEPT_IF(noexcept(std::declval() = static_cast(std::declval()))) @@ -130,7 +177,6 @@ public: m_backend = v; return *this; } - template BOOST_FORCEINLINE number& operator=(const number& v) BOOST_NOEXCEPT_IF(noexcept(std::declval() = static_cast(std::declval()))) { @@ -145,6 +191,14 @@ public: m_backend = v.backend(); return *this; } + template + BOOST_FORCEINLINE typename enable_if, number& >::type + assign(const number& v) BOOST_NOEXCEPT_IF(noexcept(std::declval() = static_cast(std::declval()))) + { + m_backend = v.backend(); + return *this; + } + */ template typename disable_if, number& >::type @@ -156,9 +210,19 @@ public: detail::generic_interconvert(backend(), v.backend(), number_category(), number_category()); return *this; } + template + typename disable_if, number& >::type + assign(const number& v) + { + // + // Attempt a generic interconvertion: + // + detail::generic_interconvert(backend(), v.backend(), number_category(), number_category()); + return *this; + } template - number(const detail::expression& e) + number(const detail::expression& e, typename enable_if_c::result_type, self_type>::value>::type* = 0) { *this = e; } @@ -196,7 +260,7 @@ public: } template - typename enable_if, number& >::type + typename enable_if, number& >::type operator+=(const V& v) { using default_ops::eval_add; @@ -210,24 +274,24 @@ public: return *this; } - template - number& operator-=(const detail::expression& e) + template + number& operator-=(const detail::expression& e) { // Create a copy if e contains this: if(contains_self(e)) { self_type temp(e); - do_subtract(temp, detail::terminal()); + do_subtract(detail::expression(temp), detail::terminal()); } else { - do_subtract(e, typename Exp::tag_type()); + do_subtract(e, typename detail::expression::tag_type()); } return *this; } template - typename enable_if, number& >::type + typename enable_if, number& >::type operator-=(const V& v) { using default_ops::eval_subtract; @@ -242,8 +306,8 @@ public: return *this; } - template - number& operator*=(const detail::expression& e) + template + number& operator*=(const detail::expression& e) { // Create a temporary if the RHS references *this, but not // if we're just doing an x *= x; @@ -254,13 +318,13 @@ public: } else { - do_multiplies(e, typename Exp::tag_type()); + do_multiplies(e, typename detail::expression::tag_type()); } return *this; } template - typename enable_if, number& >::type + typename enable_if, number& >::type operator*=(const V& v) { using default_ops::eval_multiply; @@ -274,24 +338,24 @@ public: do_modulus(detail::expression(e), detail::terminal()); return *this; } - template - number& operator%=(const detail::expression& e) + template + number& operator%=(const detail::expression& e) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); // Create a temporary if the RHS references *this: if(contains_self(e)) { self_type temp(e); - do_modulus(temp, detail::terminal()); + do_modulus(detail::expression(temp), detail::terminal()); } else { - do_modulus(e, typename Exp::tag_type()); + do_modulus(e, typename detail::expression::tag_type()); } return *this; } template - typename enable_if, number& >::type + typename enable_if, number& >::type operator%=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); @@ -362,8 +426,8 @@ public: return *this; } - template - number& operator/=(const detail::expression& e) + template + number& operator/=(const detail::expression& e) { // Create a temporary if the RHS references *this: if(contains_self(e)) @@ -373,13 +437,13 @@ public: } else { - do_divide(e, typename Exp::tag_type()); + do_divide(e, typename detail::expression::tag_type()); } return *this; } template - BOOST_FORCEINLINE typename enable_if, number& >::type + BOOST_FORCEINLINE typename enable_if, number& >::type operator/=(const V& v) { using default_ops::eval_divide; @@ -394,8 +458,8 @@ public: return *this; } - template - number& operator&=(const detail::expression& e) + template + number& operator&=(const detail::expression& e) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise & operation is only valid for integer types"); // Create a temporary if the RHS references *this, but not @@ -403,17 +467,17 @@ public: if(contains_self(e) && !is_self(e)) { self_type temp(e); - do_bitwise_and(temp, detail::terminal()); + do_bitwise_and(detail::expression(temp), detail::terminal()); } else { - do_bitwise_and(e, typename Exp::tag_type()); + do_bitwise_and(e, typename detail::expression::tag_type()); } return *this; } template - BOOST_FORCEINLINE typename enable_if, number& >::type + BOOST_FORCEINLINE typename enable_if, number& >::type operator&=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise & operation is only valid for integer types"); @@ -429,8 +493,8 @@ public: return *this; } - template - number& operator|=(const detail::expression& e) + template + number& operator|=(const detail::expression& e) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise | operation is only valid for integer types"); // Create a temporary if the RHS references *this, but not @@ -438,17 +502,17 @@ public: if(contains_self(e) && !is_self(e)) { self_type temp(e); - do_bitwise_or(temp, detail::terminal()); + do_bitwise_or(detail::expression(temp), detail::terminal()); } else { - do_bitwise_or(e, typename Exp::tag_type()); + do_bitwise_or(e, typename detail::expression::tag_type()); } return *this; } template - BOOST_FORCEINLINE typename enable_if, number& >::type + BOOST_FORCEINLINE typename enable_if, number& >::type operator|=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise | operation is only valid for integer types"); @@ -464,24 +528,24 @@ public: return *this; } - template - number& operator^=(const detail::expression& e) + template + number& operator^=(const detail::expression& e) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ^ operation is only valid for integer types"); if(contains_self(e)) { self_type temp(e); - do_bitwise_xor(temp, detail::terminal()); + do_bitwise_xor(detail::expression(temp), detail::terminal()); } else { - do_bitwise_xor(e, typename Exp::tag_type()); + do_bitwise_xor(e, typename detail::expression::tag_type()); } return *this; } template - BOOST_FORCEINLINE typename enable_if, number& >::type + BOOST_FORCEINLINE typename enable_if, number& >::type operator^=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ^ operation is only valid for integer types"); @@ -1535,6 +1599,8 @@ private: BOOST_FORCEINLINE BOOST_CONSTEXPR bool is_realy_self(const self_type& v)const BOOST_NOEXCEPT{ return &v == this; } static BOOST_FORCEINLINE BOOST_CONSTEXPR const Backend& canonical_value(const self_type& v) BOOST_NOEXCEPT { return v.m_backend; } + template + static BOOST_FORCEINLINE BOOST_CONSTEXPR const B2& canonical_value(const number& v) BOOST_NOEXCEPT { return v.backend(); } template static BOOST_FORCEINLINE BOOST_CONSTEXPR typename detail::canonical::type canonical_value(const V& v) BOOST_NOEXCEPT { return static_cast::type>(v); } static BOOST_FORCEINLINE typename detail::canonical::type canonical_value(const std::string& v) BOOST_NOEXCEPT { return v.c_str(); } @@ -1583,7 +1649,7 @@ inline std::istream& operator >> (std::istream& is, number> s; - r = s; + r.assign(s); return is; } @@ -1613,7 +1679,7 @@ inline std::istream& operator >> (std::istream& is, rational> (std::istream& is, rational - typename enable_if, rational_adapter&>::type operator = (Arithmetic i) + template + typename enable_if, rational_adapter&>::type operator = (Int i) { m_value = i; return *this; } + template + typename enable_if, rational_adapter&>::type operator = (Float i) + { + int e; + Float f = std::frexp(i, &e); + f = std::ldexp(f, std::numeric_limits::digits); + e -= std::numeric_limits::digits; + integer_type num(f); + integer_type denom(1u); + if(e > 0) + { + num <<= e; + } + else if(e < 0) + { + denom <<= -e; + } + m_value.assign(num, denom); + return *this; + } rational_adapter& operator = (const char* s) { std::string s1; @@ -74,7 +94,7 @@ struct rational_adapter s1.append(1, c); ++s; } - v1 = s1; + v1.assign(s1); s1.erase(); if(c == '/') { @@ -86,7 +106,7 @@ struct rational_adapter s1.append(1, c); ++s; } - v2 = s1; + v2.assign(s1); } else v2 = 1; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index abb83aa9..0acca17a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -698,6 +698,14 @@ run test_rational_io.cpp gmp release # Otherwise runtime is slow : test_rational_io_mpz ; +run test_rational_io.cpp + : # command line + : # input files + : # requirements + TEST_CPP_INT + release # Otherwise runtime is slow + : test_rational_io_cpp_int ; + run test_generic_conv.cpp : # command line : # input files @@ -792,6 +800,10 @@ if $(enable-specfun) } } +for local source in [ glob compile_fail/*.cpp ] +{ + compile-fail $(source) ; +} if ! $(disable-concepts) { diff --git a/test/compile_fail/conv_fail_1.cpp b/test/compile_fail/conv_fail_1.cpp new file mode 100644 index 00000000..c5edc3b0 --- /dev/null +++ b/test/compile_fail/conv_fail_1.cpp @@ -0,0 +1,17 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +void foo(cpp_int i) +{ +} + +int main() +{ + foo(2.3); // conversion from float is explicit +} diff --git a/test/compile_fail/conv_fail_10.cpp b/test/compile_fail/conv_fail_10.cpp new file mode 100644 index 00000000..d4376a2b --- /dev/null +++ b/test/compile_fail/conv_fail_10.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i -= 2.3; +} diff --git a/test/compile_fail/conv_fail_11.cpp b/test/compile_fail/conv_fail_11.cpp new file mode 100644 index 00000000..b07a8b89 --- /dev/null +++ b/test/compile_fail/conv_fail_11.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i *= 2.3; +} diff --git a/test/compile_fail/conv_fail_12.cpp b/test/compile_fail/conv_fail_12.cpp new file mode 100644 index 00000000..fbaf8fae --- /dev/null +++ b/test/compile_fail/conv_fail_12.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i /= 2.3; +} diff --git a/test/compile_fail/conv_fail_13.cpp b/test/compile_fail/conv_fail_13.cpp new file mode 100644 index 00000000..1d705e7f --- /dev/null +++ b/test/compile_fail/conv_fail_13.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i %= 2.3; +} diff --git a/test/compile_fail/conv_fail_14.cpp b/test/compile_fail/conv_fail_14.cpp new file mode 100644 index 00000000..54b86232 --- /dev/null +++ b/test/compile_fail/conv_fail_14.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i |= 2.3; +} diff --git a/test/compile_fail/conv_fail_15.cpp b/test/compile_fail/conv_fail_15.cpp new file mode 100644 index 00000000..e225a870 --- /dev/null +++ b/test/compile_fail/conv_fail_15.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i ^= 2.3; +} diff --git a/test/compile_fail/conv_fail_16.cpp b/test/compile_fail/conv_fail_16.cpp new file mode 100644 index 00000000..0ba8c25b --- /dev/null +++ b/test/compile_fail/conv_fail_16.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i &= 2.3; +} diff --git a/test/compile_fail/conv_fail_17.cpp b/test/compile_fail/conv_fail_17.cpp new file mode 100644 index 00000000..0649a64d --- /dev/null +++ b/test/compile_fail/conv_fail_17.cpp @@ -0,0 +1,15 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(a); +} diff --git a/test/compile_fail/conv_fail_18.cpp b/test/compile_fail/conv_fail_18.cpp new file mode 100644 index 00000000..4335d975 --- /dev/null +++ b/test/compile_fail/conv_fail_18.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(2); + i = a; +} diff --git a/test/compile_fail/conv_fail_19.cpp b/test/compile_fail/conv_fail_19.cpp new file mode 100644 index 00000000..2315252e --- /dev/null +++ b/test/compile_fail/conv_fail_19.cpp @@ -0,0 +1,15 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(a + b); +} diff --git a/test/compile_fail/conv_fail_2.cpp b/test/compile_fail/conv_fail_2.cpp new file mode 100644 index 00000000..79ffff2f --- /dev/null +++ b/test/compile_fail/conv_fail_2.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i == 2.3; +} diff --git a/test/compile_fail/conv_fail_20.cpp b/test/compile_fail/conv_fail_20.cpp new file mode 100644 index 00000000..24a63fa2 --- /dev/null +++ b/test/compile_fail/conv_fail_20.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i = a * b; +} diff --git a/test/compile_fail/conv_fail_21.cpp b/test/compile_fail/conv_fail_21.cpp new file mode 100644 index 00000000..8c845f10 --- /dev/null +++ b/test/compile_fail/conv_fail_21.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i += a * b; +} diff --git a/test/compile_fail/conv_fail_22.cpp b/test/compile_fail/conv_fail_22.cpp new file mode 100644 index 00000000..d35e837e --- /dev/null +++ b/test/compile_fail/conv_fail_22.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i -= a * b; +} diff --git a/test/compile_fail/conv_fail_23.cpp b/test/compile_fail/conv_fail_23.cpp new file mode 100644 index 00000000..3e5a9f53 --- /dev/null +++ b/test/compile_fail/conv_fail_23.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i *= a * b; +} diff --git a/test/compile_fail/conv_fail_24.cpp b/test/compile_fail/conv_fail_24.cpp new file mode 100644 index 00000000..a2581052 --- /dev/null +++ b/test/compile_fail/conv_fail_24.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i /= a * b; +} diff --git a/test/compile_fail/conv_fail_25.cpp b/test/compile_fail/conv_fail_25.cpp new file mode 100644 index 00000000..694ee712 --- /dev/null +++ b/test/compile_fail/conv_fail_25.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i %= a * b; +} diff --git a/test/compile_fail/conv_fail_26.cpp b/test/compile_fail/conv_fail_26.cpp new file mode 100644 index 00000000..0df397f4 --- /dev/null +++ b/test/compile_fail/conv_fail_26.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i &= a * b; +} diff --git a/test/compile_fail/conv_fail_27.cpp b/test/compile_fail/conv_fail_27.cpp new file mode 100644 index 00000000..3995389d --- /dev/null +++ b/test/compile_fail/conv_fail_27.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i |= a * b; +} diff --git a/test/compile_fail/conv_fail_28.cpp b/test/compile_fail/conv_fail_28.cpp new file mode 100644 index 00000000..4133aa14 --- /dev/null +++ b/test/compile_fail/conv_fail_28.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_dec_float_50 a(2), b(3); + cpp_int i(3); + i ^= a * b; +} diff --git a/test/compile_fail/conv_fail_29.cpp b/test/compile_fail/conv_fail_29.cpp new file mode 100644 index 00000000..854118fb --- /dev/null +++ b/test/compile_fail/conv_fail_29.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i + 3.3; +} diff --git a/test/compile_fail/conv_fail_3.cpp b/test/compile_fail/conv_fail_3.cpp new file mode 100644 index 00000000..0fe89320 --- /dev/null +++ b/test/compile_fail/conv_fail_3.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i != 2.3; +} diff --git a/test/compile_fail/conv_fail_30.cpp b/test/compile_fail/conv_fail_30.cpp new file mode 100644 index 00000000..4ba78fe5 --- /dev/null +++ b/test/compile_fail/conv_fail_30.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 + i; +} diff --git a/test/compile_fail/conv_fail_31.cpp b/test/compile_fail/conv_fail_31.cpp new file mode 100644 index 00000000..56a14828 --- /dev/null +++ b/test/compile_fail/conv_fail_31.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 - i; +} diff --git a/test/compile_fail/conv_fail_32.cpp b/test/compile_fail/conv_fail_32.cpp new file mode 100644 index 00000000..1769185f --- /dev/null +++ b/test/compile_fail/conv_fail_32.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i - 3.3; +} diff --git a/test/compile_fail/conv_fail_33.cpp b/test/compile_fail/conv_fail_33.cpp new file mode 100644 index 00000000..36758318 --- /dev/null +++ b/test/compile_fail/conv_fail_33.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i * 3.3; +} diff --git a/test/compile_fail/conv_fail_34.cpp b/test/compile_fail/conv_fail_34.cpp new file mode 100644 index 00000000..7d178c48 --- /dev/null +++ b/test/compile_fail/conv_fail_34.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 * i; +} diff --git a/test/compile_fail/conv_fail_35.cpp b/test/compile_fail/conv_fail_35.cpp new file mode 100644 index 00000000..67f6bdc8 --- /dev/null +++ b/test/compile_fail/conv_fail_35.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 / i; +} diff --git a/test/compile_fail/conv_fail_36.cpp b/test/compile_fail/conv_fail_36.cpp new file mode 100644 index 00000000..3b175be8 --- /dev/null +++ b/test/compile_fail/conv_fail_36.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i / 3.3; +} diff --git a/test/compile_fail/conv_fail_37.cpp b/test/compile_fail/conv_fail_37.cpp new file mode 100644 index 00000000..164db0b9 --- /dev/null +++ b/test/compile_fail/conv_fail_37.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i % 3.3; +} diff --git a/test/compile_fail/conv_fail_38.cpp b/test/compile_fail/conv_fail_38.cpp new file mode 100644 index 00000000..a905e20e --- /dev/null +++ b/test/compile_fail/conv_fail_38.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 % i; +} diff --git a/test/compile_fail/conv_fail_39.cpp b/test/compile_fail/conv_fail_39.cpp new file mode 100644 index 00000000..fa495d70 --- /dev/null +++ b/test/compile_fail/conv_fail_39.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 & i; +} diff --git a/test/compile_fail/conv_fail_4.cpp b/test/compile_fail/conv_fail_4.cpp new file mode 100644 index 00000000..6bd72119 --- /dev/null +++ b/test/compile_fail/conv_fail_4.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i <= 2.3; +} diff --git a/test/compile_fail/conv_fail_40.cpp b/test/compile_fail/conv_fail_40.cpp new file mode 100644 index 00000000..f3ccf05b --- /dev/null +++ b/test/compile_fail/conv_fail_40.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i & 3.3; +} diff --git a/test/compile_fail/conv_fail_41.cpp b/test/compile_fail/conv_fail_41.cpp new file mode 100644 index 00000000..67c30945 --- /dev/null +++ b/test/compile_fail/conv_fail_41.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i | 3.3; +} diff --git a/test/compile_fail/conv_fail_42.cpp b/test/compile_fail/conv_fail_42.cpp new file mode 100644 index 00000000..6ebe5f5b --- /dev/null +++ b/test/compile_fail/conv_fail_42.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 | i; +} diff --git a/test/compile_fail/conv_fail_43.cpp b/test/compile_fail/conv_fail_43.cpp new file mode 100644 index 00000000..cac2c020 --- /dev/null +++ b/test/compile_fail/conv_fail_43.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = 3.3 ^ i; +} diff --git a/test/compile_fail/conv_fail_44.cpp b/test/compile_fail/conv_fail_44.cpp new file mode 100644 index 00000000..32a27593 --- /dev/null +++ b/test/compile_fail/conv_fail_44.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i(3), j; + j = i ^ 3.3; +} diff --git a/test/compile_fail/conv_fail_5.cpp b/test/compile_fail/conv_fail_5.cpp new file mode 100644 index 00000000..23f49022 --- /dev/null +++ b/test/compile_fail/conv_fail_5.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i >= 2.3; +} diff --git a/test/compile_fail/conv_fail_6.cpp b/test/compile_fail/conv_fail_6.cpp new file mode 100644 index 00000000..78fea0f7 --- /dev/null +++ b/test/compile_fail/conv_fail_6.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i > 2.3; +} diff --git a/test/compile_fail/conv_fail_7.cpp b/test/compile_fail/conv_fail_7.cpp new file mode 100644 index 00000000..af4286f4 --- /dev/null +++ b/test/compile_fail/conv_fail_7.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i < 2.3; +} diff --git a/test/compile_fail/conv_fail_8.cpp b/test/compile_fail/conv_fail_8.cpp new file mode 100644 index 00000000..d741c613 --- /dev/null +++ b/test/compile_fail/conv_fail_8.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i = 2.3; +} diff --git a/test/compile_fail/conv_fail_9.cpp b/test/compile_fail/conv_fail_9.cpp new file mode 100644 index 00000000..29ce8b7b --- /dev/null +++ b/test/compile_fail/conv_fail_9.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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_0.txt) + +#include + +using namespace boost::multiprecision; + +int main() +{ + cpp_int i = 2; + i += 2.3; +} diff --git a/test/math/log1p_expm1_test.cpp b/test/math/log1p_expm1_test.cpp index 1754094c..4a53064b 100644 --- a/test/math/log1p_expm1_test.cpp +++ b/test/math/log1p_expm1_test.cpp @@ -46,7 +46,7 @@ #include #include -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include "libs/math/test/log1p_expm1_test.hpp" diff --git a/test/math/powm1_sqrtp1m1_test.cpp b/test/math/powm1_sqrtp1m1_test.cpp index c3853651..db2621eb 100644 --- a/test/math/powm1_sqrtp1m1_test.cpp +++ b/test/math/powm1_sqrtp1m1_test.cpp @@ -46,7 +46,7 @@ #include #include -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include "libs/math/test/powm1_sqrtp1m1_test.hpp" diff --git a/test/math/table_type.hpp b/test/math/table_type.hpp new file mode 100644 index 00000000..c3b5cee3 --- /dev/null +++ b/test/math/table_type.hpp @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////// +// 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_ + +#ifndef BOOST_MP_TABLE_TYPE + +#include +#include + +struct string_table_entry +{ +private: + const char* m_data; +public: + string_table_entry(const char* p) : m_data(p) {} + + template + operator T () const + { + return static_cast(m_data); + } +}; + +inline std::ostream& operator << (std::ostream& os, string_table_entry const & what) +{ + return os << static_cast(what); +} + +template +struct table_type > +{ + typedef string_table_entry type; +}; + +#define SC_(x) string_table_entry(BOOST_STRINGIZE(x)) + +#endif + diff --git a/test/math/test_bessel_i.cpp b/test/math/test_bessel_i.cpp index 3532f397..c9e7bb3c 100644 --- a/test/math/test_bessel_i.cpp +++ b/test/math/test_bessel_i.cpp @@ -41,7 +41,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#define SC_(x) static_cast::type>(BOOST_STRINGIZE(x)) #include #include "libs/math/test/test_bessel_i.hpp" diff --git a/test/math/test_bessel_j.cpp b/test/math/test_bessel_j.cpp index 931422aa..14c32412 100644 --- a/test/math/test_bessel_j.cpp +++ b/test/math/test_bessel_j.cpp @@ -41,7 +41,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include #include "libs/math/test/test_bessel_j.hpp" diff --git a/test/math/test_bessel_k.cpp b/test/math/test_bessel_k.cpp index 856180e9..46ce61b9 100644 --- a/test/math/test_bessel_k.cpp +++ b/test/math/test_bessel_k.cpp @@ -42,7 +42,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include #include "libs/math/test/test_bessel_k.hpp" diff --git a/test/math/test_bessel_y.cpp b/test/math/test_bessel_y.cpp index dd9c99dd..2672d8bd 100644 --- a/test/math/test_bessel_y.cpp +++ b/test/math/test_bessel_y.cpp @@ -41,7 +41,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include #include "libs/math/test/test_bessel_y.hpp" diff --git a/test/math/test_beta.cpp b/test/math/test_beta.cpp index b69c1808..39409cb7 100644 --- a/test/math/test_beta.cpp +++ b/test/math/test_beta.cpp @@ -41,7 +41,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include #include "libs/math/test/test_beta.hpp" diff --git a/test/math/test_binomial_coeff.cpp b/test/math/test_binomial_coeff.cpp index 146b1af2..daae89b2 100644 --- a/test/math/test_binomial_coeff.cpp +++ b/test/math/test_binomial_coeff.cpp @@ -41,7 +41,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include #include "libs/math/test/test_binomial_coeff.hpp" diff --git a/test/math/test_carlson.cpp b/test/math/test_carlson.cpp index 1aacc108..30f96116 100644 --- a/test/math/test_carlson.cpp +++ b/test/math/test_carlson.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_cbrt.cpp b/test/math/test_cbrt.cpp index b896d6d7..156e0dd6 100644 --- a/test/math/test_cbrt.cpp +++ b/test/math/test_cbrt.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_digamma.cpp b/test/math/test_digamma.cpp index 2d18eaa6..16653f83 100644 --- a/test/math/test_digamma.cpp +++ b/test/math/test_digamma.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_ellint_1.cpp b/test/math/test_ellint_1.cpp index c7da569a..b74c0f56 100644 --- a/test/math/test_ellint_1.cpp +++ b/test/math/test_ellint_1.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_ellint_2.cpp b/test/math/test_ellint_2.cpp index c07bddac..9529a21c 100644 --- a/test/math/test_ellint_2.cpp +++ b/test/math/test_ellint_2.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_ellint_3.cpp b/test/math/test_ellint_3.cpp index 9d3d6904..986b864b 100644 --- a/test/math/test_ellint_3.cpp +++ b/test/math/test_ellint_3.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_erf.cpp b/test/math/test_erf.cpp index 1b77e3a4..77db0a60 100644 --- a/test/math/test_erf.cpp +++ b/test/math/test_erf.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_expint.cpp b/test/math/test_expint.cpp index 0dbffc58..90b77e79 100644 --- a/test/math/test_expint.cpp +++ b/test/math/test_expint.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_gamma.cpp b/test/math/test_gamma.cpp index 44ca68be..a4df3f37 100644 --- a/test/math/test_gamma.cpp +++ b/test/math/test_gamma.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_hermite.cpp b/test/math/test_hermite.cpp index 271b8138..277e96a7 100644 --- a/test/math/test_hermite.cpp +++ b/test/math/test_hermite.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_ibeta.cpp b/test/math/test_ibeta.cpp index b78358f2..e48fb900 100644 --- a/test/math/test_ibeta.cpp +++ b/test/math/test_ibeta.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #define TEST_DATA 1 diff --git a/test/math/test_ibeta_2.cpp b/test/math/test_ibeta_2.cpp index 7dcc2fd8..212056a7 100644 --- a/test/math/test_ibeta_2.cpp +++ b/test/math/test_ibeta_2.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #define TEST_DATA 2 diff --git a/test/math/test_ibeta_3.cpp b/test/math/test_ibeta_3.cpp index d1f0d132..8bb2a9a9 100644 --- a/test/math/test_ibeta_3.cpp +++ b/test/math/test_ibeta_3.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #define TEST_DATA 3 diff --git a/test/math/test_ibeta_4.cpp b/test/math/test_ibeta_4.cpp index f71c117f..d4b224ff 100644 --- a/test/math/test_ibeta_4.cpp +++ b/test/math/test_ibeta_4.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #define TEST_DATA 4 diff --git a/test/math/test_ibeta_inv_1.cpp b/test/math/test_ibeta_inv_1.cpp index 88fc6184..54cb44eb 100644 --- a/test/math/test_ibeta_inv_1.cpp +++ b/test/math/test_ibeta_inv_1.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #define TEST_DATA 4 diff --git a/test/math/test_ibeta_inv_ab_4.cpp b/test/math/test_ibeta_inv_ab_4.cpp index e00fb612..e9916b96 100644 --- a/test/math/test_ibeta_inv_ab_4.cpp +++ b/test/math/test_ibeta_inv_ab_4.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #define TEST_DATA 4 diff --git a/test/math/test_igamma.cpp b/test/math/test_igamma.cpp index 429f1f40..50aff1c5 100644 --- a/test/math/test_igamma.cpp +++ b/test/math/test_igamma.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #include #include "libs/math/test/test_igamma.hpp" diff --git a/test/math/test_igamma_inv.cpp b/test/math/test_igamma_inv.cpp index 1bf31054..697b58fd 100644 --- a/test/math/test_igamma_inv.cpp +++ b/test/math/test_igamma_inv.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_igamma_inva.cpp b/test/math/test_igamma_inva.cpp index 09633434..8ff4e6d4 100644 --- a/test/math/test_igamma_inva.cpp +++ b/test/math/test_igamma_inva.cpp @@ -37,7 +37,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_laguerre.cpp b/test/math/test_laguerre.cpp index fe309c88..8f70b1ca 100644 --- a/test/math/test_laguerre.cpp +++ b/test/math/test_laguerre.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_legendre.cpp b/test/math/test_legendre.cpp index e3b26c51..7ec607ac 100644 --- a/test/math/test_legendre.cpp +++ b/test/math/test_legendre.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_tgamma_ratio.cpp b/test/math/test_tgamma_ratio.cpp index 7657e325..931ffe3c 100644 --- a/test/math/test_tgamma_ratio.cpp +++ b/test/math/test_tgamma_ratio.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/math/test_zeta.cpp b/test/math/test_zeta.cpp index 0c7976cd..1d2184ce 100644 --- a/test/math/test_zeta.cpp +++ b/test/math/test_zeta.cpp @@ -36,7 +36,7 @@ #include #endif -#define SC_(x) BOOST_STRINGIZE(x) +#include "table_type.hpp" #define TEST_UDT #include diff --git a/test/test_acos.cpp b/test/test_acos.cpp index b4dcc828..97cc96d2 100644 --- a/test/test_acos.cpp +++ b/test/test_acos.cpp @@ -53,21 +53,21 @@ void test() // static const boost::array, 13> exact_data = {{ - {{ 0.5, "1.04719755119659774615421446109316762806572313312503527365831486410260546876206966620934494178070568932738269550442743555" }}, - {{ 0.25, "1.31811607165281796574566425464604046984639096659071471685354851741333314266208327690226867044304393238598144034722708676" }}, - {{0.75, "0.722734247813415611178377352641333362025218486424440267626754132583707381914630264964827610939101303690078815991333621490" }}, - {{1 - std::ldexp(1.0, -20), "0.00138106804176241718210883847756746694048570648553426714212025111150044290934710742282266738617709904634187850607042604204" }}, - {{std::ldexp(1.0, -20), "1.57079537312058021283676140197495835299636605165647561806789944133748780804448843729970624018104090863783682329820313127" }}, - {{1, "0" }}, + {{ 0.5, static_cast("1.04719755119659774615421446109316762806572313312503527365831486410260546876206966620934494178070568932738269550442743555") }}, + {{ 0.25, static_cast("1.31811607165281796574566425464604046984639096659071471685354851741333314266208327690226867044304393238598144034722708676") }}, + {{0.75, static_cast("0.722734247813415611178377352641333362025218486424440267626754132583707381914630264964827610939101303690078815991333621490") }}, + {{1 - std::ldexp(1.0, -20), static_cast("0.00138106804176241718210883847756746694048570648553426714212025111150044290934710742282266738617709904634187850607042604204") }}, + {{std::ldexp(1.0, -20), static_cast("1.57079537312058021283676140197495835299636605165647561806789944133748780804448843729970624018104090863783682329820313127") }}, + {{1, static_cast("0") }}, - {{0, "1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332" }}, + {{0, static_cast("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332") }}, - {{ -0.5, "2.09439510239319549230842892218633525613144626625007054731662972820521093752413933241868988356141137865476539100885487110" }}, - {{ -0.25, "1.82347658193697527271697912863346241435077843278439110412139607489448326362412572172576615489907313559616664616605521989" }}, - {{-0.75, "2.41885840577637762728426603063816952217195091295066555334819045972410902437157873366320721440301576429206927052194868516" }}, - {{-1 + std::ldexp(1.0, -20), "3.14021158554803082128053454480193541725668369288957155383282434119631596337686189120521215795593996893580620800721188061" }}, - {{-std::ldexp(1.0, -20), "1.57079728046921302562588198130454453120080334771863020290704515097032859824172056132832858516107615934431126321507917538" }}, - {{-1, "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230665" }}, + {{ -0.5, static_cast("2.09439510239319549230842892218633525613144626625007054731662972820521093752413933241868988356141137865476539100885487110") }}, + {{ -0.25, static_cast("1.82347658193697527271697912863346241435077843278439110412139607489448326362412572172576615489907313559616664616605521989") }}, + {{-0.75, static_cast("2.41885840577637762728426603063816952217195091295066555334819045972410902437157873366320721440301576429206927052194868516") }}, + {{-1 + std::ldexp(1.0, -20), static_cast("3.14021158554803082128053454480193541725668369288957155383282434119631596337686189120521215795593996893580620800721188061") }}, + {{-std::ldexp(1.0, -20), static_cast("1.57079728046921302562588198130454453120080334771863020290704515097032859824172056132832858516107615934431126321507917538") }}, + {{-1, static_cast("3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230665") }}, }}; unsigned max_err = 0; for(unsigned k = 0; k < exact_data.size(); k++) diff --git a/test/test_arithmetic.cpp b/test/test_arithmetic.cpp index e15efa6a..99c1bb8b 100644 --- a/test/test_arithmetic.cpp +++ b/test/test_arithmetic.cpp @@ -64,16 +64,17 @@ #if defined(TEST_CPP_INT) || defined(TEST_CPP_INT_BR) #include #endif + +template +struct is_boost_rational : public boost::mpl::false_{}; + #if defined(TEST_TOMMATH_BOOST_RATIONAL) || defined(TEST_MPZ_BOOST_RATIONAL) #include #define NO_MIXED_OPS template -bool is_boost_rational(const boost::rational&) -{ - return true; -} +struct is_boost_rational > : public boost::mpl::true_{}; namespace boost{ namespace multiprecision{ @@ -138,7 +139,11 @@ struct is_twos_complement_integer : public boost #define BOOST_TEST_EQUAL(a, b) BOOST_TEST((a) == (b)) template -void test_comparisons(Val a, Val b) +void test_comparisons(Val, Val, const boost::mpl::false_) +{} + +template +void test_comparisons(Val a, Val b, const boost::mpl::true_) { Real r1(a); Real r2(b); @@ -222,14 +227,8 @@ void test_complement(Real, Real, Real, const boost::mpl::false_&) template void test_integer_ops(const T&){} -template -bool is_boost_rational(const T&) -{ - return false; -} - template -void test_integer_ops(const boost::mpl::int_&) +void test_rational(const boost::mpl::true_&) { Real a(2); a /= 3; @@ -240,16 +239,29 @@ void test_integer_ops(const boost::mpl::int_> b; + BOOST_CHECK_EQUAL(a, b); +} + +template +void test_rational(const boost::mpl::false_&) +{ + Real a(2); + a /= 3; + BOOST_TEST(numerator(a) == 2); + BOOST_TEST(denominator(a) == 3); + Real b(4); + b /= 6; + BOOST_TEST(a == b); + + BOOST_CHECK_THROW(Real(a / 0), std::overflow_error); + BOOST_CHECK_THROW(Real("3.14"), std::runtime_error); + b = Real("2/3"); + BOOST_CHECK_EQUAL(a, b); // // Check IO code: // @@ -259,6 +271,12 @@ void test_integer_ops(const boost::mpl::int_ +void test_integer_ops(const boost::mpl::int_&) +{ + test_rational(is_boost_rational()); +} + template void test_integer_ops(const boost::mpl::int_&) { @@ -661,6 +679,16 @@ void test_negative_mixed(boost::mpl::true_ const&) if(std::numeric_limits::is_specialized && !std::numeric_limits::is_signed) return; typedef typename lexical_cast_target_type::type target_type; + typedef typename boost::mpl::if_< + boost::is_convertible, + typename boost::mpl::if_c::value && (sizeof(Num) < sizeof(int)), int, Num>::type, + Real + >::type cast_type; + typedef typename boost::mpl::if_< + boost::is_convertible, + Num, + Real + >::type simple_cast_type; std::cout << "Testing mixed arithmetic with type: " << typeid(Real).name() << " and " << typeid(Num).name() << std::endl; Num n1 = -static_cast(1uLL << (std::numeric_limits::digits - 1)); Num n2 = -1; @@ -668,22 +696,22 @@ void test_negative_mixed(boost::mpl::true_ const&) Num n4 = -20; Num n5 = -8; - test_comparisons(n1, n2); - test_comparisons(n1, n3); - test_comparisons(n3, n1); - test_comparisons(n2, n1); - test_comparisons(n1, n1); - test_comparisons(n3, n3); + test_comparisons(n1, n2, boost::is_convertible()); + test_comparisons(n1, n3, boost::is_convertible()); + test_comparisons(n3, n1, boost::is_convertible()); + test_comparisons(n2, n1, boost::is_convertible()); + test_comparisons(n1, n1, boost::is_convertible()); + test_comparisons(n3, n3, boost::is_convertible()); // Default construct: - BOOST_TEST(Real(n1) == n1); - BOOST_TEST(Real(n2) == n2); - BOOST_TEST(Real(n3) == n3); - BOOST_TEST(Real(n4) == n4); - BOOST_TEST(n1 == Real(n1)); - BOOST_TEST(n2 == Real(n2)); - BOOST_TEST(n3 == Real(n3)); - BOOST_TEST(n4 == Real(n4)); + BOOST_TEST(Real(n1) == static_cast(n1)); + BOOST_TEST(Real(n2) == static_cast(n2)); + BOOST_TEST(Real(n3) == static_cast(n3)); + BOOST_TEST(Real(n4) == static_cast(n4)); + BOOST_TEST(static_cast(n1) == Real(n1)); + BOOST_TEST(static_cast(n2) == Real(n2)); + BOOST_TEST(static_cast(n3) == Real(n3)); + BOOST_TEST(static_cast(n4) == Real(n4)); BOOST_TEST(Real(n1).template convert_to() == n1); BOOST_TEST(Real(n2).template convert_to() == n2); BOOST_TEST(Real(n3).template convert_to() == n3); @@ -709,54 +737,54 @@ void test_negative_mixed(boost::mpl::true_ const&) BOOST_TEST_CLOSE(n4, boost::lexical_cast(Real(n4).str(0, f)), 0); // Assignment: Real r(0); - BOOST_TEST(r != n1); - r = n1; - BOOST_TEST(r == n1); - r = n2; - BOOST_TEST(r == n2); - r = n3; - BOOST_TEST(r == n3); - r = n4; - BOOST_TEST(r == n4); + BOOST_TEST(r != static_cast(n1)); + r = static_cast(n1); + BOOST_TEST(r == static_cast(n1)); + r = static_cast(n2); + BOOST_TEST(r == static_cast(n2)); + r = static_cast(n3); + BOOST_TEST(r == static_cast(n3)); + r = static_cast(n4); + BOOST_TEST(r == static_cast(n4)); // Addition: - r = n2; - BOOST_TEST(r + n4 == n2 + n4); - BOOST_TEST(Real(r + n4) == n2 + n4); - r += n4; - BOOST_TEST(r == n2 + n4); + r = static_cast(n2); + BOOST_TEST(r + static_cast(n4) == static_cast(n2 + n4)); + BOOST_TEST(Real(r + static_cast(n4)) == static_cast(n2 + n4)); + r += static_cast(n4); + BOOST_TEST(r == static_cast(n2 + n4)); // subtraction: - r = n4; - BOOST_TEST(r - n5 == n4 - n5); - BOOST_TEST(Real(r - n5) == n4 - n5); - r -= n5; - BOOST_TEST(r == n4 - n5); + r = static_cast(n4); + BOOST_TEST(r - static_cast(n5) == static_cast(n4 - n5)); + BOOST_TEST(Real(r - static_cast(n5)) == static_cast(n4 - n5)); + r -= static_cast(n5); + BOOST_TEST(r == static_cast(n4 - n5)); // Multiplication: - r = n2; - BOOST_TEST(r * n4 == n2 * n4); - BOOST_TEST(Real(r * n4) == n2 * n4); - r *= n4; - BOOST_TEST(r == n2 * n4); + r = static_cast(n2); + BOOST_TEST(r * static_cast(n4) == static_cast(n2 * n4)); + BOOST_TEST(Real(r * static_cast(n4)) == static_cast(n2 * n4)); + r *= static_cast(n4); + BOOST_TEST(r == static_cast(n2 * n4)); // Division: - r = n1; - BOOST_TEST(r / n5 == n1 / n5); - BOOST_TEST(Real(r / n5) == n1 / n5); - r /= n5; - BOOST_TEST(r == n1 / n5); + r = static_cast(n1); + BOOST_TEST(r / static_cast(n5) == static_cast(n1 / n5)); + BOOST_TEST(Real(r / static_cast(n5)) == static_cast(n1 / n5)); + r /= static_cast(n5); + BOOST_TEST(r == static_cast(n1 / n5)); // // Extra cases for full coverage: // - r = Real(n4) + n5; - BOOST_TEST(r == n4 + n5); - r = n4 + Real(n5); - BOOST_TEST(r == n4 + n5); - r = Real(n4) - n5; - BOOST_TEST(r == n4 - n5); - r = n4 - Real(n5); - BOOST_TEST(r == n4 - n5); - r = n4 * Real(n5); - BOOST_TEST(r == n4 * n5); - r = (4 * n4) / Real(4); - BOOST_TEST(r == n4); + r = Real(n4) + static_cast(n5); + BOOST_TEST(r == static_cast(n4 + n5)); + r = static_cast(n4) + Real(n5); + BOOST_TEST(r == static_cast(n4 + n5)); + r = Real(n4) - static_cast(n5); + BOOST_TEST(r == static_cast(n4 - n5)); + r = static_cast(n4) - Real(n5); + BOOST_TEST(r == static_cast(n4 - n5)); + r = static_cast(n4) * Real(n5); + BOOST_TEST(r == static_cast(n4 * n5)); + r = static_cast(4 * n4) / Real(4); + BOOST_TEST(r == static_cast(n4)); } template @@ -768,6 +796,16 @@ template void test_mixed() { typedef typename lexical_cast_target_type::type target_type; + typedef typename boost::mpl::if_< + boost::is_convertible, + typename boost::mpl::if_c::value && (sizeof(Num) < sizeof(int)), int, Num>::type, + Real + >::type cast_type; + typedef typename boost::mpl::if_< + boost::is_convertible, + Num, + Real + >::type simple_cast_type; if(std::numeric_limits::digits < std::numeric_limits::digits) return; @@ -779,18 +817,18 @@ void test_mixed() Num n4 = 20; Num n5 = 8; - test_comparisons(n1, n2); - test_comparisons(n1, n3); - test_comparisons(n1, n1); - test_comparisons(n3, n1); - test_comparisons(n2, n1); - test_comparisons(n3, n3); + test_comparisons(n1, n2, boost::is_convertible()); + test_comparisons(n1, n3, boost::is_convertible()); + test_comparisons(n1, n1, boost::is_convertible()); + test_comparisons(n3, n1, boost::is_convertible()); + test_comparisons(n2, n1, boost::is_convertible()); + test_comparisons(n3, n3, boost::is_convertible()); // Default construct: - BOOST_TEST(Real(n1) == n1); - BOOST_TEST(Real(n2) == n2); - BOOST_TEST(Real(n3) == n3); - BOOST_TEST(Real(n4) == n4); + BOOST_TEST(Real(n1) == static_cast(n1)); + BOOST_TEST(Real(n2) == static_cast(n2)); + BOOST_TEST(Real(n3) == static_cast(n3)); + BOOST_TEST(Real(n4) == static_cast(n4)); BOOST_TEST(Real(n1).template convert_to() == n1); BOOST_TEST(Real(n2).template convert_to() == n2); BOOST_TEST(Real(n3).template convert_to() == n3); @@ -801,10 +839,10 @@ void test_mixed() BOOST_TEST(static_cast(Real(n3)) == n3); BOOST_TEST(static_cast(Real(n4)) == n4); #endif - BOOST_TEST(n1 == Real(n1)); - BOOST_TEST(n2 == Real(n2)); - BOOST_TEST(n3 == Real(n3)); - BOOST_TEST(n4 == Real(n4)); + BOOST_TEST(static_cast(n1) == Real(n1)); + BOOST_TEST(static_cast(n2) == Real(n2)); + BOOST_TEST(static_cast(n3) == Real(n3)); + BOOST_TEST(static_cast(n4) == Real(n4)); #if defined(TEST_MPFR) || defined(TEST_MPFR_50) Num tol = 10 * std::numeric_limits::epsilon(); #else @@ -820,50 +858,50 @@ void test_mixed() BOOST_TEST_CLOSE(n4, boost::lexical_cast(Real(n4).str(0, f)), 0); // Assignment: Real r(0); - BOOST_TEST(r != n1); - r = n1; - BOOST_TEST(r == n1); - r = n2; - BOOST_TEST(r == n2); - r = n3; - BOOST_TEST(r == n3); - r = n4; - BOOST_TEST(r == n4); + BOOST_TEST(r != static_cast(n1)); + r = static_cast(n1); + BOOST_TEST(r == static_cast(n1)); + r = static_cast(n2); + BOOST_TEST(r == static_cast(n2)); + r = static_cast(n3); + BOOST_TEST(r == static_cast(n3)); + r = static_cast(n4); + BOOST_TEST(r == static_cast(n4)); // Addition: - r = n2; - BOOST_TEST(r + n4 == n2 + n4); - BOOST_TEST(Real(r + n4) == n2 + n4); - r += n4; - BOOST_TEST(r == n2 + n4); + r = static_cast(n2); + BOOST_TEST(r + static_cast(n4) == static_cast(n2 + n4)); + BOOST_TEST(Real(r + static_cast(n4)) == static_cast(n2 + n4)); + r += static_cast(n4); + BOOST_TEST(r == static_cast(n2 + n4)); // subtraction: - r = n4; - BOOST_TEST(r - n5 == n4 - n5); - BOOST_TEST(Real(r - n5) == n4 - n5); - r -= n5; - BOOST_TEST(r == n4 - n5); + r = static_cast(n4); + BOOST_TEST(r - static_cast(n5) == static_cast(n4 - n5)); + BOOST_TEST(Real(r - static_cast(n5)) == static_cast(n4 - n5)); + r -= static_cast(n5); + BOOST_TEST(r == static_cast(n4 - n5)); // Multiplication: - r = n2; - BOOST_TEST(r * n4 == n2 * n4); - BOOST_TEST(Real(r * n4) == n2 * n4); - r *= n4; - BOOST_TEST(r == n2 * n4); + r = static_cast(n2); + BOOST_TEST(r * static_cast(n4) == static_cast(n2 * n4)); + BOOST_TEST(Real(r * static_cast(n4)) == static_cast(n2 * n4)); + r *= static_cast(n4); + BOOST_TEST(r == static_cast(n2 * n4)); // Division: - r = n1; - BOOST_TEST(r / n5 == n1 / n5); - BOOST_TEST(Real(r / n5) == n1 / n5); - r /= n5; - BOOST_TEST(r == n1 / n5); + r = static_cast(n1); + BOOST_TEST(r / static_cast(n5) == static_cast(n1 / n5)); + BOOST_TEST(Real(r / static_cast(n5)) == static_cast(n1 / n5)); + r /= static_cast(n5); + BOOST_TEST(r == static_cast(n1 / n5)); // // special cases for full coverage: // - r = n5 + Real(n4); - BOOST_TEST(r == n4 + n5); - r = n4 - Real(n5); - BOOST_TEST(r == n4 - n5); - r = n4 * Real(n5); - BOOST_TEST(r == n4 * n5); - r = (4 * n4) / Real(4); - BOOST_TEST(r == n4); + r = static_cast(n5) + Real(n4); + BOOST_TEST(r == static_cast(n4 + n5)); + r = static_cast(n4) - Real(n5); + BOOST_TEST(r == static_cast(n4 - n5)); + r = static_cast(n4) * Real(n5); + BOOST_TEST(r == static_cast(n4 * n5)); + r = static_cast(4 * n4) / Real(4); + BOOST_TEST(r == static_cast(n4)); test_negative_mixed(boost::mpl::bool_::is_signed>()); } diff --git a/test/test_asin.cpp b/test/test_asin.cpp index 271172fe..2b56e062 100644 --- a/test/test_asin.cpp +++ b/test/test_asin.cpp @@ -53,12 +53,12 @@ void test() // static const boost::array, 6> exact_data = {{ - {{ 0.5, "0.523598775598298873077107230546583814032861566562517636829157432051302734381034833104672470890352844663691347752213717775" }}, - {{ 0.25, "0.252680255142078653485657436993710972252193733096838193633923778740575060481021222411748742228014601605092602909414066566" }}, - {{0.75, "0.848062078981481008052944338998418080073366213263112642860718163570200821228474234349189801731957230300995227265307531834" }}, - {{std::ldexp(1.0, -20), "9.53674316406394560289664793089102218648031077292419572854816420395098616062014311172490017625353237219958438022056661501e-7" }}, - {{ 1 - std::ldexp(1.0, -20), "1.56941525875313420204921285316218397515809899320201864334535204504240776023375739189119474528488143494473216475057072728" }}, - {{ 1, "1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064" }}, + {{ 0.5, static_cast("0.523598775598298873077107230546583814032861566562517636829157432051302734381034833104672470890352844663691347752213717775") }}, + {{ 0.25, static_cast("0.252680255142078653485657436993710972252193733096838193633923778740575060481021222411748742228014601605092602909414066566") }}, + {{0.75, static_cast("0.848062078981481008052944338998418080073366213263112642860718163570200821228474234349189801731957230300995227265307531834") }}, + {{std::ldexp(1.0, -20), static_cast("9.53674316406394560289664793089102218648031077292419572854816420395098616062014311172490017625353237219958438022056661501e-7") }}, + {{ 1 - std::ldexp(1.0, -20), static_cast("1.56941525875313420204921285316218397515809899320201864334535204504240776023375739189119474528488143494473216475057072728") }}, + {{ 1, static_cast("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064") }}, }}; unsigned max_err = 0; for(unsigned k = 0; k < exact_data.size(); k++) diff --git a/test/test_atan.cpp b/test/test_atan.cpp index 1b28a395..5e139fdf 100644 --- a/test/test_atan.cpp +++ b/test/test_atan.cpp @@ -123,7 +123,7 @@ void test() "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412671058533891074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600954572824283461730174305227163324106696803630124570637195626836636491127420774093793814747960379191015517279628513338998598607743566594025406809304089138", }}; - T arg = "1e-100"; + T arg = static_cast("1e-100"); unsigned max_err = 0; for(unsigned k = 0; k < data.size(); k++) @@ -149,7 +149,7 @@ void test() // // And again, but test all the phases of atan2: // - arg = "1e-100"; + arg = static_cast("1e-100"); unsigned err; for(unsigned k = 0; k < data.size(); k++) { diff --git a/test/test_constants.cpp b/test/test_constants.cpp index 4e72ca11..770b8721 100644 --- a/test/test_constants.cpp +++ b/test/test_constants.cpp @@ -172,13 +172,13 @@ void test() typedef typename T::backend_type backend_type; T num, expect; num.backend() = boost::multiprecision::default_ops::get_constant_pi(); - expect = pi; + expect = static_cast(pi); BOOST_CHECK_CLOSE_FRACTION(num, expect, std::numeric_limits::epsilon() * (is_mpfr(num) ? 1200 : 2)); num.backend() = boost::multiprecision::default_ops::get_constant_ln2(); - expect = ln2; + expect = static_cast(ln2); BOOST_CHECK_CLOSE_FRACTION(num, expect, std::numeric_limits::epsilon() * (is_mpfr(num) ? 30 : 1)); num.backend() = boost::multiprecision::default_ops::get_constant_e(); - expect = e; + expect = static_cast(e); BOOST_CHECK_CLOSE_FRACTION(num, expect, std::numeric_limits::epsilon() * (is_mpfr(num) ? 2 : 1)); } diff --git a/test/test_cos.cpp b/test/test_cos.cpp index 36488b1b..e429d06b 100644 --- a/test/test_cos.cpp +++ b/test/test_cos.cpp @@ -155,7 +155,7 @@ void test() boost::uintmax_t max_err = 0; for(unsigned k = 0; k < data.size(); k++) { - static const T euler_gamma = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + static const T euler_gamma = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); T val = cos(euler_gamma * ((100 * k) - 5000)); T e = relative_error(val, T(data[k])); unsigned err = e.template convert_to(); @@ -225,12 +225,12 @@ void test() "0.09655529472977379853549858833033074225823562054271495313739665642376685099661084023094270272485976247900824483810911634635819558334630910267353320029261330296977292720266655308513559530586843550229208517388789783011887450865488554143475302590353915732321663418057567573042594801866258948380684000769091353165879953111046260532796891917772727185993569684246844052518121013717183610828519193371796413317", }}; - T half_pi = "1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064"; + T half_pi = static_cast("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064"); max_err = 0; for(unsigned k = 0; k < near_one.size(); k++) { - static const T euler_gamma = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + static const T euler_gamma = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); T val = cos(half_pi - (euler_gamma + k) / 523); T e = relative_error(val, T(near_one[k])); unsigned err = e.template convert_to(); @@ -251,14 +251,14 @@ void test() // static const boost::array, 8> exact_data = {{ - {{ 0.5, "0.877582561890372716116281582603829651991645197109744052997610868315950763274213947405794184084682258355478400593109053993" }}, - {{ 0.25, "0.968912421710644784144595449494189199804134190287442831148128124288942561184523327264655202799685025510352709626116202617" }}, - {{0.75, "0.731688868873820886311838753000084543840541276050772482507683220220750082501569499540967562610201174960122884908227300721" }}, - {{std::ldexp(1.0, -20), "0.99999999999954525264911357034690133684385823577463126432241468890539365027135494672267164697779879113636143901797362388" }}, - {{ 2, "-0.416146836547142386997568229500762189766000771075544890755149973781964936124079169074531777860169140367366791365215728559" }}, - {{ 5, "0.283662185463226264466639171513557308334422592252215944930359066586151456767382702286176981668344573238827368717546699737" }}, - {{ 10, "-0.839071529076452452258863947824064834519930165133168546835953731048792586866270768400933712760422138927451054405350243624" }}, - {{ 8.5, "-0.60201190268482361534842652295699870029606776360435523539636606145572515876770619546025351418378467287262574566665150299" }} + {{ 0.5, static_cast("0.877582561890372716116281582603829651991645197109744052997610868315950763274213947405794184084682258355478400593109053993") }}, + {{ 0.25, static_cast("0.968912421710644784144595449494189199804134190287442831148128124288942561184523327264655202799685025510352709626116202617") }}, + {{0.75, static_cast("0.731688868873820886311838753000084543840541276050772482507683220220750082501569499540967562610201174960122884908227300721") }}, + {{std::ldexp(1.0, -20), static_cast("0.99999999999954525264911357034690133684385823577463126432241468890539365027135494672267164697779879113636143901797362388") }}, + {{ 2, static_cast("-0.416146836547142386997568229500762189766000771075544890755149973781964936124079169074531777860169140367366791365215728559") }}, + {{ 5, static_cast("0.283662185463226264466639171513557308334422592252215944930359066586151456767382702286176981668344573238827368717546699737") }}, + {{ 10, static_cast("-0.839071529076452452258863947824064834519930165133168546835953731048792586866270768400933712760422138927451054405350243624") }}, + {{ 8.5, static_cast("-0.60201190268482361534842652295699870029606776360435523539636606145572515876770619546025351418378467287262574566665150299") }} }}; max_err = 0; for(unsigned k = 0; k < exact_data.size(); k++) diff --git a/test/test_cosh.cpp b/test/test_cosh.cpp index 46900c40..b2c82e08 100644 --- a/test/test_cosh.cpp +++ b/test/test_cosh.cpp @@ -102,7 +102,7 @@ void test() "4.4466189016791091516801723880812533528438597080549410911235655611382010503145789286158745555771483577943662768773465284793798720178177605712848440200402906836390133865748188969184005230383247111166918721449908133920663776952786683837038180436264738937354101153867171804315769471050303182129269442292354388037298125177941217926845803005587166270803697433886463469168814941555804311717400657004050157245e1110", }}; - T eg = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + T eg = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); unsigned max_err = 0; for(unsigned k = 0; k < data.size(); k++) diff --git a/test/test_cpp_int.cpp b/test/test_cpp_int.cpp index 9efa78a3..1ba8f9ec 100644 --- a/test/test_cpp_int.cpp +++ b/test/test_cpp_int.cpp @@ -72,10 +72,10 @@ void test() int si = d.convert_to(); unsigned ui = si; - test_type a1 = a.str(); - test_type b1 = b.str(); - test_type c1 = c.str(); - test_type d1 = d.str(); + test_type a1 = static_cast(a.str()); + test_type b1 = static_cast(b.str()); + test_type c1 = static_cast(c.str()); + test_type d1 = static_cast(d.str()); BOOST_CHECK_EQUAL(a.str(), a1.str()); BOOST_CHECK_EQUAL(b.str(), b1.str()); diff --git a/test/test_exp.cpp b/test/test_exp.cpp index 4167d4c7..424601dc 100644 --- a/test/test_exp.cpp +++ b/test/test_exp.cpp @@ -102,7 +102,7 @@ void test() "6.83336127500041943234365059231968669406267422759442985746460610830503287734479988530512309065240678799786759250323660701e3848", }}; - T pi = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609"; + T pi = static_cast("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609"); unsigned max_err = 0; for(unsigned k = 0; k < data.size(); k++) @@ -127,16 +127,16 @@ void test() static const boost::array, 10> exact_data = {{ - {{ std::ldexp(1.0, -50), "1.00000000000000088817841970012562676935794497867573073630970950828771105957980924149923657574337470594698012676100224953" }}, - {{ std::ldexp(1.0, -20), "1.00000095367477115374544678824955687428365188553281789775169686343569285229334215539516690752571791280462887427635269562" }}, - {{ std::ldexp(1.0, -10), "1.00097703949241653524284529261160650646585162918174419940186408264916250428896869173656853690882467186075613761065459261" }}, - {{ 0.25, "1.28402541668774148407342056806243645833628086528146308921750729687220776586723800275330641943955356890166283174967968731" }}, - {{ 0.5, "1.64872127070012814684865078781416357165377610071014801157507931164066102119421560863277652005636664300286663775630779700" }}, - {{ 0.75, "2.11700001661267466854536981983709561013449158470240342177913303081098453336401282000279156026661579821888590471901551426" }}, - {{ 10, "22026.4657948067165169579006452842443663535126185567810742354263552252028185707925751991209681645258954515555010924578367" }}, - {{ 10.5, "36315.5026742466377389120269013166179689315579671275857607480190550842856628099187749764427758174866310742771977376827512" }}, - {{ 25, "7.20048993373858725241613514661261579152235338133952787362213864472320593107782569745000325654258093194727871848859163684e10" }}, - {{ 31.25, "3.72994612957188849046766396046821396700589012875701157893019118883826370993674081486706667149871508642909416337810227575e13" }}, + {{ std::ldexp(1.0, -50), static_cast("1.00000000000000088817841970012562676935794497867573073630970950828771105957980924149923657574337470594698012676100224953") }}, + {{ std::ldexp(1.0, -20), static_cast("1.00000095367477115374544678824955687428365188553281789775169686343569285229334215539516690752571791280462887427635269562") }}, + {{ std::ldexp(1.0, -10), static_cast("1.00097703949241653524284529261160650646585162918174419940186408264916250428896869173656853690882467186075613761065459261") }}, + {{ 0.25, static_cast("1.28402541668774148407342056806243645833628086528146308921750729687220776586723800275330641943955356890166283174967968731") }}, + {{ 0.5, static_cast("1.64872127070012814684865078781416357165377610071014801157507931164066102119421560863277652005636664300286663775630779700") }}, + {{ 0.75, static_cast("2.11700001661267466854536981983709561013449158470240342177913303081098453336401282000279156026661579821888590471901551426") }}, + {{ 10, static_cast("22026.4657948067165169579006452842443663535126185567810742354263552252028185707925751991209681645258954515555010924578367") }}, + {{ 10.5, static_cast("36315.5026742466377389120269013166179689315579671275857607480190550842856628099187749764427758174866310742771977376827512") }}, + {{ 25, static_cast("7.20048993373858725241613514661261579152235338133952787362213864472320593107782569745000325654258093194727871848859163684e10") }}, + {{ 31.25, static_cast("3.72994612957188849046766396046821396700589012875701157893019118883826370993674081486706667149871508642909416337810227575e13") }}, }}; max_err = 0; diff --git a/test/test_float_io.cpp b/test/test_float_io.cpp index 410b531a..d2973446 100644 --- a/test/test_float_io.cpp +++ b/test/test_float_io.cpp @@ -172,18 +172,18 @@ void test() BOOST_CHECK_EQUAL(val.str(), "-inf"); BOOST_CHECK_EQUAL(val.str(0, std::ios_base::showpos), "-inf"); - val = "inf"; + val = static_cast("inf"); BOOST_CHECK_EQUAL(val, std::numeric_limits::infinity()); - val = "+inf"; + val = static_cast("+inf"); BOOST_CHECK_EQUAL(val, std::numeric_limits::infinity()); - val = "-inf"; + val = static_cast("-inf"); BOOST_CHECK_EQUAL(val, -std::numeric_limits::infinity()); } if(std::numeric_limits::has_quiet_NaN) { T val = std::numeric_limits::quiet_NaN(); BOOST_CHECK_EQUAL(val.str(), "nan"); - val = "nan"; + val = static_cast("nan"); BOOST_CHECK(boost::math::isnan(val)); } } @@ -246,9 +246,9 @@ void do_round_trip(const T& val, std::ios_base::fmtflags f) #endif ss.flags(f); ss << val; - T new_val = ss.str(); + T new_val = static_cast(ss.str()); BOOST_CHECK_EQUAL(new_val, val); - new_val = val.str(0, f); + new_val = static_cast(val.str(0, f)); BOOST_CHECK_EQUAL(new_val, val); } diff --git a/test/test_generic_conv.cpp b/test/test_generic_conv.cpp index a552a3cd..6664f4e9 100644 --- a/test/test_generic_conv.cpp +++ b/test/test_generic_conv.cpp @@ -91,18 +91,18 @@ int main() dec_float_500 tol("1e-500"); #ifdef TEST_GMP mpf = df; - mpf2 = df.str(); + mpf2 = static_cast(df.str()); BOOST_CHECK_EQUAL(mpf, mpf2); df = mpf; - df2 = mpf.str(); + df2 = static_cast(mpf.str()); BOOST_CHECK(fabs((df - df2) / df) < tol); #endif #ifdef TEST_MPFR mpfr = df; - mpfr2 = df.str(); + mpfr2 = static_cast(df.str()); BOOST_CHECK_EQUAL(mpfr, mpfr2); df = mpfr; - df2 = mpfr.str(); + df2 = static_cast(mpfr.str()); BOOST_CHECK(fabs((df - df2) / df) < tol); #endif // @@ -124,12 +124,12 @@ int main() // #ifdef TEST_GMP mpq = c; - mpq_rational mpq2 = c.str(); + mpq_rational mpq2 = static_cast(c.str()); BOOST_CHECK_EQUAL(mpq, mpq2); #endif #ifdef TEST_TOMMATH tr = c; - tom_rational tr2 = c.str(); + tom_rational tr2 = static_cast(c.str()); BOOST_CHECK_EQUAL(tr, tr2); #endif // diff --git a/test/test_gmp_conversions.cpp b/test/test_gmp_conversions.cpp index fad3d97d..8b1b2ec0 100644 --- a/test/test_gmp_conversions.cpp +++ b/test/test_gmp_conversions.cpp @@ -101,13 +101,13 @@ int main() rat = 2; BOOST_TEST(mpz_int(rat) == 2); iz = 3; - iz = f0; + iz = static_cast(f0); BOOST_TEST(iz == 2); iz = 3; - iz = f50; + iz = static_cast(f50); BOOST_TEST(iz == 2); iz = 3; - iz = rat; + iz = static_cast(rat); BOOST_TEST(iz == 2); BOOST_TEST(mpq_rational(mpz) == 2); diff --git a/test/test_int_io.cpp b/test/test_int_io.cpp index 1f87a88c..b603fa88 100644 --- a/test/test_int_io.cpp +++ b/test/test_int_io.cpp @@ -66,9 +66,9 @@ void do_round_trip(const T& val, std::ios_base::fmtflags f) #endif ss.flags(f); ss << val; - T new_val = ss.str(); + T new_val = static_cast(ss.str()); BOOST_CHECK_EQUAL(new_val, val); - new_val = val.str(0, f); + new_val = static_cast(val.str(0, f)); BOOST_CHECK_EQUAL(new_val, val); } diff --git a/test/test_log.cpp b/test/test_log.cpp index 1d5f0342..6426e307 100644 --- a/test/test_log.cpp +++ b/test/test_log.cpp @@ -152,7 +152,7 @@ void test() "19.565410630120075532420489068555321524954362381908007338302983473268528473151341321768804731192210840056455228388636731122203200610869021021871133154865620432257415783302175345843898977949742849569372169004904667621738405749986270376895267386643049526766451459390277406632576412790748533372863644721976845168460840162066672290292749672668879524315410824251032084115058493720402881895485689493165441193", }}; - T pi = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609"; + T pi = static_cast("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609"); T tenth = 1; tenth /= 10; T logten = log(T(10)); diff --git a/test/test_rational_io.cpp b/test/test_rational_io.cpp index 8003d4f3..7b027cbf 100644 --- a/test/test_rational_io.cpp +++ b/test/test_rational_io.cpp @@ -9,9 +9,10 @@ # define _SCL_SECURE_NO_WARNINGS #endif -#if !defined(TEST_MPQ) && !defined(TEST_TOMMATH) +#if !defined(TEST_MPQ) && !defined(TEST_TOMMATH) && !defined(TEST_CPP_INT) # define TEST_MPQ # define TEST_TOMMATH +# define TEST_CPP_INT #ifdef _MSC_VER #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!") @@ -28,6 +29,9 @@ #if defined(TEST_TOMMATH) #include #endif +#ifdef TEST_CPP_INT +#include +#endif #include #include @@ -71,9 +75,9 @@ void do_round_trip(const T& val, std::ios_base::fmtflags f, const boost::mpl::tr #endif ss.flags(f); ss << val; - T new_val = ss.str(); + T new_val = static_cast(ss.str()); BOOST_CHECK_EQUAL(new_val, val); - new_val = val.str(0, f); + new_val = static_cast(val.str(0, f)); BOOST_CHECK_EQUAL(new_val, val); } @@ -132,6 +136,10 @@ int main() #ifdef TEST_TOMMATH test_round_trip >(); test_round_trip(); +#endif +#ifdef TEST_CPP_INT + test_round_trip >(); + test_round_trip(); #endif return boost::report_errors(); } diff --git a/test/test_sin.cpp b/test/test_sin.cpp index fef86827..78d1b620 100644 --- a/test/test_sin.cpp +++ b/test/test_sin.cpp @@ -155,7 +155,7 @@ void test() boost::uintmax_t max_err = 0; for(unsigned k = 0; k < data.size(); k++) { - static const T euler_gamma = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + static const T euler_gamma = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); T val = sin(euler_gamma * ((100 * k) - 5000)); T e = relative_error(val, T(data[k])); unsigned err = e.template convert_to(); @@ -228,7 +228,7 @@ void test() max_err = 0; for(unsigned k = 0; k < small_data.size(); k++) { - static const T euler_gamma = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + static const T euler_gamma = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); T val = sin((euler_gamma + k) / 53); T e = relative_error(val, T(small_data[k])); unsigned err = e.template convert_to(); @@ -252,15 +252,15 @@ void test() // static const boost::array, 9> exact_data = {{ - {{ 0.5, "0.479425538604203000273287935215571388081803367940600675188616613125535000287814832209631274684348269086132091084505717418" }}, - {{ 0.25, "0.247403959254522929596848704849389195893390980386965810676544830494398136043486821690984848527973792338327197752176516138" }}, - {{0.75, "0.681638760023334166733241952779893935338382394659229909213625262151100388887003782753145274849781911981438190343146876189" }}, - {{std::ldexp(1.0, -20), "9.53674316406105439710335272649306549801506698739838753888815787489707114648106832493113326022411646219016312547902694921e-7" }}, - {{ 2, "0.909297426825681695396019865911744842702254971447890268378973011530967301540783544620126688924959380309967896742399486261" }}, - {{ 5, "-0.958924274663138468893154406155993973352461543964601778131672454235102558086559603076995955429532866596530638461663378937" }}, - {{ 10, "-0.544021110889369813404747661851377281683643012916223891574184012616757209640493425707075673894983216158293824238262832286" }}, + {{ 0.5, static_cast("0.479425538604203000273287935215571388081803367940600675188616613125535000287814832209631274684348269086132091084505717418") }}, + {{ 0.25, static_cast("0.247403959254522929596848704849389195893390980386965810676544830494398136043486821690984848527973792338327197752176516138") }}, + {{0.75, static_cast("0.681638760023334166733241952779893935338382394659229909213625262151100388887003782753145274849781911981438190343146876189") }}, + {{std::ldexp(1.0, -20), static_cast("9.53674316406105439710335272649306549801506698739838753888815787489707114648106832493113326022411646219016312547902694921e-7") }}, + {{ 2, static_cast("0.909297426825681695396019865911744842702254971447890268378973011530967301540783544620126688924959380309967896742399486261") }}, + {{ 5, static_cast("-0.958924274663138468893154406155993973352461543964601778131672454235102558086559603076995955429532866596530638461663378937") }}, + {{ 10, static_cast("-0.544021110889369813404747661851377281683643012916223891574184012616757209640493425707075673894983216158293824238262832286") }}, {{ 0, 0 }}, - {{ "1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064", 1 }} + {{ static_cast("1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440548783296672306423782411689339158263560095457282428346173017430522716332410669680363012457064"), 1 }} }}; max_err = 0; for(unsigned k = 0; k < exact_data.size(); k++) diff --git a/test/test_sinh.cpp b/test/test_sinh.cpp index 2a18c8b5..ae8f11d0 100644 --- a/test/test_sinh.cpp +++ b/test/test_sinh.cpp @@ -102,7 +102,7 @@ void test() "4.4466189016791091516801723880812533528438597080549410911235655611382010503145789286158745555771483577943662768773465284793798720178177605712848440200402906836390133865748188969184005230383247111166918721449908133920663776952786683837038180436264738937354101153867171804315769471050303182129269442292354388037298125177941217926845803005587166270803697433886463469168814941555804311717400657004050157245e1110", }}; - T eg = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + T eg = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); unsigned max_err = 0; for(unsigned k = 0; k < data.size(); k++) diff --git a/test/test_sqrt.cpp b/test/test_sqrt.cpp index 57b84206..c59be223 100644 --- a/test/test_sqrt.cpp +++ b/test/test_sqrt.cpp @@ -152,7 +152,7 @@ void test() "17.7245385090551602729816748334114518279754945612238712821380778985291128459103218137495065673854466541622682362428257066623615286572442260252509370960278706846203769865310512284992517302895082622893209537926796280017463901535147972051670019018523401858544697449491264031392177552590621640541933250090639840761373347747515343366798978936585183640879545116516173876005906739343179133280985484624818490205465485219561325156164746751504273876105610799612710721006037204448367236529661370809432349883166842421384570960912042042778577806869476657000521830568512541339663694465418151071669388332194292935706226886522442054214994804992075648639887483850593064021821402928581123306497894520362114907896228738940324597819851313487126651250629326004465638210967502681249693059542046156076195221739152507020779275809905433290066222306761446966124818874306997883520506146444385418530797357425717918563595974995995226384924220388910396640644729397284134504300214056423343303926175613417633632001703765416347632066927654181283576249032690450848532013419243598973087119379948293873011126256165881888478597787596376136", }}; - T pi = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913152"; + T pi = static_cast("3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913152"); unsigned max_err = 0; for(unsigned k = 0; k < data.size(); k++) diff --git a/test/test_tanh.cpp b/test/test_tanh.cpp index a76fbe48..623585ec 100644 --- a/test/test_tanh.cpp +++ b/test/test_tanh.cpp @@ -102,7 +102,7 @@ void test() "1.", }}; - T eg = "5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"; + T eg = static_cast("5.77215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291746749514631447249807082480960504014486542836224173997644923536253500333742937337737673942792595258247094916008735203948165670853233151776611528621199501507984793745085705740029921354786146694029604325421519e-1"); unsigned max_err = 0; for(unsigned k = 0; k < data.size(); k++)