Skip to content
Snippets Groups Projects

Timestamp function for Lua

Merged Hannu Hanhi requested to merge Hannu_Hanhi/SRB2:lua-timestamp into next
3 files
+ 17
2
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 7
1
@@ -2163,7 +2163,13 @@ precise_t I_GetPreciseTime(void)
int I_PreciseToMicros(precise_t d)
{
return (int)(d / (timer_frequency / 1000000.0));
// d is going to be converted into a double. So remove the highest bits
// to avoid loss of precision in the lower bits, for the (probably rare) case
// that the higher bits are actually used.
d &= ((precise_t)1 << 53) - 1; // The mantissa of a double can handle 53 bits at most.
// The resulting double from the calculation is converted first to UINT64 to avoid overflow,
// which is undefined behaviour when converting floating point values to integers.
return (int)(UINT64)(d / (timer_frequency / 1000000.0));
}
//
Loading