2至1000的幂 [英] 2 to the power of 1000

查看:62
本文介绍了2至1000的幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,计算机不会显示大量的所有数字.
例如,由于以下原因,它显示"1.07150860718627E + 301":

As you know computer doesn''t show all of digits of a large number.
For example it show "1.07150860718627E+301" as result of:

Math.Pow(2, 1000);


如何获得普通模式结果?


How can I have got normal mode result?

推荐答案

问题是正在计算的类型为double,只有64位. double是浮点"表示,将数字存储为数字的最高有效53位和10位标度".这就是为什么只能使用大约15个十进制数字表示的原因. 如果确实需要一个非常大的整数的所有精度,请使用BigInteger数据类型.
The problem is that is being computed in type double, which is only 64-bits. double is a "floating-point" representation and stores numbers as the most significant 53 bits of the number and a 10 bit "scale". This is why only about 15 decimal digits of prcision are possible.
If you really need all of the precision for a very large integer, use the BigInteger data type.


根本问题是浮点类型设计用于近似计算.原则上这是不可避免的.您是否知道一般情况下,单个实数包含无限量的信息?因此,原则上没有办法在没有近似的情况下呈现这种值.

现在,您的案例处理整数值.对于整数值,存在一个无限制大小的奇妙类型:System.Numerics.BigInteger:
http://msdn.microsoft.com/en-us/library/system.numerics. biginteger.aspx [ ^ ].

无限"实际上是指受系统提供给您的应用程序的所有可用内存的限制".这很多……



顺便说一下,使用v.4.0时可以使用此类型.对你有好处.那些没有支持此版本开发工具的人可以从Mono中获取源代码.

祝你好运,
—SA
The root problem is that the floating-point types are designed for approximate calculations. This is unavoidable in principle. Did you know that in general case, the single real number contains the infinite volume of information? So, there is no a way in principle to present such value without approximation.

Now, your case deals with integer values. For integer values, there is a wonderful type with unlimited size: System.Numerics.BigInteger:
http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx[^].

"Unlimited" actually means "limited by all available memory provided by the system to your application". And this is, well, a lot…



By the way, this type is available to you as you use v.4.0. Good for you. Those who does not have development tools supporting this version could pick up the source code from Mono.

Good luck,
—SA


这篇关于2至1000的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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