Long vs BigInteger [英] Long vs BigInteger

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

问题描述

我知道 java.lang.Long java.math.BigInteger 都可以包含非常大的自然数。

I understand that both java.lang.Long and java.math.BigIntegercan hold very large natural numbers.

我也知道Long的最大值,但BigInteger的最大值是多少?

I also know Long's max value, but what is the max value for BigInteger?

除了容量,BigInteger在使用仍然在Long范围内的一般大整数时会表现得更好吗?

And aside from capacity, would BigInteger ever perform better when working with generally large integers that still fall in Long's range?

唯一的考虑因素是:我的价值对于Long来说太大了吗?

Is the only consideration: is my value too large for Long?

推荐答案

BigInteger能够持有比Long更大的数字。 BigInteger似乎能够持有(2 ^ 32)^ Integer.MAX_VALUE,虽然这取决于实现(并且,即使在实现中真正无限制,最终也会有物理资源限制)参见此处的说明

BigInteger is capable of holding far bigger numbers than Long. BigInteger seems capable of holding (2 ^ 32) ^ Integer.MAX_VALUE, though that depends on the implementation (and, even if truly unbounded in the implementation, there will eventually be a physical resource limit) See explanation here.

为[-9,223,372,036,854,775,808,+9,223,372,036,854,775,807]。

The range of Long is [-9,223,372,036,854,775,808, +9,223,372,036,854,775,807].

龙将除BigInteger所以这真的取决于什么更好的表现你的价值观的大小。如果它们都属于Long的最大值,那么使用Long是没有意义的。如果任何值大于Long max值,你几乎必须使用BigInteger。

Long will perform better than BigInteger so it really depends on what the size of your values will be. If they would all fall under Long's max value, it makes no sense not to use Long. If any would be bigger than the Long max value, you pretty much have to use BigInteger.

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

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