-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
seq:add floating point support #6959
base: main
Are you sure you want to change the base?
seq:add floating point support #6959
Conversation
use bigdecimal::BigDecimal; | ||
use num_traits::FromPrimitive; | ||
|
||
pub fn parse_hexadecimal_float(s: &str) -> Result<PreciseNumber, ParseNumberError> { |
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 these functions can be used by other coreutils programs, no?
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.
Perhaps. Since I'm not very familiar with the other modules yet, I’ve only used them in seq so far. But I’m sure we can make them shared if needed
@@ -698,7 +698,7 @@ fn test_parse_error_hex() { | |||
new_ucmd!() | |||
.arg("0xlmnop") | |||
.fails() | |||
.usage_error("invalid hexadecimal argument: '0xlmnop'"); | |||
.usage_error("invalid floating point argument: '0xlmnop'"); | |||
} | |||
|
|||
#[test] |
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.
please add more tests
the unit tests are nice but integration tests are much better :)
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.
No problem
GNU testsuite comparison:
|
bb32693
to
6ef9921
Compare
GNU testsuite comparison:
|
b25be31
to
4f55794
Compare
GNU testsuite comparison:
|
0fa1c61
to
5284545
Compare
GNU testsuite comparison:
|
Initial version of a hexadecimal float parser. This implementation is intended for preview and further discussion. Issue uutils#6935
Turn on the float parser. Now it's possible to use hexadecimal floats as parameters. For example, cargo run -- 0x1p-1 3 0.5 1.5 2.5 Issue uutils#6935
Fix the test that fails after the implementation of the floating-point format. The expected output now matches the GNU seq output. seq 0xlmnop seq: invalid floating point argument: ‘0xlmnop’ Issue uutils#6935
5284545
to
dc44647
Compare
GNU testsuite comparison:
|
// In fact, the 4095.953125 is correct value. | ||
// (65535 + 4/16)*2^(-4) = 4095.953125 | ||
// So, it looks like a formatting or output rounding differences | ||
new_ucmd!() |
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.
@sylvestre Hello,
Could you please find some time to discuss the test results?
Here are the tests that showed differences in the output between the Rust and GNU versions of the utility.
The GNU seq uses printf
with the %Lg
format, which doesn't seem to have a direct equivalent in Rust. Furthermore, %Lg
can switch between %f
and %e
formats depending on the precision, which also behaves differently in Rust.
I plan to experiment with formats and GNU glibc to replicate the printf behavior in Rust, but it might take some time. Please let me know if implementing a Rust equivalent is the preferred way to handle these output mismatches.
Additionally, I was wondering if it might make sense to prepare and merge what we already have. This way, we can share the code and gather more real-world feedback. Since these changes address the initial issue, it’s still a step forward. Of course, I’m not insisting—just considering other options. I’m happy to proceed with whichever approach works best for the project.
Thx
About
Hello,
This is the initial implementation of hexadecimal floating-point arguments in
seq
(Issue #6935). I’d like to gather feedback to ensure we’re heading in the right direction. If the approach looks good enough, I will proceed with refining the details, such as adding tests, improving documentation, and better integrating it into the application.Any comments, tips, or suggestions are greatly appreciated.
Before
After
Expected
Thank you