Skip to content

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

Merged
merged 3 commits into from
May 16, 2017
Merged

Pretty float #914

merged 3 commits into from
May 16, 2017

Conversation

kroening
Copy link
Member

This PR makes the output of floating-point numbers look more similar to what stdc libraries do

mp_integer adjusted_exponent=base10_digits(_fraction)+_exponent;

if(adjusted_exponent>=format_spec.precision ||
adjusted_exponent<-4)
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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.

// and trailing dots.

while(!result.empty() && result.back()=='0')
result.resize(result.size()-1);
Copy link
Collaborator

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').

Copy link
Collaborator

@tautschnig tautschnig left a 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.

@tautschnig tautschnig merged commit dffb4ef into master May 16, 2017
@tautschnig tautschnig deleted the pretty-float branch June 19, 2017 21:56
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 this pull request may close these issues.

2 participants