Java:与<;和<;=用于9223372036854775807L的长整数
当我在JVM中运行以下代码时,我无法理解它为什么会这样。 根据我的理解,Java:与<;和<;=用于9223372036854775807L的长整数,java,precision,Java,Precision,当我在JVM中运行以下代码时,我无法理解它为什么会这样。 根据我的理解,
操作员应该一直工作到x-1
public class LongQuestion {
public static void main(String[] args) {
if(9223372036854775807L < Math.pow(2,63)) {
System.out.println("True"); // DOES NOT GET PRINTED
}
if(9223372036854775807L <= Math.pow(2,63) - 1 ) {
System.out.println("Also True"); // THIS GETS PRINTED
}
}
}
公共类长问题{
公共静态void main(字符串[]args){
如果(9223372036854775807L<数学功率(2,63)){
System.out.println(“True”);//无法打印
}
如果(9223372036854775807LMath.pow
被声明为
public static double pow(double a, double b)
因此,我们要处理的是双精度。Math.pow(2,63)
是“2.0d^63.0d
”(功率,而不是eor)。由于double
总共是64位,在最高有效位以下更改60个奇数位的值不会改变值。因此Math.pow(2,63)==Math.pow(2,63)-1
,也就是(双精度)9223372036854775807L
使隐式转换在第一个if
中隐式
if((double)9223372036854775807L < Math.pow(2.0d,63.0d)) {
System.out.println("True"); // DOES NOT GET PRINTED
}
if((双精度)9223372036854775807L
Math.pow的左侧和右侧都声明为
public static double pow(double a, double b)
因此,我们要处理的是双精度。Math.pow(2,63)
是“2.0d^63.0d
”(功率,而不是eor)。由于double
总共是64位,在最高有效位以下更改60个奇数位的值不会改变值。因此Math.pow(2,63)==Math.pow(2,63)-1
,也就是(双精度)9223372036854775807L
使隐式转换在第一个if
中隐式
if((double)9223372036854775807L < Math.pow(2.0d,63.0d)) {
System.out.println("True"); // DOES NOT GET PRINTED
}
if((双精度)9223372036854775807L
的左侧和右侧以下代码将帮助您理解它:
public class Main {
public static void main(String[] args) {
System.out.println("Long.MAX_VALUE is " + Long.MAX_VALUE);
System.out.println("Math.pow(2, 63) is " + Math.pow(2, 63));
System.out.println("Math.pow(2, 63) - 1 is " + (Math.pow(2, 63) - 1));
System.out.println("(long)Math.pow(2, 63) is " + (long) Math.pow(2, 63));
System.out.println("(long)(Math.pow(2, 63) - 1) is " + (long) (Math.pow(2, 63) - 1));
if (9223372036854775807L < Math.pow(2, 63)) {
System.out.println("9223372036854775807L < Math.pow(2, 63)");
}
if (9223372036854775807L <= Math.pow(2, 63)) {
System.out.println("9223372036854775807L <= Math.pow(2, 63)");
}
if (9223372036854775807L <= Math.pow(2, 63) - 1) {
System.out.println("9223372036854775807L <= Math.pow(2, 63) - 1");
}
if (9223372036854775807L < (long) Math.pow(2, 63)) {
System.out.println("9223372036854775807L < (long)Math.pow(2, 63)");
}
if (9223372036854775807L <= (long) Math.pow(2, 63)) {
System.out.println("9223372036854775807L <= (long)Math.pow(2, 63)");
}
if (9223372036854775807L <= (long) Math.pow(2, 63) - 1) {
System.out.println("9223372036854775807L <= (long)Math.pow(2, 63) - 1");
}
if (9223372036854775807L <= (long) (Math.pow(2, 63) - 1)) {
System.out.println("9223372036854775807L <= (long)(Math.pow(2, 63) - 1)");
}
}
}
公共类主{
公共静态void main(字符串[]args){
System.out.println(“Long.MAX_值为”+Long.MAX_值);
System.out.println(“Math.pow(2,63)是“+Math.pow(2,63));
System.out.println(“Math.pow(2,63)-1是”+(Math.pow(2,63)-1));
System.out.println(“(long)Math.pow(2,63)是”+(long)Math.pow(2,63));
System.out.println(((long)(Math.pow(2,63)-1)是“+(long)(Math.pow(2,63)-1));
如果(9223372036854775807L<数学功率(2,63)){
System.out.println(“9223372036854775807L 如果(9223372036854775807L以下代码将帮助您理解它:
public class Main {
public static void main(String[] args) {
System.out.println("Long.MAX_VALUE is " + Long.MAX_VALUE);
System.out.println("Math.pow(2, 63) is " + Math.pow(2, 63));
System.out.println("Math.pow(2, 63) - 1 is " + (Math.pow(2, 63) - 1));
System.out.println("(long)Math.pow(2, 63) is " + (long) Math.pow(2, 63));
System.out.println("(long)(Math.pow(2, 63) - 1) is " + (long) (Math.pow(2, 63) - 1));
if (9223372036854775807L < Math.pow(2, 63)) {
System.out.println("9223372036854775807L < Math.pow(2, 63)");
}
if (9223372036854775807L <= Math.pow(2, 63)) {
System.out.println("9223372036854775807L <= Math.pow(2, 63)");
}
if (9223372036854775807L <= Math.pow(2, 63) - 1) {
System.out.println("9223372036854775807L <= Math.pow(2, 63) - 1");
}
if (9223372036854775807L < (long) Math.pow(2, 63)) {
System.out.println("9223372036854775807L < (long)Math.pow(2, 63)");
}
if (9223372036854775807L <= (long) Math.pow(2, 63)) {
System.out.println("9223372036854775807L <= (long)Math.pow(2, 63)");
}
if (9223372036854775807L <= (long) Math.pow(2, 63) - 1) {
System.out.println("9223372036854775807L <= (long)Math.pow(2, 63) - 1");
}
if (9223372036854775807L <= (long) (Math.pow(2, 63) - 1)) {
System.out.println("9223372036854775807L <= (long)(Math.pow(2, 63) - 1)");
}
}
}
公共类主{
公共静态void main(字符串[]args){
System.out.println(“Long.MAX_值为”+Long.MAX_值);
System.out.println(“Math.pow(2,63)是“+Math.pow(2,63));
System.out.println(“Math.pow(2,63)-1是”+(Math.pow(2,63)-1));
System.out.println(“(long)Math.pow(2,63)是”+(long)Math.pow(2,63));
System.out.println(((long)(Math.pow(2,63)-1)是“+(long)(Math.pow(2,63)-1));
如果(9223372036854775807L<数学功率(2,63)){
System.out.println(“9223372036854775807L 如果(9223372036854775807L)你能详细说明一下吗?我无法理解这一点。“eor”?更常见的称为“xor”。为了澄清,64位数字9223372036854775807L
变成9.223372036854776E18
,因为64位double
只有53位精度。@Andreas xor(/,EOR,EXOR,⊻, ⩒, ⩛, ⊕, ↮, 和≢. (来源:Wikipedia!)EOR是6502和ARM汇编语言中使用的助记符,对我来说也可以。@TomHawtin tackline哇,旧的6502,现在可以恢复记忆了……不管怎样,大多数现代编程语言都使用xor
,包括Java,其中和都有xor(…)
方法。没有EOR(…)
Java运行时库中的方法。您能详细说明一下吗?我无法理解这一点。“eor”?更常见的称为“xor”。为了澄清,64位数字9223372036854775807L
变成9.223372036854776E18
,因为64位双精度
只有53位。@Andreas xor(或)提高采收率,⊻, ⩒, ⩛, ⊕, ↮, 和≢. (来源:Wikipedia!)EOR是6502和ARM汇编语言中使用的助记符,对我来说也可以。@TomHawtin tackline哇,旧的6502,现在可以恢复记忆了……不管怎样,大多数现代编程语言都使用xor
,包括Java,其中和都有xor(…)
方法。没有EOR(…)
Java运行时库中的方法。很抱歉,我无法理解它是如何回答这个问题的?谢谢,你能解释一下它为什么会这样吗?很抱歉,我无法理解它是如何回答这个问题的?谢谢,你能解释一下它为什么会这样吗?