本文介绍了C ++对于非常大的整数,什么变量类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试使用

long long int

但它不工作的数字像3141592653589793238462643383279502884197169399375,我需要这个高达10 ^ 80。任何想法?让我知道。非常感谢。

But it wont work for numbers like 3141592653589793238462643383279502884197169399375, I need this up to 10 ^ 80. Any idea? Let me know. Thanks alot.

推荐答案

您不能使用任何内置的整数类型。你需要一个多精度整数akabignum库。对于C ++,我首先尝试,但是请注意,Boost可能会比它更有价值,特别是如果你使用的模块有任何共享库(也称为DLL)组件。另一个明显的选择是。它只有一个C接口,但它是良好的维护,可靠,快速,非常受欢迎(事实上,看来Boost.MP是只是一个C ++包装器!)

You can't use any built-in integer type for this. You need a "multiple precision integer" aka "bignum" library. For C++, I would try Boost.Multiprecision first, but be aware that Boost can be considerably more trouble than it is worth, particularly if the module you're using has any shared library (aka DLL) component. The other obvious choice is GNU MP. It only has a C interface, but it is well-maintained, reliable, fast, and very popular (in fact, it appears that Boost.MP is "just" a C++ wrapper for it!)

警告:您可能需要一个bignum库,因为您试图实现使用大量数字的加密原语,例如。 不要这样做 。通用bignum库对于加密使用是不安全的,即使它们是,仍然会有几十个微妙的错误,你可以做,将破坏你的安全。使用经过良好测试的加密库;对于C ++我推荐。

WARNING: You might want a bignum library because you are trying to implement one of the cryptographic primitives that uses huge numbers, like RSA. Do not do this. The generic bignum libraries are not safe for cryptographic use, and even if they were, there would still be dozens of subtle mistakes you can make that would ruin your security. Use a well-tested cryptography library instead; for C++ I recommend Botan.

这篇关于C ++对于非常大的整数,什么变量类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 22:23