mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2682 from jfinkels/seq-simpler-terminator-check
seq: add is_first_iteration to avoid comparisons
This commit is contained in:
commit
88a689075c
1 changed files with 6 additions and 4 deletions
|
@ -287,7 +287,12 @@ fn print_seq(
|
|||
let (first, increment, last) = range;
|
||||
let mut i = 0isize;
|
||||
let mut value = first + i as f64 * increment;
|
||||
let mut is_first_iteration = true;
|
||||
while !done_printing(&value, &increment, &last) {
|
||||
if !is_first_iteration {
|
||||
write!(stdout, "{}", separator)?;
|
||||
}
|
||||
is_first_iteration = false;
|
||||
let istr = format!("{:.*}", largest_dec, value);
|
||||
let ilen = istr.len();
|
||||
let before_dec = istr.find('.').unwrap_or(ilen);
|
||||
|
@ -299,11 +304,8 @@ fn print_seq(
|
|||
write!(stdout, "{}", istr)?;
|
||||
i += 1;
|
||||
value = first + i as f64 * increment;
|
||||
if !done_printing(&value, &increment, &last) {
|
||||
write!(stdout, "{}", separator)?;
|
||||
}
|
||||
}
|
||||
if (first >= last && increment < 0f64) || (first <= last && increment > 0f64) {
|
||||
if !is_first_iteration {
|
||||
write!(stdout, "{}", terminator)?;
|
||||
}
|
||||
stdout.flush()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue