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

Convert to inverse unit incorrect #165

Closed
Gra-tak opened this issue Sep 10, 2021 · 1 comment · Fixed by #166
Closed

Convert to inverse unit incorrect #165

Gra-tak opened this issue Sep 10, 2021 · 1 comment · Fixed by #166

Comments

@Gra-tak
Copy link

Gra-tak commented Sep 10, 2021

Thanks for this awesome library. As far as I can tell, I have found an error in the conversion between inverse magnitudes like Hertz and seconds.

units::precise_unit unitA=units::unit_from_string("ms");
units::precise_unit unitB=units::unit_from_string("kHz");
double v=units::convert(1, unitA, unitB);
double v2=units::convert(v, unitB, unitA);
std::cout << "v = '" << v << "'" << std::endl;
std::cout << "v2 = '" << v2 << "'" << std::endl;

gives the following output:

v = '1e+06'
v2 = '1e-12'

As far as I can tell,
return result.multiplier() / (val * start.multiplier());
should be replaced by
1.0 / (val * start.multiplier() * result.multiplier());.

@phlptp phlptp linked a pull request Sep 10, 2021 that will close this issue
@phlptp
Copy link
Collaborator

phlptp commented Sep 10, 2021

You are correct. I had never tested that code path with both units having multipliers.
Added some tests and fixed the issue in #166

Thanks for catching that.

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

Successfully merging a pull request may close this issue.

2 participants