2
我遇到了將代碼移動到服務器的問題。boost :: multiprecision從整型轉換爲cpp_dec_float編譯錯誤
問題的最小工作實例是下面的代碼(文件名mp2.cpp
):
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>
using namespace std;
using namespace boost::multiprecision;
int main() {
uint128_t a = 1;
uint128_t b = 2;
cpp_dec_float_50 fa = static_cast<cpp_dec_float_50>(a);
cpp_dec_float_50 fb = static_cast<cpp_dec_float_50>(b);
cout << fa/fb << endl;
return 0;
}
編譯和按預期運行,我開發機(克++ 4.6.3上在標準輸出寫0.5
,升壓1.55 ,32位CPU)。
對於相同的代碼,G ++失敗,此錯誤在服務器上編譯:
In file included from /usr/local/include/boost/multiprecision/number.hpp:22:0,
from /usr/local/include/boost/multiprecision/cpp_int.hpp:12,
from mp2.cpp:1:
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp: In instantiation of 'void boost::multiprecision::detail::generic_interconvert(To&, const From&, const mpl_::int_<1>&, const mpl_::int_<0>&) [with To = boost::multiprecision::backends::cpp_dec_float<50u>; From = boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>]':
/usr/local/include/boost/multiprecision/number.hpp:108:7: required from 'boost::multiprecision::number<Backend, ExpressionTemplates>::number(const boost::multiprecision::number<Other, ET>&, typename boost::enable_if_c<(! boost::multiprecision::detail::is_explicitly_convertible<Other, Backend>::value)>::type*) [with Other = boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>; boost::multiprecision::expression_template_option ET = (boost::multiprecision::expression_template_option)0u; Backend = boost::multiprecision::backends::cpp_dec_float<50u>; boost::multiprecision::expression_template_option ExpressionTemplates = (boost::multiprecision::expression_template_option)1u; typename boost::enable_if_c<(! boost::multiprecision::detail::is_explicitly_convertible<Other, Backend>::value)>::type = void]'
mp2.cpp:11:55: required from here
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:43:4: error: no matching function for call to 'eval_is_zero(boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>&)'
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:43:4: note: candidates are:
In file included from mp2.cpp:2:0:
/usr/local/include/boost/multiprecision/cpp_dec_float.hpp:2905:13: note: template<unsigned int Digits10, class ExponentType, class Allocator> bool boost::multiprecision::backends::eval_is_zero(const boost::multiprecision::backends::cpp_dec_float<Digits10, ExponentType, Allocator>&)
/usr/local/include/boost/multiprecision/cpp_dec_float.hpp:2905:13: note: template argument deduction/substitution failed:
In file included from /usr/local/include/boost/multiprecision/number.hpp:22:0,
from /usr/local/include/boost/multiprecision/cpp_int.hpp:12,
from mp2.cpp:1:
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:43:4: note: 'boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>' is not derived from 'const boost::multiprecision::backends::cpp_dec_float<Digits10, ExponentType, Allocator>'
In file included from /usr/local/include/boost/multiprecision/cpp_int.hpp:1787:0,
from mp2.cpp:1:
/usr/local/include/boost/multiprecision/cpp_int/misc.hpp:94:4: note: template<unsigned int MinBits1, unsigned int MaxBits1, boost::multiprecision::cpp_integer_type SignType1, boost::multiprecision::cpp_int_check_type Checked1, class Allocator1> typename boost::enable_if_c<(! boost::multiprecision::backends::is_trivial_cpp_int<boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value), bool>::type boost::multiprecision::backends::eval_is_zero(const boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>&)
/usr/local/include/boost/multiprecision/cpp_int/misc.hpp:94:4: note: template argument deduction/substitution failed:
/usr/local/include/boost/multiprecision/cpp_int/misc.hpp: In substitution of 'template<unsigned int MinBits1, unsigned int MaxBits1, boost::multiprecision::cpp_integer_type SignType1, boost::multiprecision::cpp_int_check_type Checked1, class Allocator1> typename boost::enable_if_c<(! boost::multiprecision::backends::is_trivial_cpp_int<boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value), bool>::type boost::multiprecision::backends::eval_is_zero(const boost::multiprecision::backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>&) [with unsigned int MinBits1 = 128u; unsigned int MaxBits1 = 128u; boost::multiprecision::cpp_integer_type SignType1 = (boost::multiprecision::cpp_integer_type)0u; boost::multiprecision::cpp_int_check_type Checked1 = (boost::multiprecision::cpp_int_check_type)0u; Allocator1 = void]':
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:43:4: required from 'void boost::multiprecision::detail::generic_interconvert(To&, const From&, const mpl_::int_<1>&, const mpl_::int_<0>&) [with To = boost::multiprecision::backends::cpp_dec_float<50u>; From = boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>]'
/usr/local/include/boost/multiprecision/number.hpp:108:7: required from 'boost::multiprecision::number<Backend, ExpressionTemplates>::number(const boost::multiprecision::number<Other, ET>&, typename boost::enable_if_c<(! boost::multiprecision::detail::is_explicitly_convertible<Other, Backend>::value)>::type*) [with Other = boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>; boost::multiprecision::expression_template_option ET = (boost::multiprecision::expression_template_option)0u; Backend = boost::multiprecision::backends::cpp_dec_float<50u>; boost::multiprecision::expression_template_option ExpressionTemplates = (boost::multiprecision::expression_template_option)1u; typename boost::enable_if_c<(! boost::multiprecision::detail::is_explicitly_convertible<Other, Backend>::value)>::type = void]'
mp2.cpp:11:55: required from here
/usr/local/include/boost/multiprecision/cpp_int/misc.hpp:94:4: error: no type named 'type' in 'struct boost::enable_if_c<false, bool>'
In file included from /usr/local/include/boost/multiprecision/cpp_int.hpp:18:0,
from mp2.cpp:1:
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp: In instantiation of 'void boost::multiprecision::detail::generic_interconvert(To&, const From&, const mpl_::int_<1>&, const mpl_::int_<0>&) [with To = boost::multiprecision::backends::cpp_dec_float<50u>; From = boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>]':
/usr/local/include/boost/multiprecision/number.hpp:108:7: required from 'boost::multiprecision::number<Backend, ExpressionTemplates>::number(const boost::multiprecision::number<Other, ET>&, typename boost::enable_if_c<(! boost::multiprecision::detail::is_explicitly_convertible<Other, Backend>::value)>::type*) [with Other = boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>; boost::multiprecision::expression_template_option ET = (boost::multiprecision::expression_template_option)0u; Backend = boost::multiprecision::backends::cpp_dec_float<50u>; boost::multiprecision::expression_template_option ExpressionTemplates = (boost::multiprecision::expression_template_option)1u; typename boost::enable_if_c<(! boost::multiprecision::detail::is_explicitly_convertible<Other, Backend>::value)>::type = void]'
mp2.cpp:11:55: required from here
/usr/local/include/boost/multiprecision/rational_adaptor.hpp:252:13: note: template<class IntBackend> bool boost::multiprecision::backends::eval_is_zero(const boost::multiprecision::backends::rational_adaptor<IntBackend>&)
/usr/local/include/boost/multiprecision/rational_adaptor.hpp:252:13: note: template argument deduction/substitution failed:
In file included from /usr/local/include/boost/multiprecision/number.hpp:22:0,
from /usr/local/include/boost/multiprecision/cpp_int.hpp:12,
from mp2.cpp:1:
/usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:43:4: note: 'boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0u, (boost::multiprecision::cpp_int_check_type)0u, void>' is not derived from 'const boost::multiprecision::backends::rational_adaptor<IntBackend>'
服務器運行克++ 4.7.2和升壓1.56,在64位CPU。我已經安裝了相同的g ++和boost版本來查看這是否是問題,但事實並非如此。
從實驗來源看,每當我嘗試將整數轉換爲浮點數時,就會出現問題。但是,正如in the documentation所提到的,這是正確的方法。
有人知道問題是怎麼回事,以及如何解決它?