大数字库在c ++ [英] Big numbers library in c++
问题描述
我在做一个需要真正大数字的项目,最多100位数。我已经读过,java支持大整数( java.Math.BigInteger
),我想知道是否有类似的C ++。所以,这里是我的问题:是否有一个标准或非标准的c ++库实现大整数?
I'm doing a project which requires really big numbers, up to 100 digits. I have read that java supports big integers (java.Math.BigInteger
), and I want to know if there is something like that in C++. So, here is my question: Is there a standard or non-standard c++ library which implements big integers?
注意标准实现的大整数,我想要一个简单非标准。提前感谢。
Note: If there is no standard implementation for big integers, I would like a simple non-standard. Thanks in advance.
推荐答案
GNU多精度算术库会执行您想要的 http://gmplib.org/
The GNU Multiple Precision Arithmetic Library does what you want http://gmplib.org/
Gnu MP是一个C库,但它有一个 C++类接口,如果您只对大整数感兴趣,可以只处理 mpz_class
。查看我从页面 C ++接口常规中取得的示例
Gnu MP is a C library but it has a C++ class Interface and if you are interested only in big integers, you may just deal with mpz_class
. Look at the sample below which I took from the page C++ Interface General
int main (void)
{
mpz_class a, b, c;
a = 1234;
b = "-5678";
c = a+b;
cout << "sum is " << c << "\n";
cout << "absolute value is " << abs(c) << "\n";
return 0;
}
这篇关于大数字库在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!