Duplicate :


Relates :


Relates :


Relates :

The javadoc for java.lang.Math.sin/cos says:  A result must be within 1 ulp of the correctly rounded result. Results must be semimonotonic.  The Math.cos(x) is not within 1 ulp from StrictMath.cos(x) on Win98 where x = Double.longBitsToDouble(0x3ff921f0d7e968a9L) or x = Double.longBitsToDouble(0xbcc5cb3b399d747fL) The Math.sin(x) is not within 1 ulp from StrictMath.sin(x) on Win98 where x = Double.longBitsToDouble(0xc01921fb54442d18L) Below you can see the test run of the example on Solaris and on win98. The Solaris results are correct and are the same for Math and StrictMath. The win98 results differ between Math and StrictMath. The StrictMath result on win98 and on Solaris are the same thing, which is the correct result. However, the win98 Math sin/cos return values that are not winthin 1 ulp (in binary) from the correct result. Inside the test example in comments you will find the output of the JCK test run, which shows results in hexadecimal notation and it is clear that the "Expected" and "Got" results differ more than 1 ulp. public class Test { public static void main(String [] args) throws Exception { //this is the output from JCK test: //cos failed for 3ff921f0d7e968a9 Expected 3ee4f8b588dd0ce3 +/ 1 ulp Got: 3ee4f8b588dd0ce1 //cos failed for 3ff921fb54442d1b Expected bcc5cb3b399d747f +/ 1 ulp Got: bcc5cb4000000000 //sin failed for c01921fb54442d18 Expected 3cb1a62633145c07 +/ 1 ulp Got: 3cb1a60000000000 System.out.println("x1 = " + Double.longBitsToDouble(0x3ff921f0d7e968a9L)); System.out.println("x2 = " + Double.longBitsToDouble(0x3ff921fb54442d1bL)); System.out.println("cos(x1) = " + Math.cos(Double.longBitsToDouble(0x3ff921f0d7e968a9L))); System.out.println("cos(x2) = " + Math.cos(Double.longBitsToDouble(0x3ff921fb54442d1bL))); System.out.println("cos(x1) = " + StrictMath.cos(Double.longBitsToDouble(0x3ff921f0d7e968a9L))); System.out.println("cos(x2) = " + StrictMath.cos(Double.longBitsToDouble(0x3ff921fb54442d1bL))); System.out.println("x3 = " + Double.longBitsToDouble(0xc01921fb54442d18L)); System.out.println("sin(x3) = " + Math.sin(Double.longBitsToDouble(0xc01921fb54442d18L))); System.out.println("sin(x3) = " + StrictMath.sin(Double.longBitsToDouble(0xc01921fb54442d18L))); } } solaris run:  x1 = 1.5707863267948972 x2 = 1.5707963267948972 cos(x1) = 9.999999999293945E6 cos(x2) = 6.049014748177263E16 cos(x1) = 9.999999999293945E6 cos(x2) = 6.049014748177263E16 x3 = 6.283185307179586 sin(x3) = 2.4492935982947064E16 sin(x3) = 2.4492935982947064E16 win 98 run:  x1 = 1.5707863267948972 x2 = 1.5707963267948972 cos(x1) = 9.999999999293941E6 cos(x2) = 6.049034970839751E16 cos(x1) = 9.999999999293945E6 cos(x2) = 6.049014748177263E16 x3 = 6.283185307179586 sin(x3) = 2.4492127076447545E16 sin(x3) = 2.4492935982947064E16
