title: Is there a solution for Floating point Arithmetic problems in C++?
body: <p>I am doing some floating point arithmetic and having precision problems. The resulting value is different on two machines for the same input. I read the post @ <a href="https://stackoverflow.com/questions/3031143/why-cant-i-multiply-a-float">Why can&#39;t I multiply a float?</a> and also read other material on the web &amp; understood that it is got to do with binary representation of floating point and on machine epsilon. However, I wanted to check if there is a way to solve this problem / Some work around for Floating point arithmetic in C++ ?? I am converting a float to unsigned short for storage and am converting back when necessary. However, when I convert it back to unsigned short, the precision (to 6 decimal points) remains correct on one machine but fails on the other. </p>
  
  <pre><code>//convert FLOAT to short
  
  unsigned short sConst = 0xFFFF;
  
  unsigned short shortValue = (unsigned short)(floatValue * sConst);
  
  //Convert SHORT to FLOAT
  
  float floatValue = ((float)shortValue / sConst);
  </code></pre>