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 多精度库.其实它已经有一个factorial program 可以支持高达 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.
这篇关于如何存储非常大的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何存储非常大的数字?
基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
