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

Better rounding on rate conversion? #50

Open
thejpster opened this issue Jul 26, 2024 · 0 comments
Open

Better rounding on rate conversion? #50

thejpster opened this issue Jul 26, 2024 · 0 comments

Comments

@thejpster
Copy link

thejpster commented Jul 26, 2024

When doing rate conversion, fugit multiplies by RD_TIMES_LN and divides by LD_TIMES_RN in

let raw = lh / Helpers::<I_NOM, I_DENOM, NOM, DENOM>::LD_TIMES_RN;
.

Should it add half of LD_TIMES_RN to do half-up rounding?

I expect Rate<u32, 1, 1>(12_000_000) to convert to Rate<u32, 1000, 65536>(0x0020c49c) but instead I get Rate<u32, 1000, 65536>(0x0020c49b).

Converting 0x0020c49b back I get 32767.990 (error 0.01) whereas 0x0020c49c gives 32768.005 (error 0.005).

Am I holding it wrong?

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

1 participant