-
-
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
GNU testsuite comparison:
|
bb32693
to
6ef9921
Compare
GNU testsuite comparison:
|
b25be31
to
4f55794
Compare
GNU testsuite comparison:
|
0fa1c61
to
5284545
Compare
GNU testsuite comparison:
|
5284545
to
dc44647
Compare
GNU testsuite comparison:
|
dc44647
to
4d9a86e
Compare
GNU testsuite comparison:
|
src/uu/seq/src/floatparse.rs
Outdated
/// ``` | ||
pub fn parse_hexadecimal_float(s: &str) -> Result<PreciseNumber, ParseNumberError> { | ||
let value = parse_float(s)?; | ||
let number = BigDecimal::from_f64(value).ok_or(ParseNumberError::Float)?; |
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.
in case of floating points, seq already supports arbitrary precision floating points, i.e.:
uu_seq 1e9865 1e9864 2e9865
the above limits hexadecimal support to f64, so p1023
is maximal binary exponent supported.
(i.e. uu_seq 0x1p1023 0x1p1023
will work, but uu_seq 0x1p1024 0x1p1024
will not)
(not sure if that is an issue or not, but imo it would be nice to have arbitrary precision supported in both variants)
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.
@gim913 Thanks, this is a good point. I also thought about it. And:
- I decided to start with native & simple f64 just to have something to demonstrate and discuss. :)
- arbitrary precision is a great option, but we should also consider compatibility with the original seq. From what I can see, GNU seq operates on
long double
's with a15-bit exponent
. This should serve as a bound for arbitrary precision. For example,
seq 0x1.4p16383 0
seq 0x1.4p16384 0
seq: invalid floating point argument: ‘0x1.4p16384’
Try 'seq --help' for more information.
4d9a86e
to
a1f4acf
Compare
GNU testsuite comparison:
|
2 similar comments
GNU testsuite comparison:
|
GNU testsuite comparison:
|
db975aa
to
8b6317f
Compare
GNU testsuite comparison:
|
29601c8
to
3b2664c
Compare
GNU testsuite comparison:
|
7fb8584
to
16afa0f
Compare
GNU testsuite comparison:
|
16afa0f
to
4e5d2df
Compare
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
Let's update the structure and add separate functions for parsing each part of the number. It's simpler and allows us to maintain a consistent level of detail
This commit adds special cases for displaying floating-point values, making the behavior closer to the original GNU seq.
Add some tests from GNU coreutils that fail quite often. Feel free to add more.
Let's drop some latest modifications and start once again
Let's try to implement GNU-like precision detection. These are early steps to test the idea, and it will likely be modified and improved
Let's add and test a more GNU-like version of number precision.
4e5d2df
to
0a5687e
Compare
GNU testsuite comparison:
|
About
Hello,
This is the initial implementation of hexadecimal floating-point arguments in seq. It started as an attempt to add parsing for hexadecimal floats (issue #6935), but quickly grew into bigger changes.
Before
After
Expected
Changes
Added the
hexdecimalfloat
module for parsing hex-floats and detecting the precision of numbers closer to GNU seq. I tried to keep the new functionality separate and minimize changes to the existing code to make changes more observable. I'm sure it’s possible unify number parsing to handle all types of values in one place. However, this seems like a big change and (IMHO) deserves a separate refactor-like PR.Changed the method for detecting and using precision for numbers. The initial approach of using the number of fractional digits from a
BigDecimal
didn’t match the GNU behavior and led to different representations. For now the precision is detected separately and this is not a part of thePreciseNumber
(to avoid changing too much of the existing code).Added decimal/exponent notations for hexadecimal floats to match the
%Lg
format in GNU seq. Thesprintf
function fromuucore
is used for this.Added tests. During development, I found some additional mismatches with GNU seq. However, they are not directly related to hexadecimal floating points and could be addressed in future PRs.
Thank you