问题描述
我尝试使用
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.
推荐答案
您不能为此使用任何内置整数类型。您需要一个多精度整数或 bignum库。对于C ++,我会先尝试,但是请注意,Boost带来的麻烦要比其值得多得多,尤其是如果您使用的模块具有任何共享库(aka 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.
这篇关于极大的整数是什么类型的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!