Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The right way to do this is:

    scaled = raw * mult >> shift;
Calculate mult and shift based on the timer frequency. The multiplication likely needs to be done with a 96 or 128 bit output. If shift is forced to be >= 64 (on a 64-bit machine), then the resulting assembly code is short and fast.


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: