6 Replies Latest reply on Jan 6, 2009 12:43 AM by nberger

    A bug about cosine function?

    traits
      cosine bug

      Hi All,

      I found that the result of cos(1611.625) is incorrect. It's 1.0 on GPU, whereas it's -0.9893 on CPU.

      My box is HD4870, AMD Stream SDK 1.3 and Ubuntu amd64.

      Is it a bug?

      Thanks

      Traits

        • A bug about cosine function?
          gaurav.garg

          Try sending 1611.625 as a constant parameter to kernel so that its value is not determined at compile time. It will help us know if its an issue with compiler or hadware floating point accuracy.

            • A bug about cosine function?
              traits

              The test code:

               

              kernel void cosin_testcase(float x<>, out float y<>)
              {   
                  y=cos(x);
              }


              int main()
              {
                 
                  int length=4;
                        
                  float * x, *y;
                 
                  int i=0;
                 
                  x=(float*) malloc(sizeof(float) *length);
                 
                  y=(float*) malloc(sizeof(float) *length);
                 

                  for(i=0;i<length;i++){
                     
                      x [ i ]=1611.625f;
                     
                      y [ i ]=0.0f;
                     
                  }
                 

                  {
                     
                      float x_stream<length>;
                     
                      float y_stream<length>;
                     

                      x_stream.read(x);
                     
                      cosin_testcase(x_stream, y_stream);
                     
                      y_stream.write(y);
                     
                  }
                 
                  for(i=0;i<length;i++){
                     
                      printf("%lf\n",y [ i ] );
                     
                  }
                 
                  free(x);
                 
                  free(y);
                 
                  return 0;
                 
              }

            • A bug about cosine function?
              nberger
              Is this documented somewhere? What about the other transcendentals?