[time-nuts] arduino solar clock

Hal Murray hmurray at megapathdsl.net
Mon Jan 20 04:59:02 UTC 2014


albertson.chris at gmail.com 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.






More information about the Time-nuts_lists.febo.com mailing list