问题描述
如何获得比Long.MAX_VALUE大的整数?
How can I get a long number bigger than Long.MAX_VALUE?
我希望此方法返回true
:
boolean isBiggerThanMaxLong(long val) {
return (val > Long.MAX_VALUE);
}
推荐答案
该方法无法返回true
.这就是Long.MAX_VALUE
的要点.如果它的名字是……假,那将是真的令人困惑.然后,应将其称为Long.SOME_FAIRLY_LARGE_VALUE
,并且合理地使用零个字.只需使用 Android的isUserAGoat
,否则您可以滚动自己的函数,该函数始终返回false
.
That method can't return true
. That's the point of Long.MAX_VALUE
. It would be really confusing if its name were... false. Then it should be just called Long.SOME_FAIRLY_LARGE_VALUE
and have literally zero reasonable uses. Just use Android's isUserAGoat
, or you may roll your own function that always returns false
.
请注意,内存中的long
占用固定数量的字节. 来自Oracle :
Note that a long
in memory takes a fixed number of bytes. From Oracle:
您可能会从基础计算机科学或离散数学中学到的,因为它是64位,所以很长的时间内可能有2 ^ 64个值.从离散数学,数论或常识中可以知道,如果只有有限的多种可能性,则其中之一必须是最大的.那将是Long.MAX_VALUE
.因此,您在问类似是否有一个大于0且小于1的整数?"的问题.数学上没有意义.
As you may know from basic computer science or discrete math, there are 2^64 possible values for a long, since it is 64 bits. And as you know from discrete math or number theory or common sense, if there's only finitely many possibilities, one of them has to be the largest. That would be Long.MAX_VALUE
. So you are asking something similar to "is there an integer that's >0 and < 1?" Mathematically nonsensical.
如果您实际需要此功能,请使用BigInteger
类.
If you actually need this for something for real then use BigInteger
class.
这篇关于比Long.MAX_VALUE大很多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!