title: Conversion to float in uint32_t calculation
body: <p>I am trying to improve a SWRTC by modifying the definition of a second (<strong>long unsigned n_ticks_per_second</strong>) by synchronizing time with a server.</p>
  <pre><code>#include &lt;stdint.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(int argc, char * argv[]){
  
      int32_t total_drift_SEC;
      int32_t drift_per_sec_TICK;
      uint32_t at_update_posix_time = 1491265740;
      uint32_t posix_time = 1491265680;
      uint32_t last_update_posix_time = 1491251330;
      long unsigned n_ticks_per_sec = 1000;
  
      total_drift_SEC = (posix_time - at_update_posix_time);
      drift_per_sec_TICK = ((float) total_drift_SEC) / (at_update_posix_time - last_update_posix_time);
  
      n_ticks_per_sec += drift_per_sec_TICK;
  
      printf(&quot;Total drift sec %d\r\n&quot;, total_drift_SEC);
      printf(&quot;Drift per sec in ticks %d\r\n&quot;, drift_per_sec_TICK);
      printf(&quot;n_ticks_per_second %lu\r\n&quot;, n_ticks_per_sec);
  
      return 0;
  
  }
  </code></pre>
  <p>What I don't understand is that I need to cast <strong>total_drift_SEC</strong> to <strong>float</strong> in order to have a correct result in the end, <em>ie to have n_ticks_per_sec equal to 1000 in the end</em>.</p>
  <p>The output of this code is:</p>
  <blockquote>
  <p>Total drift sec -60</p>
  <p>Drift per sec in ticks 0</p>
  <p>n_ticks_per_second 1000</p>
  </blockquote>
  <p>Whereas the output of the code without the cast to float is:</p>
  <blockquote>
  <p>Total drift sec -60</p>
  <p>Drift per sec in ticks 298054</p>
  <p>n_ticks_per_second 299054</p>
  </blockquote>