-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
seq: correctly compute width due to decimal places #2613
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
Conversation
1d801cd to
21b7d64
Compare
|
As I understand it this moves the logic to calculate the number of fractional digits from being based on the user input to a stringification of the parsed user input. This is a difference if you add trailing zeros to your example: but it is I think what we need to do to match gnu's behavior for scientific notation is to
For example, |
|
You and the other uutils team members are really good at coming up with test cases. 😄 Thank you! I'll add some more test cases and make the suggested changes. |
21b7d64 to
20495db
Compare
|
Okay, I have updated this pull request with some more unit tests and a different implementation. At @miDeb's suggestion, we are now parsing the input string itself to compute the number of integral digits and the number of fractional digits needed to display a given number. This branch includes the changes from pull request #2657, so that one should be reviewed first. |
110037a to
1624dcc
Compare
Change the way `seq` computes the number of digits needed to print a number so that it works for inputs given in scientific notation. Specifically, this commit parses the input string to determine whether it is an integer, a float in decimal notation, or a float in scientific notation, and then computes the number of integral digits and the number of fractional digits based on that. This also supports floating point negative zero, expressed in both decimal and scientific notation.
Remove the `Number::num_digits()` function in favor of the `digits::num_integral_digits()` functions.
1624dcc to
3854a97
Compare
|
Ignore my previous comment about including the changes from another pull request. Everything you need to review this is in this branch. |
|
Looks great, thanks |
This pull request fixes a bug in the behavior of
seqwith the-woption when printing floating point numbers with digits after the decimal point. Previously, the code assumed that the string provided on the command-line was a floating point number in decimal format, like 12.34. But the command-line argument might be a floating point number in scientific notation, like 1e-2. This commit changes the code to compute the number of required decimal places to display in fixed-width mode after converting the command-line argument tof64. For example: