return 0;
}
- uint64_t nanosecondsPerTick = ((uint64_t)(mtid.denom) / (uint64_t)(mtid.numer));
- return SecondsToNanoSeconds * nanosecondsPerTick;
+ // (numer / denom) gives you the nanoseconds per tick, so the below code
+ // computes the number of ticks per second. We explicitly do the multiplication
+ // first in order to help minimize the error that is produced by integer division.
+
+ return (SecondsToNanoSeconds * (uint64_t)(mtid.denom)) / (uint64_t)(mtid.numer);
#else
struct timespec ts;
}
uint64_t nanosecondsPerTick = ((uint64_t)(ts.tv_sec) * SecondsToNanoSeconds) + (uint64_t)(ts.tv_nsec);
- return SecondsToNanoSeconds * nanosecondsPerTick;
+ return SecondsToNanoSeconds / nanosecondsPerTick;
#endif
}