我最近使用的是boost :: multiprecision。我的代码是这样的:
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace bm = boost::multiprecision;
int main(void) {
bm::int512_t a = 12;
bm::cpp_dec_float_100 f = a;
std::cout << f * 3.14 << std::endl;
return 0;
}
它没有编译。错误显示:
b.cpp: In function ‘int main()’:
b.cpp:9:28: error: conversion from ‘boost::multiprecision::int512_t {aka boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<512u, 512u, (boost::multiprecision::cpp_integer_type)1u, (boost::multiprecision::cpp_int_check_type)0u, void> >}’ to non-scalar type ‘boost::multiprecision::cpp_dec_float_100 {aka boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u> >}’ requested
bm::cpp_dec_float_100 f = a;
^
How can I convert it correctly? Thanks a lot!
答案 0 :(得分:0)
我自己对这些东西不熟悉,但我一直在使用boost multi_precision, 我想下面应该有效
bm :: cpp_dec_float_100 f = bm :: cpp_dec_float_100 f(a);