Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modulo operation instead of divide and substract #28

Open
robots opened this issue Aug 19, 2018 · 1 comment
Open

Use modulo operation instead of divide and substract #28

robots opened this issue Aug 19, 2018 · 1 comment

Comments

@robots
Copy link

robots commented Aug 19, 2018

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.

@n8ur
Copy link
Member

n8ur commented Oct 29, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants