Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

alexs-sh
Copy link
Contributor

@alexs-sh alexs-sh commented Dec 14, 2024

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

cargo run -q seq 0x1p-1 2
seq: invalid hexadecimal argument: '0x1p-1'

After

cargo run -q seq 0x1p-1 2
0.5
1.5

Expected

seq 0x1p-1 2
0.5
1.5

Thank you

use bigdecimal::BigDecimal;
use num_traits::FromPrimitive;

pub fn parse_hexadecimal_float(s: &str) -> Result<PreciseNumber, ParseNumberError> {
Copy link
Contributor

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?

Copy link
Contributor Author

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]
Copy link
Contributor

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@alexs-sh alexs-sh force-pushed the feature/seq-add-floating-point-support-6935 branch 2 times, most recently from bb32693 to 6ef9921 Compare December 15, 2024 09:20
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@alexs-sh alexs-sh force-pushed the feature/seq-add-floating-point-support-6935 branch from b25be31 to 4f55794 Compare December 15, 2024 11:34
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

@alexs-sh alexs-sh force-pushed the feature/seq-add-floating-point-support-6935 branch 3 times, most recently from 0fa1c61 to 5284545 Compare December 16, 2024 08:51
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

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
@alexs-sh alexs-sh force-pushed the feature/seq-add-floating-point-support-6935 branch from 5284545 to dc44647 Compare December 16, 2024 11:56
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

// 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!()
Copy link
Contributor Author

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

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