Merge pull request #6928 from artP2/scientific-notation-uppercase-E

seq: handle scientific notation with uppercase 'E'
This commit is contained in:
Daniel Hofstetter 2024-12-07 14:55:28 +01:00 committed by GitHub
commit f7c38a3079
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -333,7 +333,7 @@ impl FromStr for PreciseNumber {
// number differently depending on its form. This is important
// because the form of the input dictates how the output will be
// presented.
match (s.find('.'), s.find('e')) {
match (s.find('.'), s.find(['e', 'E'])) {
// For example, "123456" or "inf".
(None, None) => parse_no_decimal_no_exponent(s),
// For example, "123e456" or "1e-2".
@ -392,6 +392,7 @@ mod tests {
fn test_parse_big_int() {
assert_eq!(parse("0"), ExtendedBigDecimal::zero());
assert_eq!(parse("0.1e1"), ExtendedBigDecimal::one());
assert_eq!(parse("0.1E1"), ExtendedBigDecimal::one());
assert_eq!(
parse("1.0e1"),
ExtendedBigDecimal::BigDecimal("10".parse::<BigDecimal>().unwrap())

View file

@ -333,6 +333,11 @@ fn test_width_scientific_notation() {
.succeeds()
.stdout_is("0999\n1000\n")
.no_stderr();
new_ucmd!()
.args(&["-w", "999", "1E3"])
.succeeds()
.stdout_is("0999\n1000\n")
.no_stderr();
}
#[test]