C++ 求高精度算法
用string做输入输出结果的类型
能处理负数,小数(如-12.44)
可以处理 加 减 乘 除 取余 五种运算
代码不要太阴间
GNU Multiple Precision Arithmetic Library
Boost.Multiprecision
等等
【以下回答由 GPT 生成】
回答:
对于您的需求,C++标准库中并没有提供直接支持高精度计算的模块。但是,可以使用第三方库来实现高精度算法。其中比较常用的库有GMP(GNU Multiple Precision Arithmetic Library)和BigInt(Boost C++ Libraries)。
下面以BigInt库为例,提供一种实现高精度算法的代码示例:
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
cpp_int a("123456789123456789");
cpp_int b("-987654321987654321");
cpp_int c = a + b;
cpp_int d = a - b;
cpp_int e = a * b;
cpp_int f = a / b;
cpp_int g = a % b;
std::string result_c = c.str();
std::string result_d = d.str();
std::string result_e = e.str();
std::string result_f = f.str();
std::string result_g = g.str();
这样,您就可以用BigInt库来实现高精度算法,满足您的需求。希望对您有帮助!如果您对其他细节有更多要求,请提供更具体的信息,以便我能为您提供更精确的回答。
【相关推荐】