-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
printf
rewrite (with a lot of seq
changes)
#5128
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
lot of conflicts, sorry! |
I think most are easy to solve because this is a full rewrite of the functionality. I'll look into it soon. |
…nto printf-rewrite
So changing |
af492c7
to
e7d58f6
Compare
This can be un-ignored when it is implemented
printf
rewriteprintf
rewrite (with a lot of seq
changes)
tests/by-util/test_printf.rs
Outdated
@@ -293,7 +298,7 @@ fn sub_num_float_e_no_round() { | |||
#[test] | |||
fn sub_num_float_round() { | |||
new_ucmd!() | |||
.args(&["two is %f", "1.9999995"]) | |||
.args(&["two is %f", "1.9999996"]) |
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.
That's cheating ;-)
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 thought it wasn't cheating because my printf
said:
❯ printf "two is %f" 1.9999995
two is 1,999999
but I just tried with
❯ env printf "two is %f" 1.9999995
two is 2,000000
So yeah I should change that back 😄
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've ignored this test for now. I did add a test for 0.9999995
as well so that we at least have a test which checks for rounding (and which does work).
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.
maybe check for the two potential values ?
This is a limitation of the current implementation, which should ultimately use "long double" precision instead of f64.
…nto printf-rewrite
GNU testsuite comparison:
|
you fixed an issue with seq that a fuzzer found
yours:
gnu:
|
011f1c6
to
715857c
Compare
715857c
to
e95add7
Compare
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
|
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.
src/uu/seq/src/number.rs
Outdated
@@ -3,79 +3,9 @@ | |||
// For the full copyright and license information, please view the LICENSE | |||
// file that was distributed with this source code. | |||
// spell-checker:ignore extendedbigdecimal extendedbigint |
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.
// spell-checker:ignore extendedbigdecimal extendedbigint | |
// spell-checker:ignore extendedbigdecimal |
src/uu/seq/src/seq.rs
Outdated
@@ -4,26 +4,20 @@ | |||
// file that was distributed with this source code. | |||
// spell-checker:ignore (ToDO) istr chiter argptr ilen extendedbigdecimal extendedbigint numberparse |
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.
// spell-checker:ignore (ToDO) istr chiter argptr ilen extendedbigdecimal extendedbigint numberparse | |
// spell-checker:ignore (ToDO) extendedbigdecimal numberparse |
…t matching on result
3c86940
to
8eb66ab
Compare
The current
printf
implementation is -- with all due respect to the original author -- a mess. So I'm rewriting it completely to be smaller and more readable.Here's what changed:
FormatArgument
enum. This enum includesUnparsed
variant where we can still give strings to parse first and then format. This is how theprintf
util works.Spec
type which represents a % directive with all options included.dd
does not need to useprintf("%g", ...)
but can call theFloat
format directly.seq
can use theFormat
type, which accepts only a single directive. With that type, we can parse the whole format string before we print, which simplifies the error handling around it.seq
had to change so much. The reason is that GNUseq
only accepts float % directives and that there is no special path for integers. So, I had to remove all the integer handling from that util. This allowed me to give the correct type (i.e.f64
) to the format. As a nice side-effect,seq
got much simpler!I'm marking this as ready because I'm passing all the tests now. I can open issues for things that still need to change. Current limitations:
\uHHHH
and\UHHHHHHHH
needs some more work for handling invalid codes.seq
needs to only accept 1 length parameter, whileprintf
can accept multiple, so this needs to be configurable.