Unlike most assemblers, the result of multiplication has the same number of digits as the multipliers in C / C + +. In order not to lose the accuracy, sometimes it is needed to perform additional operations for the multiplication.
Let us consider the task. The system determines the time since starting the program in the microprocessor’s ticks by calling the function:

unsigned long long getTickCount ();
Length unsigned long long - 64 bits. Converting to the physical units of time in the system, there is a constant:

const unsigned long long TICKS_PER_SECOND = 1999000000ULL;
It is required to determine the function of transferring ticks in a nanoseconds getNsec (unsigned long long ticks) with semantics:

unsigned long long getNsecNaive (unsigned long long ticks) {
static const unsigned long long NSEC_PER_SECOND = 1000000000ULL;
unsigned long long nsec = NSEC_PER_SECOND * ticks / TICKS_PER_SECOND;
return nsec;
}
Pirat 22 september 2011, 11:17