Repository navigation
uucore: avoid huge divisors for tiny hex durations - #15482
Merged
Merged
Conversation
sylvestre
reviewed
Oct 18, 2026
| construct_extended_big_decimal(digits, negative, base, scale, exponent.unwrap_or_default()); | ||
| let exponent = exponent.unwrap_or_default(); | ||
|
|
||
| // A duration smaller than one nanosecond rounds up to one nanosecond. |
Contributor
There was a problem hiding this comment.
could you please make this comment shorter? two lines should be enough
sylvestre
reviewed
Oct 18, 2026
| let ebd_result = if target == ParseTarget::Duration | ||
| && base == Base::Hexadecimal | ||
| && !digits.is_zero() | ||
| && BigInt::from(digits.bits()) + &exponent - BigInt::from(scale) * 4 <= BigInt::from(-30) |
Contributor
There was a problem hiding this comment.
please put -30 in a named const with a short comment (2^-30 s < 1ns)
sylvestre
reviewed
Oct 18, 2026
| && !digits.is_zero() | ||
| && BigInt::from(digits.bits()) + &exponent - BigInt::from(scale) * 4 <= BigInt::from(-30) | ||
| { | ||
| if negative { |
Contributor
There was a problem hiding this comment.
returning NotNumeric for a valid number feels like a hack
could we return make_error(false, negative) and reject a negative underflow in parse_time instead?
Contributor
|
@limadog9 our time isn't infinite, please pause the contributions a bit, it is impossible to handle such a large volume |
Contributor
Author
|
Will do, thanks |
limadog9
force-pushed
the
fix/duration-tiny-hex-12226
branch
from
October 18, 2026 22:37
0705a5b to
9792f38
Compare
sylvestre
reviewed
Oct 19, 2026
| //! Utilities for parsing numbers in various formats | ||
|
|
||
| // 2^-30 seconds < 1 ns. | ||
| const SUBNANOSECOND_BINARY_EXPONENT: i32 = -30; |
Contributor
There was a problem hiding this comment.
could you please move it after the use block? constants usually live there
sylvestre
reviewed
Oct 19, 2026
| } | ||
|
|
||
| #[test] | ||
| #[cfg(target_os = "linux")] |
Tiny hexadecimal durations with many fractional zeros spent seconds constructing a huge denominator. Detect values below one nanosecond before that division, accounting for binary exponents and unit suffixes. Add parser and sleep regressions. Validation: 55 sleep integration tests and 84 parser tests pass. Closes uutils#12226
limadog9
force-pushed
the
fix/duration-tiny-hex-12226
branch
from
October 19, 2026 10:06
9792f38 to
384b157
Compare
Contributor
Author
|
Moved the constant and enabled the regression test across platforms. |
Contributor
|
Thanks for your PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tiny hexadecimal durations with many fractional zeros spent seconds constructing a huge denominator. Detect values below one nanosecond before that division, accounting for binary exponents and unit suffixes. Add parser and sleep regressions.
Validation: 55 sleep integration tests and 84 parser tests pass.
Closes #12226