2014-11-14 57 views
0

为什么Python能够存储任意长度的长整数作为Java,C只能提供64位? 如果在Java中有这样的方法,请显示它。long-type in Python vs Java&C

+1

['BigInteger'](https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html)具有任意精度。 – August 2014-11-14 21:51:12

+0

你可能想读这个 - http://programmers.stackexchange.com/questions/128589/how-to-handle-large-numbers – ha9u63ar 2014-11-14 21:52:31

回答

2

Java中有BigInteger类。

看到这个python帮助文件。

Plain integers (also just called integers) are implemented using long in C, 
which gives them at least 32 bits of precision 
(sys.maxint is always set to the maximum plain integer value for the current platform, 
the minimum value is -sys.maxint - 1). 
Long integers have unlimited precision. 

基本上是一样的。在Java中,你可以使用。

  • 字节 - 8位
  • 短 - 16位
  • INT - 32位
  • 长 - 64位
  • 的BigInteger

在蟒它自动改变由于其类型为弱分类,请参阅下面的python代码

>>> a = 1000 
>>> type(a) 
<type 'int'> 
>>> a = 1000000000000000000000000000000000000000000000000000000000000000 
>>> type(a) 
<type 'long'> 

在java中,你必须自己改变变量的类型。

0

Python存储无限制的长整数,只要有可用的地址空间,就可以存储大量数据。

至于Java中,使用的BigInteger类