C ++ Boost多精度cpp_int [英] C++ Boost multiprecision cpp_int

查看:397
本文介绍了C ++ Boost多精度cpp_int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试获取大量日志.我该怎么办?我不能使用gmp.hpp,因为它说Cannot open include file: 'gmp.h': No such file or directory

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

以下代码

#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;
}

给我错误:

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 ==========

推荐答案

log采用实数,而不是整数.

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";
}

查看 在Coliru上直播

See it Live on Coliru

这篇关于C ++ Boost多精度cpp_int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆