Log In  
Follow
maxthemooshroom

Precision Drift in t() Over Long Uptimes

Bug Description

Over hours, floating-point division yields cumulative precision drift.

This results in noticeable glitching in all applications that derive any of their values from t() at any point during their _update() or _draw() functions.

Summary

  • Root cause: lua54_time() uses 60.0f (32-bit), resulting in precision drift
  • Fix: change 60.0f => 60.0
  • Alternatives: new stat(STAT_SEC_TICKS) or stat(STAT_TICKS_RUNNING, n)

If this is behaving as intended or you go with the "Fix", I implore you to consider implementing one of the stat() solutions!

Context

  • time() is the lua-side of the c function lua54_time()
  • lua54_time() returns cproc->ticks_running / 60.0 as a lua_Number
  • ticks_running is a once-per-tick integer counter
    • (tick = 1/60 seconds) => t() increments ~0.01667 seconds per tick
  • No reliable sub-second API for long-running apps

[ Continue Reading.. ]

0 comments