Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4306049

java.math: inaccurate values of cosine for numbers close to pi

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Won't Fix
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: vm-legacy
    • Labels:

      Description

      cu is getting inaccurate values of cosine for numbers close to pi
      This code under Solaris produces to correct output for Math.cos and Math.sin
      in direct function calls or in a loop where call is placed to these funcitons.

      On NT, after commenting out the loop section of the code, values of the return result from the Math.cos function is wrong after 5th position.

      Solaris resluts:
      for "wr" variabe in the code is consistent: 6.123233995736766E-17

      NT results:
      test1: without loop: C:\Test>java Ctest2
      VICTIM CODE
      l: 2 le: 4 le1: 2 pile1: 1.5707963267948966
       wr: 6.123233995736766E-17 wi: -1.0

      test2: with loop
      C:\Test>java Ctest2
      VICTIM CODE
      l: 2 le: 4 le1: 2 pile1: 1.5707963267948966
       wr: 6.123031769111886E-17 wi: -1.0
      CRIMINAL CODE
      l: 1 le: 2 le1: 1 pile1: 3.141592653589793
       wr: -1.0 wi: -1.2246063538223773E-16
      l: 2 le: 4 le1: 2 pile1: 1.5707963267948966
       wr: 6.123031769111886E-17 wi: -1.0



      This is a simple test case from customer:
      import java.math.*;
      import java.io.*;
      import java.text.*;

      /****************************************************************************************
      * Test code to demonstrate a serious bug, possibly in Java compiler, for
      * jdk1.2.2 running in Windows NT 4 environment. Hardware context is Dell Optiplex
      * GX1 system, PII @ 450 MHz. Service Pack 5 has been applied to NT 4.
      *
      * W. Leue, GE CRD 1/19/00 518-387-7210, ###@###.###
      *****************************************************************************************/

      public class Ctest {

      public static void main(String[] args) {
      double pile1;
      double wr;
      int l;
      int le;
      int le1;
      int m;
      m = 8;
      double ur;
      double ui;
      double wi;

      System.out.println("VICTIM CODE");
      l = 2;
      le = 1<<l; /* gap between butterflies */
      le1 = le>>1; /* gap between butterfly input points */
      ur=1.0; /* real twiddle for W0 */
      ui=0.0; /* imaginary twiddle for W0 */
      pile1 = (Math.PI/(double)le1); /* twiddle angle increment */
      wr = Math.cos(pile1); /* real twiddle angle increment */
      wi = -Math.sin(pile1); /* imaginary twiddle angle increment */
         System.out.println("l: " + l + " le: " + le + " le1: " + le1 + " pile1: " + pile1);
          System.out.println(" wr: " + wr + " wi: " + wi);
          // uncomment the code below to demonstrate the bug!
          // the value of 'wr' in the ABOVE code changes depending on whether
          // the loop code BELOW is commented out or not! YIKES!!!!!!
          
          //System.out.println("CRIMINAL CODE");
          //for(l=1; l<=m; l++) { /* for each stage, l */
      // le = 1<<l; /* gap between butterflies */
      // le1 = le>>1; /* gap between butterfly input points */
      // ur=1.0; /* real twiddle for W0 */
      // ui=0.0; /* imaginary twiddle for W0 */
      // pile1 = (Math.PI/(double)le1); /* twiddle angle increment */
      // wr = Math.cos(pile1); /* real twiddle angle increment */
      // wi = -Math.sin(pile1); /* imaginary twiddle angle increment */
      // System.out.println("l: " + l + " le: " + le + " le1: " + le1 + " pile1: " +
      pile1);
          // System.out.println(" wr: " + wr + " wi: " + wi);
      //}

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              gbrachasunw Gilad Bracha (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: