1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

seq: remove unused Number::num_digits() function

Remove the `Number::num_digits()` function in favor of the
`digits::num_integral_digits()` functions.
This commit is contained in:
Jeffrey Finkelstein 2021-09-11 12:57:14 -04:00
parent 2ac5dc0a70
commit 3854a97749

View file

@ -67,38 +67,6 @@ impl Number {
Number::F64(n) => n,
}
}
/// Number of characters needed to print the integral part of the number.
///
/// The number of characters includes one character to represent the
/// minus sign ("-") if this number is negative.
///
/// # Examples
///
/// ```rust,ignore
/// use num_bigint::{BigInt, Sign};
///
/// assert_eq!(
/// Number::BigInt(BigInt::new(Sign::Plus, vec![123])).num_digits(),
/// 3
/// );
/// assert_eq!(
/// Number::BigInt(BigInt::new(Sign::Minus, vec![123])).num_digits(),
/// 4
/// );
/// assert_eq!(Number::F64(123.45).num_digits(), 3);
/// assert_eq!(Number::MinusZero.num_digits(), 2);
/// ```
fn num_digits(&self) -> usize {
match self {
Number::MinusZero => 2,
Number::BigInt(n) => n.to_string().len(),
Number::F64(n) => {
let s = n.to_string();
s.find('.').unwrap_or_else(|| s.len())
}
}
}
}
impl FromStr for Number {
@ -404,23 +372,3 @@ fn print_seq_integers(
}
Ok(())
}
#[cfg(test)]
mod tests {
use crate::Number;
use num_bigint::{BigInt, Sign};
#[test]
fn test_number_num_digits() {
assert_eq!(
Number::BigInt(BigInt::new(Sign::Plus, vec![123])).num_digits(),
3
);
assert_eq!(
Number::BigInt(BigInt::new(Sign::Minus, vec![123])).num_digits(),
4
);
assert_eq!(Number::F64(123.45).num_digits(), 3);
assert_eq!(Number::MinusZero.num_digits(), 2);
}
}