title: Clock_gettime nanoseconds calculation
body: <p>ref: <a href="http://linux.die.net/man/3/clock_gettime" rel="nofollow">linux clock_gettime</a></p>
  
  <p>I found a formula which works well to get the processing time, but there's something I don't understand.
  See the result below.</p>
  
  <p>The first 2 rows is just to show the forumla in their respective columns.</p>
  
  <p>I'm only showing 3 results from a quick run.<br>
  The interesting part is in the last row, why is <code>5551 - 999896062</code> nanoseconds = 18446744072709661105?<br>
  Why is <code>18446744072709661105+1/1E9</code> = 0.000109?</p>
  
  <p>I think there's some data conversion going on that affects the results?</p>
  
  <pre><code>xx:      | t1.tv_sec |   | t1.tv_nsec |          | t2.tv_sec |   | t2.tv_nsec 
  xx:      t2-t1(sec)      t2-t1(nsec)         (t2-t1(sec))+(t2-t1(nsec))/1E9
  
  52291:   | 30437 |   | 999649886 |       | 30437 |   | 999759331 
  52291:   0   109445          0.000109
  
  52292:   | 30437 |   | 999772970 |       | 30437 |   | 999882416 
  52292:   0   109446          0.000109
  
  52293:   | 30437 |   | 999896062 |       | 30438 |   | 5551 
  52293:   1   18446744072709661105        0.000109
  </code></pre>
  
  <p>source code:</p>
  
  <pre><code>int main() {
      struct timespec t1, t2;
  
      int i = 0;
      while(1) {
          clock_gettime(CLOCK_MONOTONIC, &amp;t1);
              for(int j=0;j&lt;25000;j++) { };
          clock_gettime(CLOCK_MONOTONIC, &amp;t2);
          printf("%d: \t | %llu | \t | %lu | \t\t | %llu | \t | %lu \n", i, (unsigned long long) t1.tv_sec, t1.tv_nsec, (unsigned long long) t2.tv_sec, t2.tv_nsec);
          printf("%d: \t %llu \t %lu \t\t %lf\n", i, (unsigned long long) t2.tv_sec - t1.tv_sec, t2.tv_nsec - t1.tv_nsec, (t2.tv_sec - t1.tv_sec)+(t2.tv_nsec - t1.tv_nsec)/1E9);
          if ((t2.tv_sec - t1.tv_sec) == 1) break;
          i++;
      }
      return 0;
  }
  </code></pre>