java - Python 与 Java 和 C 中的长类型

标签 java python long-integer primitive

为什么 Python 能够存储任意长度的长整数,而 Java 和 C 只提供 64 位? 如果 Java 有办法做到这一点,请展示。

最佳答案

BigInteger Java 中的类。

请参阅此 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 位
  • 大整数

在 python 中,由于弱类型,它会自动更改其类型,请参见下面的 python 代码

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

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

关于java - Python 与 Java 和 C 中的长类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26939410/

相关文章:

java - 如何在 Java 中将字符串的二进制表示形式转换为字节?

Python使用卡尔曼滤波器来改进模拟但结果更差

c++ - OS X 上的 printf 和 %llu 对比 %lu

java - 如何将switch语句中的条件返回到while?

java - 如何将 Shell 脚本添加为 Java 项目的一部分

java - 如何为单页 AngularJS 应用程序实现基本的 Spring 安全性( session 管理)

python - Scrapy - 获取 Javascript 变量的值

python - 如何在打开顶层时删除登录窗口?

php - SQL执行时间太长

scala - 专门集合中的 AnyVal 元素是否需要装箱?