-
Notifications
You must be signed in to change notification settings - Fork 33
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
Round f32 when used as integers #44
base: main
Are you sure you want to change the base?
Conversation
Thanks! To me this makes sense -- @marcelbuesing do you have an opinion of this? How does it interact with min/max settings? Looks like there is no |
I just realised that the |
I have implemented rounding with However, that adds a new dependency to users of the generated code. Any thoughts on that? |
Honestly I don't know. I think I would probably check this against the cantools implementation. So basically regenerate this part using the changes you added to the example.dbc @mvalenzuelamoixa . And look at their C code in comparison. Regeneration is described here
Yes even better, embedded-hal just added alpha CAN support based on the can-embedded-hal experience. |
Hi @marcelbuesing. As you recommended I added a test on the However, rather than rounding, it seems that the main difference is in the floating point representation, with
I've also tried changing the codegen to use |
Thanks you @mvalenzuelamoixa ! So if I understand correctly it would suffice to switch to |
So it does help for some specific inputs, but it seems like the truncation vs rounding problem still happens for some (I wrote a test that goes through all 2^16 inputs), which is not behaviour that I would expect. However, this is also the case for the For example (with f64 in the rust code):
With the
To me, the behaviour below seems more sensible, and |
I was finding problems with values that after scaling were not exact, such as 79.99999 being truncated to 79 instead of rounded to 80. I have added a test and the fix for this use case.
Let me know if this was a design choice because of performance and I have misunderstood it to be a bug.