Skip to content

Commit

Permalink
seq:style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-sh committed Jan 4, 2025
1 parent 8222d37 commit 5038d46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/uu/seq/src/floatparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ pub fn detect_precision(s: &str) -> Option<usize> {
.count();

if length > 0 {
let exponent_value: i32 =
s[exponent + 1..exponent + length + 1].parse().unwrap_or(0);
let exponent_value: i32 = s[exponent + 1..=exponent + length].parse().unwrap_or(0);
if exponent_value < 0 {
precision = precision.map(|x| x + exponent_value.abs());
} else {
Expand Down Expand Up @@ -253,8 +252,8 @@ fn parse_exponent_part(s: &str) -> Result<(Option<i32>, &str), ParseNumberError>
#[cfg(test)]
mod tests {

use super::parse_hexadecimal_float;
use crate::{floatparse::detect_precision, numberparse::ParseNumberError, ExtendedBigDecimal};
use super::{detect_precision, parse_hexadecimal_float};
use crate::{numberparse::ParseNumberError, ExtendedBigDecimal};
use bigdecimal::BigDecimal;
use num_traits::ToPrimitive;

Expand Down Expand Up @@ -380,13 +379,11 @@ mod tests {
assert_eq!(detect_precision("0x1.1"), None);
assert_eq!(detect_precision("0x1.1p2"), None);
assert_eq!(detect_precision("0x1.1p-2"), None);
assert_eq!(detect_precision("0x1.1p-2"), None);
assert_eq!(detect_precision(".1"), Some(1));
assert_eq!(detect_precision("1.1"), Some(1));
assert_eq!(detect_precision("1.12"), Some(2));
assert_eq!(detect_precision("1.12345678"), Some(8));
assert_eq!(detect_precision("1.1e-1"), Some(2));
assert_eq!(detect_precision("1.1e-3"), Some(4));
assert_eq!(detect_precision("1.1e-3"), Some(4));
}
}
2 changes: 1 addition & 1 deletion src/uu/seq/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn write_value_float(
// format without precision: hexadecimal floats
match value {
ExtendedBigDecimal::BigDecimal(bd) => {
format_bigdecimal(&bd).unwrap_or("{value}".to_owned())
format_bigdecimal(bd).unwrap_or("{value}".to_owned())
}
_ => format!("{value:>0width$}"),
}
Expand Down

0 comments on commit 5038d46

Please sign in to comment.