-
Notifications
You must be signed in to change notification settings - Fork 273
Pretty float #914
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
Pretty float #914
Conversation
mp_integer adjusted_exponent=base10_digits(_fraction)+_exponent; | ||
|
||
if(adjusted_exponent>=format_spec.precision || | ||
adjusted_exponent<-4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to have a comment explaining the magic number -4
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually know where that is from (was there before); and actual implementations appear to be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a comment to that effect? In particular, the fact that actual implementations appear to differ sounds interesting to me.
src/util/ieee_float.cpp
Outdated
// and trailing dots. | ||
|
||
while(!result.empty() && result.back()=='0') | ||
result.resize(result.size()-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would have implemented this using result.find_last_not_of('0')
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comments, but the main addition I'd ask for is a regression test covering this code, in particular the newly added e
/E
formatting.
This PR makes the output of floating-point numbers look more similar to what stdc libraries do