title: Float rounding problems
body: <p>I finished my thesis in CUDA but I am having a final problem, that has to do with rounding float numbers.</p>
  
  <p>I have an integer variable named bin that is the codification of x+y*X_dim. Given the bin I want to find the x and y coordenates that originated it so I can do a symmetry calculation. This is my original program:</p>
  
  <pre><code>float yaux,xaux;
      yaux=(float)floorf((float)bin/((float)DETECTOR_X_DIM));
  
  
      if(abs(yaux-floorf(yaux)) &lt; 0.0001)
      yaux=floorf(yaux);
      else
      yaux=ceilf(yaux);
  
  
      xaux=(float)((float)(((float)bin/((float)DETECTOR_X_DIM))-(float)yaux)*((float)DETECTOR_X_DIM));
  
      return (int)xaux;
  
      if(abs(xaux-floorf(xaux)) &lt; 0.0001)
      xaux=floorf(xaux);
      else
      xaux=ceilf(xaux);
      return (int)xaux;
  
  
      xaux = (float)DETECTOR_X_DIM - xaux -(float)1;
  
      return (int)xaux+(int)yaux*DETECTOR_X_DIM;
  </code></pre>
  
  <p>The problem is that it works for some bins of the detector but it doesnt work for others(it returns xaux added by 1). Is there some better way to this?</p>
  
  <p>Thank you in advance</p>