如何存储极大数字? [英] How to store extremely large numbers?

查看:176
本文介绍了如何存储极大数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个factorial程序,需要保存真正巨大的整数,可以是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.

这篇关于如何存储极大数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆