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

wrong number of decimal places formatting mpf_float as fixed-point #113

Closed
emfrias opened this issue Feb 12, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@emfrias
Copy link
Contributor

commented Feb 12, 2019

Hello,

I've encountered a bug where I get the wrong number of digits when formatting an mpf_float_50 as fixed precision:

std::cout << std::setprecision(3) << std::fixed << boost::multiprecision::mpf_float_50("99.9809") << "\n";

This prints "99.9809" instead of the expected "99.981".

I traced into it a little and it looks like the code starts by calling mpf_get_str() asking for three digits,
which returns "1" with e == 3 (meaning 100). So it turns around and calls mpf_get_str() again, this time asking
for 6 digits, and this time it returns "999809" with e == 2 (meaning 99.9809) -- the extra digits caused mpf_get_str() to round differently.

I've hacked my copy to check whether e changes, and if so, adjusts digits accordingly and calling mpf_get_str() a third time, but I'm not sure that's the right solution.

@jzmaddock

This comment has been minimized.

Copy link
Collaborator

commented Mar 4, 2019

Will be in the next release.

@jzmaddock jzmaddock closed this Mar 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.