How to store extremely large numbers?(如何存储极大的数字?)
问题描述
例如,我有一个阶乘程序,它需要保存非常大的整数,其长度可能超过 50 位.C++ 中的绝对最大原始数据类型是 unsigned long long int,最大值 18446744073709551615 只有 20 位长.这是 C++ 限制的链接:http://www.cplusplus.com/reference/climits/
For example I have a factorial program that needs to save really huge integers that can be 50+ digits long. The absolute maximum primitive data type in C++ is unsigned long long int with a maximum value 18446744073709551615 which is only 20 digits long. Here's the link to the limits of C++: http://www.cplusplus.com/reference/climits/
如何将大于某个变量的数字存储在某种变量中?
How do I store numbers that are larger than that in a variable of some sort?
推荐答案
如果你已经有了 boost 依赖(现在很多人都有),你可以使用 boost 多精度库.事实上,它已经有一个 阶乘程序,可以支持高达 128 位的输出,但进一步扩展它非常简单.
If you already have a boost dependency (which many people these days do), you can use the boost multi-precision library. In fact, it already has an example of a factorial program that can support output up to 128 bits, though extending it further is pretty trivial.
这篇关于如何存储极大的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何存储极大的数字?
基础教程推荐
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
