M
mmquan
public class ex4{
public static void main(String[] args){
double eps[] = new double[5];
double a12, a34;
eps[1] = Double.longBitsToDouble(0x4037CB020C49BA5EL);
eps[2] = Double.longBitsToDouble(0x403C1E76C8B43958L);
eps[3] = Double.longBitsToDouble(0xBFF943D46B26BF87L);
eps[4] = Double.longBitsToDouble(0xBFF943D46B26BF87L);
System.out.println(Long.toHexString(Double.doubleToLongBits(eps[1]*eps[2]-eps[3]*eps[4])));
a12 = eps[1]*eps[2];
a34 = eps[3]*eps[4];
System.out.println(Long.toHexString(Double.doubleToLongBits(a12-a34)));
}
}
I wrote a similar program in Fortran, but I get different results of
the first output. I know the second output should be the same because
the two operands of the subtraction are rounded to 64 bits. But the
first one in Fortran is an intermediate results with 80 bits but what
about Java, did Java also use the same 80 bits as the subtraction
operands?
this is the output of Java:
4084d455e2cff391
4084d455e2cff391
this is the output of Fortran:
4084D455E2CFF392
4084D455E2CFF391
Thanks for your responding!
public static void main(String[] args){
double eps[] = new double[5];
double a12, a34;
eps[1] = Double.longBitsToDouble(0x4037CB020C49BA5EL);
eps[2] = Double.longBitsToDouble(0x403C1E76C8B43958L);
eps[3] = Double.longBitsToDouble(0xBFF943D46B26BF87L);
eps[4] = Double.longBitsToDouble(0xBFF943D46B26BF87L);
System.out.println(Long.toHexString(Double.doubleToLongBits(eps[1]*eps[2]-eps[3]*eps[4])));
a12 = eps[1]*eps[2];
a34 = eps[3]*eps[4];
System.out.println(Long.toHexString(Double.doubleToLongBits(a12-a34)));
}
}
I wrote a similar program in Fortran, but I get different results of
the first output. I know the second output should be the same because
the two operands of the subtraction are rounded to 64 bits. But the
first one in Fortran is an intermediate results with 80 bits but what
about Java, did Java also use the same 80 bits as the subtraction
operands?
this is the output of Java:
4084d455e2cff391
4084d455e2cff391
this is the output of Fortran:
4084D455E2CFF392
4084D455E2CFF391
Thanks for your responding!