#include <time.h>
#include <iostream>
using namespace std;
int main() {
// your code goes here
double duration = 24000.0/1001.0;
double first_pts = (double)time(NULL);
unsigned long long nb_frame = 1000000;
double time_after_1 = first_pts + nb_frame * duration;
double time_after_2 = first_pts;
for(unsigned long long i = 0 ; i < nb_frame ; ++i)
{
time_after_2 += duration;
}
double time_after_3 = first_pts;
double c = 0.0; // A running compensation for lost low-order bits.
for(unsigned long long i = 0 ; i < nb_frame ; ++i)
{
double y = duration - c; // So far, so good: c is zero.
double t = time_after_3 + y; // Alas, sum is big, y small, so low-order digits of y are lost.
c = (t - time_after_3) - y; // (t - sum) recovers the high-order part of y; subtracting y recovers -(low part of y)
time_after_3 = t; // Algebraically, c should always be zero. Beware overly-aggressive optimizing compilers!
// Next time around, the lost low part will be added to y in a fresh attempt.
}
cout << time_after_1 - time_after_2 << " or " << time_after_1 - time_after_3 << endl;
return 0;
}
I2luY2x1ZGUgPHRpbWUuaD4KCiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJZG91YmxlIGR1cmF0aW9uID0gMjQwMDAuMC8xMDAxLjA7Cglkb3VibGUgZmlyc3RfcHRzID0gKGRvdWJsZSl0aW1lKE5VTEwpOwoJdW5zaWduZWQgbG9uZyBsb25nIG5iX2ZyYW1lID0gMTAwMDAwMDsKCQoJZG91YmxlIHRpbWVfYWZ0ZXJfMSA9IGZpcnN0X3B0cyArIG5iX2ZyYW1lICogZHVyYXRpb247Cglkb3VibGUgdGltZV9hZnRlcl8yID0gZmlyc3RfcHRzOwoJZm9yKHVuc2lnbmVkIGxvbmcgbG9uZyBpID0gMCA7IGkgPCBuYl9mcmFtZSA7ICsraSkKCXsKCQl0aW1lX2FmdGVyXzIgKz0gZHVyYXRpb247Cgl9CgkKCWRvdWJsZSB0aW1lX2FmdGVyXzMgPSBmaXJzdF9wdHM7Cglkb3VibGUgYyA9IDA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