[email protected] said:
> The trick is for integer math is to never do or postpone division.  So if
> you have 1560 PPS per 1432 ticks (or whatever) the number is a rational
> fraction of 1560/1432 and you store it as two integer.  The goals is to
> always be exact.   that at the end you need to multiply maybe "23425" by the
> ratio it is easy (23425*1560)/1432.  Store fractions as fractions. But you
> have to check yourself first if that might be an over flow.  If so then
> shift it all over some number of bits and shift the answer back. 

We are probably saying the same thing, but I didn't think of it this way when 
reading your description...

If you are doing something like
  seconds += ticks/ticksPerSecond;
You can get a lot closer by keeping track of the remainder.
  seconds += ticks/ticksPerSecond;
  rem += ticks % ticksPerSecond;
  if (rem > ticksPerSecond) {
  seconds += 1;
  rem -= ticksPerSecond;
  }



-- 
These are my opinions.  I hate spam.



_______________________________________________
time-nuts mailing list -- [email protected]
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Reply via email to