printf rewrite (with a lot of seq changes)#5128
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
| 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.
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.
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.
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)] | ||
|
|
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.
| // 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.
| // 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
printfimplementation 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:
FormatArgumentenum. This enum includesUnparsedvariant where we can still give strings to parse first and then format. This is how theprintfutil works.Spectype which represents a % directive with all options included.dddoes not need to useprintf("%g", ...)but can call theFloatformat directly.seqcan use theFormattype, 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.seqhad to change so much. The reason is that GNUseqonly 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,seqgot 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:
\uHHHHand\UHHHHHHHHneeds some more work for handling invalid codes.seqneeds to only accept 1 length parameter, whileprintfcan accept multiple, so this needs to be configurable.