JDK-4294075 : java.lang.StrictMath.cos/sin results are not within 1ulp on Win98
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1999-11-23
  • Updated: 1999-11-25
  • Resolved: 1999-11-25
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
The javadoc for java.lang.Math.sin/cos says:

------
      A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.
------

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.999999999293945E-6
cos(x2) = -6.049014748177263E-16
cos(x1) = 9.999999999293945E-6
cos(x2) = -6.049014748177263E-16
x3 = -6.283185307179586
sin(x3) = 2.4492935982947064E-16
sin(x3) = 2.4492935982947064E-16

win 98 run:
-------
x1 = 1.5707863267948972
x2 = 1.5707963267948972
cos(x1) = 9.999999999293941E-6
cos(x2) = -6.049034970839751E-16
cos(x1) = 9.999999999293945E-6
cos(x2) = -6.049014748177263E-16
x3 = -6.283185307179586
sin(x3) = 2.4492127076447545E-16
sin(x3) = 2.4492935982947064E-16

 

Comments
EVALUATION this is a HotSot bug. It's not reproducible in the classic VM.
11-06-2004