C++ Boost multiprecision cpp_int

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

I try to get log of a big number. How should I do it? I cannot use gmp.hpp because it says Cannot open include file: 'gmp.h': No such file or directory

The following code

#include <iostream> #include <boost/multiprecision/cpp_int.hpp>  #define rsa100 "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"   using namespace std; using namespace boost::multiprecision;  int main(){     cpp_int n(rsa100);     cout << boost::multiprecision::log(n);     return 0; } 

Give me error:

1>------ Build started: Project: rsa, Configuration: Debug x64 ------ 1>  Source.cpp 1>Source.cpp(12): error C2893: Failed to specialize function template 'enable_if_c<boost::multiprecision::number_category<Num>::value==1,boost::multiprecision::detail::expression<boost::multiprecision::detail::function,boost::multiprecision::detail::log_funct<Backend>,boost::multiprecision::number<B,et_on>,void,void>>::type boost::multiprecision::log(const boost::multiprecision::number<B,et_on> &)' 1>          With the following template arguments: 1>          'Backend=boost::multiprecision::backends::cpp_int_backend<0,0,signed_magnitude,unchecked,std::allocator<boost::multiprecision::limb_type>>' 1>Source.cpp(12): error C2784: 'enable_if_c<boost::multiprecision::number_category<boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4>>::value==number_kind_floating_point,boost::multiprecision::detail::expression<boost::multiprecision::detail::function,boost::multiprecision::detail::log_funct<detail::backend_type<boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4>>::type>,boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4>,void,void>>::type boost::multiprecision::log(const boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4> &)' : could not deduce template argument for 'const boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4> &' from 'boost::multiprecision::cpp_int' 1>          C:\boost_1_55_0\boost/multiprecision/detail/default_ops.hpp(1998) : see declaration of 'boost::multiprecision::log' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

回答1:

log takes a real number, not integer.

#include <iostream> #include <iomanip> #include <boost/multiprecision/cpp_dec_float.hpp>  #define rsa100 "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"  using namespace std; using namespace boost::multiprecision;  int main(){     cpp_dec_float_100 n(rsa100);      auto log_n     = log(n);     auto exp_log_n = exp(log_n);      cout << std::fixed << log_n     << "\n";     cout << std::fixed << exp_log_n << "\n"; } 

See it Live on Coliru



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!