title: high precision division in C
body: <p>I want to do the following calculation without losing precision in C.</p>
  
  <pre><code>uint64_t ts_1 = 0x5212cb03ca115ac0; 
  uint64_t ts_2 = 0x5212cb03ca115cc0; 
  uint64_t ts_delta = (ts_2 - ts_1)
  
  double scale_factor = ts_delta/(2^32)
  </code></pre>
  
  <p>I am getting the value of ts_delta as <code>0x200.</code> However the value of scale_factor as <code>15.000000</code>.Basically I am losing precision during the calculation.</p>
  
  <p>How do I do it without losing precision.?</p>
  
  <p>Here is a short self contained example on how I am trying to print.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;inttypes.h&gt;
  
  int main()
  {
          uint64_t ts_1 = 0x5212cb03ca115ac0;
          uint64_t ts_2 = 0x5212cb03ca115cc0;
          uint64_t ts_delta = (ts_2 - ts_1);
          double scale_factor = ((double)ts_delta) / (((uint64_t)1) &lt;&lt; 32);
  
          printf("ts_delta %"PRIx64" scale factor %f \n",ts_delta,scale_factor);
  
          return 0;
  }
  </code></pre>