TICC icon indicating copy to clipboard operation
TICC copied to clipboard

Use modulo operation instead of divide and substract

Open robots opened this issue 7 years ago • 1 comments

I have no idea if this project is still alive or not. But i found mistake in the 64bit print function. Following code produces incorrect output for certain numbers. Eg. -1000000019516.

int64_t sec, secx, frac, frach, fracx, fracl; char str[128]; sec = abs(x / 1000000000000); // hopefully avoid double negative sign. Thanks, Curt! secx = sec * 1000000000000; frac = abs(x - secx); // break fractional part of seconds into two 6 digit numbers frach = frac / 1000000; fracx = frach * 1000000; fracl = frac - fracx;

I suggest to rewrite the calculations as following:

sec = ABS(x / 1000000000000); frac = ABS(x % 1000000000000); // break fractional part of seconds into two 6 digit numbers frach = frac / 1000000; fracl = frac % 1000000;

I have tested this on both native 64bit machine and 32bit mcu.

robots avatar Aug 19 '18 16:08 robots

I'm working on an update to the TICC firmware and if I can validate this problem and your solution, will make the change. Thanks!

n8ur avatar Oct 29 '19 14:10 n8ur