In article <87691@palm-dev-forum>, [EMAIL PROTECTED] says... > > Is there a good way to convert 100th secs to ticks and vice versa without > doing long arithmetics [and w/o assuming that SysTicksPerSecond() is 100]? I > would like all intermediate steps to remain UInt16. Both the ticks and the > 100th secs are also UInt16. /Paul N.
The original (non-integer) calculcation for N 100th-secs would be ticks = (N / 100) * SysTicksPerSecond You can transform this into ticks = N * .01 * SysTicksPerSecond ticks = (N * SysTicksPerSecond) / 100 which can all be done in UInt16 arithmetic. Going the other way N = (ticks / SysTicksPerSecond) * 100 N = ticks * 100U / SysTicksPerSecond Transforming it into a mult then divide usually gives better precision in the face of integer math, although overflow is still a problem. -- Ben Combee <[EMAIL PROTECTED]> CodeWarrior for Palm OS technical lead Get help at http://palmoswerks.com/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
